org.apache.lucene.codecs.lucene40

## Class Lucene40StoredFieldsWriter

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

All Implemented Interfaces:
  Closeable, AutoCloseable

    public final class Lucene40StoredFieldsWriter
    extends StoredFieldsWriter

Class responsible for writing stored document fields.

It uses <segment>.fdt and <segment>.fdx; files.

See Also:
  `Lucene40StoredFieldsFormat`
WARNING: This API is experimental and might change in incompatible ways in the next release.

### Field Summary

Fields
`static String` `FIELDS_EXTENSION` Extension of stored fields file
`static String` `FIELDS_INDEX_EXTENSION` Extension of stored fields index file

### Constructor Summary

Constructors
Constructor and Description
`Lucene40StoredFieldsWriter(Directory directory, String segment, IOContext context)` Sole constructor.

### Method Summary

Methods
`void` `abort()` Aborts writing entirely, implementation should remove any partially-written files, etc.
`void` `addRawDocuments(IndexInput stream, int[] lengths, int numDocs)` Bulk write a contiguous series of documents.
`void` `close()`
`void` `finish(FieldInfos fis, int numDocs)` Called before `StoredFieldsWriter.close()`, passing in the number of documents that were written.
`int` `merge(MergeState mergeState)` Merges in the stored fields from the readers in `mergeState`.
`void` `startDocument(int numStoredFields)` Called before writing the stored fields of the document.
`void` `writeField(FieldInfo info, IndexableField field)` Writes a single stored field.

### Methods inherited from class org.apache.lucene.codecs.StoredFieldsWriter

`addDocument, finishDocument`

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

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

### Field Detail

#### FIELDS_EXTENSION

    public static final String FIELDS_EXTENSION

Extension of stored fields file

See Also:
  Constant Field Values

#### FIELDS_INDEX_EXTENSION

    public static final String FIELDS_INDEX_EXTENSION

Extension of stored fields index file

See Also:
  Constant Field Values

### Constructor Detail

#### Lucene40StoredFieldsWriter

    public Lucene40StoredFieldsWriter(Directory directory,
                              String segment,
                              IOContext context)
                               throws IOException

Sole constructor.

Throws:
  `IOException`

### Method Detail

#### startDocument

    public void startDocument(int numStoredFields)
                       throws IOException

Description copied from class: `StoredFieldsWriter`
Called before writing the stored fields of the document. `StoredFieldsWriter.writeField(FieldInfo, IndexableField)` will be called `numStoredFields` times. Note that this is called even if the document has no stored fields, in this case `numStoredFields` will be zero.

Specified by:
  `startDocument` in class `StoredFieldsWriter`
Throws:
  `IOException`

#### close

    public void close()
               throws IOException

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

#### abort

    public void abort()

Description copied from class: `StoredFieldsWriter`
Aborts writing entirely, implementation should remove any partially-written files, etc.

Specified by:
  `abort` in class `StoredFieldsWriter`

#### writeField

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

Description copied from class: `StoredFieldsWriter`
Writes a single stored field.

Specified by:
  `writeField` in class `StoredFieldsWriter`
Throws:
  `IOException`

#### addRawDocuments

    public void addRawDocuments(IndexInput stream,
                       int[] lengths,
                       int numDocs)
                         throws IOException

Bulk write a contiguous series of documents. The lengths array is the length (in bytes) of each raw document. The stream IndexInput is the fieldsStream from which we should bulk-copy all bytes.

Throws:
  `IOException`

#### finish

    public void finish(FieldInfos fis,
              int numDocs)

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

Specified by:
  `finish` in class `StoredFieldsWriter`

#### merge

    public int merge(MergeState mergeState)
              throws IOException

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

Overrides:
  `merge` in class `StoredFieldsWriter`
Throws:
  `IOException`