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(java.io.Writer writer) |
Modifier and Type | Method and Description |
---|---|
void |
initializeListener(QueryBatcher queryBatcher)
This implementation of initializeListener adds this instance of
ExportToWriterListener to the two RetryListener's in this QueryBatcher so they
will retry any batches that fail during the read request.
|
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(java.lang.String prefix)
Sets the string prefix to send to the writer before each record.
|
ExportToWriterListener |
withRecordSuffix(java.lang.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.
|
getBatchFailureListeners, getDocs, getFailureListeners, onBatchFailure, onDocumentReady, onFailure, withConsistentSnapshot
public void initializeListener(QueryBatcher queryBatcher)
initializeListener
in interface QueryBatchListener
initializeListener
in class ExportListener
queryBatcher
- the QueryBatcher which will call this Listenerpublic void processEvent(QueryBatch batch)
ExportListener
processEvent
in interface BatchListener<QueryBatch>
processEvent
in interface QueryBatchListener
processEvent
in class ExportListener
batch
- the batch of uris and some metadata about the current status of the jobpublic ExportToWriterListener withRecordSuffix(java.lang.String suffix)
suffix
- the string suffixpublic ExportToWriterListener withRecordPrefix(java.lang.String prefix)
prefix
- the string prefixpublic ExportToWriterListener onGenerateOutput(ExportToWriterListener.OutputListener listener)
listener
- the custom listener (or lambda expression)public ExportToWriterListener withTransform(ServerTransform transform)
ExportListener
withTransform
in class ExportListener
transform
- the name of the transform already installed in the REST serverpublic ExportToWriterListener withMetadataCategory(DocumentManager.Metadata category)
DocumentRecord.getMetadata
in each DocumentRecord sent to the
OutputListener registered with onGenerateOutput. To specify the format
for the metdata, call withNonDocumentFormat
.withMetadataCategory
in class ExportListener
category
- the metadata category to retrieveDocumentManager.setMetadataCategories
public ExportToWriterListener withNonDocumentFormat(Format nonDocumentFormat)
withNonDocumentFormat
in class ExportListener
nonDocumentFormat
- the format for the metadataDocumentManager.setNonDocumentFormat
Copyright © 2013-2020 MarkLogic Corporation.