Class StreamWriter
java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.core.Endpoint
com.northconcepts.datapipeline.core.DataEndpoint
com.northconcepts.datapipeline.core.DataWriter
com.northconcepts.datapipeline.core.StreamWriter
Writes records to a stream in a human-readable format.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow aStreamWriterprints each record (after its 0-based number): plain text, JSON, XML, or text plus session properties.Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionStreamWriter(File file) Creates a writer that overwrites the file, which this constructor opens immediately, and closes it when this writer is closed.StreamWriter(OutputStream outputStream) Creates a writer that encodes with the default charset and leaves the stream open when this writer is closed (seesetCloseStream(boolean)).StreamWriter(Writer writer) Creates a writer that leaves the given writer open when this one is closed (seesetCloseStream(boolean)). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Indicates that this endpoint has finished reading or writing.booleanIndicates if the stream is closed when this writer is closed (defaults to false, or true when writing to a file).Returns how each record is printed (defaults toStreamWriter.Format.RECORD).static StreamWriterCreates a new instance of StreamWriter writing JSON to System.out.static StreamWriterCreates a new instance of StreamWriter writing to System.err.static StreamWriterCreates a new instance of StreamWriter writing to System.out.static StreamWriterCreates a new instance of StreamWriter writing to System.out with all session properties.static StreamWriterCreates a new instance of StreamWriter writing XML to System.out.voidopen()Makes this endpoint ready for reading or writing.setCloseStream(boolean closeStream) Specifies if the stream should be closed when this writer is closed (default is false).setFormat(StreamWriter.Format format) Sets how each record is printed; null meansStreamWriter.Format.RECORD(the default).protected voidOverridden by subclasses to write the specified record to thisDataWriter.Methods inherited from class com.northconcepts.datapipeline.core.DataWriter
addExceptionProperties, available, getNestedEndpoint, getNestedWriter, getRootEndpoint, getRootWriter, getWriter, writeMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription
-
Constructor Details
-
StreamWriter
Creates a writer that overwrites the file, which this constructor opens immediately, and closes it when this writer is closed.- Throws:
DataException
-
StreamWriter
Creates a writer that leaves the given writer open when this one is closed (seesetCloseStream(boolean)). -
StreamWriter
Creates a writer that encodes with the default charset and leaves the stream open when this writer is closed (seesetCloseStream(boolean)).
-
-
Method Details
-
newSystemOutWriter
Creates a new instance of StreamWriter writing to System.out. -
newJsonSystemOutWriter
Creates a new instance of StreamWriter writing JSON to System.out. -
newXmlSystemOutWriter
Creates a new instance of StreamWriter writing XML to System.out. -
newSystemErrWriter
Creates a new instance of StreamWriter writing to System.err. -
newSystemOutWriterWithSessionProperties
Creates a new instance of StreamWriter writing to System.out with all session properties. -
getFormat
Returns how each record is printed (defaults toStreamWriter.Format.RECORD). -
setFormat
Sets how each record is printed; null meansStreamWriter.Format.RECORD(the default). -
getCloseStream
public boolean getCloseStream()Indicates if the stream is closed when this writer is closed (defaults to false, or true when writing to a file). -
setCloseStream
Specifies if the stream should be closed when this writer is closed (default is false).- Parameters:
closeStream-- Returns:
- this writer
-
open
Description copied from class:DataEndpointMakes this endpoint ready for reading or writing.- Overrides:
openin classDataEndpoint- Throws:
DataException
-
close
Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classDataEndpoint- Throws:
DataException
-
writeImpl
Description copied from class:DataWriterOverridden by subclasses to write the specified record to thisDataWriter.Contract for subclasses (see also
docs/authoring/DataWriter.md):- Do not call this method directly —
DataWriter.write(Record)is the template method that wraps exceptions, increments the record count, and attaches the offending record to thrownDataExceptions. - Do not call
DataEndpoint.incrementRecordCount()here;DataWriter.write(Record)already does. - Throw raw exceptions;
DataWriter.write(Record)wraps them viaexception(throwable).setRecord(record).
- Specified by:
writeImplin classDataWriter- Throws:
Throwable
- Do not call this method directly —
-