public class ExportToWriterListener extends ExportListener
An extension of ExportListener which facilitates writing all documents to a single Writer output stream. The Writer could be a FileWriter, for example, to write output to a CSV file. The Writer could pipe to a socket, for example, to send the output directly to another server endpoint.
By default only document contents are retrieved. If you would also like metadata, make sure to call withMetadataCategory to configure which categories of metadata you desire.
As with all the provided listeners, this listener will not meet the needs of all applications but the source code for it should serve as helpful sample code so you can write your own custom listeners.
| Modifier and Type | Class and Description |
|---|---|
static interface |
ExportToWriterListener.OutputListener
The listener interface required by onGenerateOutput.
|
| Constructor and Description |
|---|
ExportToWriterListener(Writer writer) |
| Modifier and Type | Method and Description |
|---|---|
ExportToWriterListener |
onGenerateOutput(ExportToWriterListener.OutputListener listener)
Registers a custom listener to override the default behavior for each document which sends the document contents to the writer.
|
void |
processEvent(QueryBatch batch)
This is the method QueryBatcher calls for ExportListener to do its thing.
|
ExportToWriterListener |
withMetadataCategory(DocumentManager.Metadata category)
Adds a metadata category to retrieve with each document.
|
ExportToWriterListener |
withNonDocumentFormat(Format nonDocumentFormat)
The format for the metadata retrieved with each document.
|
ExportToWriterListener |
withRecordPrefix(String prefix)
Sets the string prefix to send to the writer before each record.
|
ExportToWriterListener |
withRecordSuffix(String suffix)
Sets the string suffix to append to the writer after each record.
|
ExportToWriterListener |
withTransform(ServerTransform transform)
Sets the server tranform to modify the document contents.
|
onBatchFailure, onDocumentReady, withConsistentSnapshotpublic ExportToWriterListener(Writer writer)
public void processEvent(QueryBatch batch)
ExportListenerThis is the method QueryBatcher calls for ExportListener to do its thing. You should not need to call it.
processEvent in interface BatchListener<QueryBatch>processEvent in interface QueryBatchListenerprocessEvent in class ExportListenerbatch - the batch of uris and some metadata about the current status of the jobpublic ExportToWriterListener withRecordSuffix(String suffix)
Sets the string suffix to append to the writer after each record.
suffix - the string suffixpublic ExportToWriterListener withRecordPrefix(String prefix)
Sets the string prefix to send to the writer before each record.
prefix - the string prefixpublic ExportToWriterListener onGenerateOutput(ExportToWriterListener.OutputListener listener)
Registers a custom listener to override the default behavior for each document which sends the document contents to the writer. This listener can choose what string to send to the writer for each document.
listener - the custom listener (or lambda expression)public ExportToWriterListener withTransform(ServerTransform transform)
ExportListenerSets the server tranform to modify the document contents.
withTransform in class ExportListenertransform - the name of the transform already installed in the REST serverpublic ExportToWriterListener withMetadataCategory(DocumentManager.Metadata category)
Adds a metadata category to retrieve with each document. The metadata will be available via DocumentRecord.getMetadata in each DocumentRecord sent to the OutputListener registered with onGenerateOutput. To specify the format for the metdata, call withNonDocumentFormat.
withMetadataCategory in class ExportListenercategory - the metadata category to retrieveDocumentManager.setMetadataCategoriespublic ExportToWriterListener withNonDocumentFormat(Format nonDocumentFormat)
The format for the metadata retrieved with each document. The metadata will be available in each DocumentRecord sent to the OutputListener registered with onGenerateOutput.
withNonDocumentFormat in class ExportListenernonDocumentFormat - the format for the metadataDocumentManager.setNonDocumentFormatCopyright © 2013-2017 MarkLogic Corporation.