Package org.apache.lucene.codecs
Class StoredFieldsWriter
- java.lang.Object
-
- org.apache.lucene.codecs.StoredFieldsWriter
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
CompressingStoredFieldsWriter,Lucene40StoredFieldsWriter
public abstract class StoredFieldsWriter extends Object implements Closeable
Codec API for writing stored fields:- For every document,
startDocument(int)is called, informing the Codec how many fields will be written. writeField(FieldInfo, IndexableField)is called for each field in the document.- After all documents have been written,
finish(FieldInfos, int)is called for verification/sanity-checks. - Finally the writer is closed (
close())
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedStoredFieldsWriter()Sole constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidabort()Aborts writing entirely, implementation should remove any partially-written files, etc.protected voidaddDocument(Iterable<? extends IndexableField> doc, FieldInfos fieldInfos)sugar method for startDocument() + writeField() for every stored field in the documentabstract voidclose()abstract voidfinish(FieldInfos fis, int numDocs)Called beforeclose(), passing in the number of documents that were written.voidfinishDocument()Called when a document and all its fields have been added.intmerge(MergeState mergeState)Merges in the stored fields from the readers inmergeState.abstract voidstartDocument(int numStoredFields)Called before writing the stored fields of the document.abstract voidwriteField(FieldInfo info, IndexableField field)Writes a single stored field.
-
-
-
Method Detail
-
startDocument
public abstract void startDocument(int numStoredFields) throws IOExceptionCalled before writing the stored fields of the document.writeField(FieldInfo, IndexableField)will be callednumStoredFieldstimes. Note that this is called even if the document has no stored fields, in this casenumStoredFieldswill be zero.- Throws:
IOException
-
finishDocument
public void finishDocument() throws IOExceptionCalled 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
-
abort
public abstract void abort()
Aborts writing entirely, implementation should remove any partially-written files, etc.
-
finish
public abstract void finish(FieldInfos fis, int numDocs) throws IOException
Called beforeclose(), passing in the number of documents that were written. Note that this is intentionally redundant (equivalent to the number of calls tostartDocument(int), 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 inmergeState. The default implementation skips over deleted documents, and usesstartDocument(int),writeField(FieldInfo, IndexableField), andfinish(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
-
addDocument
protected final void addDocument(Iterable<? extends IndexableField> doc, FieldInfos fieldInfos) throws IOException
sugar method for startDocument() + writeField() for every stored field in the document- Throws:
IOException
-
close
public abstract void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-