org.apache.lucene.codecs

## Class StoredFieldsWriter

- java.lang.Object
- - org.apache.lucene.codecs.StoredFieldsWriter

- All Implemented Interfaces:
    Closeable, AutoCloseable
  Direct Known Subclasses:
    CompressingStoredFieldsWriter

      public abstract class StoredFieldsWriter
      extends Object
      implements Closeable

  Codec API for writing stored fields:
  1. For every document, `startDocument()` is called, informing the Codec that a new document has started.
  2. `writeField(FieldInfo, IndexableField)` is called for each field in the document.
  3. After all documents have been written, `finish(FieldInfos, int)` is called for verification/sanity-checks.
  4. Finally the writer is closed (`close()`)
  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `StoredFieldsWriter.MergeVisitor` A visitor that adds every field it sees.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `StoredFieldsWriter()` Sole constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract void` | `close()`
    `abstract void` | `finish(FieldInfos fis, int numDocs)` Called before `close()`, passing in the number of documents that were written.
    `void` | `finishDocument()` Called when a document and all its fields have been added.
    `int` | `merge(MergeState mergeState)` Merges in the stored fields from the readers in `mergeState`.
    `abstract void` | `startDocument()` Called before writing the stored fields of the document.
    `abstract void` | `writeField(FieldInfo info, IndexableField field)` Writes a single stored field.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StoredFieldsWriter

          protected StoredFieldsWriter()

      Sole constructor. (For invocation by subclass constructors, typically implicit.)

  - ### Method Detail

    - #### startDocument

          public abstract void startDocument()
                                      throws IOException

      Called before writing the stored fields of the document. `writeField(FieldInfo, IndexableField)` will be called for each stored field. Note that this is called even if the document has no stored fields.
      Throws:
        `IOException`

    - #### finishDocument

          public void finishDocument()
                              throws IOException

      Called when a document and all its fields have been added.
      Throws:
        `IOException`

    - #### writeField

          public abstract void writeField(FieldInfo info,
                        IndexableField field)
                                   throws IOException

      Writes a single stored field.
      Throws:
        `IOException`

    - #### finish

          public abstract void finish(FieldInfos fis,
                    int numDocs)
                               throws IOException

      Called before `close()`, passing in the number of documents that were written. Note that this is intentionally redundant (equivalent to the number of calls to `startDocument()`, but a Codec should check that this is the case to detect the JRE bug described in LUCENE-1282.
      Throws:
        `IOException`

    - #### merge

          public int merge(MergeState mergeState)
                    throws IOException

      Merges in the stored fields from the readers in `mergeState`. The default implementation skips over deleted documents, and uses `startDocument()`, `writeField(FieldInfo, IndexableField)`, and `finish(FieldInfos, int)`, returning the number of documents that were written. Implementations can override this method for more sophisticated merging (bulk-byte copying, etc).
      Throws:
        `IOException`

    - #### close

          public abstract void close()
                              throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException`

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.