Class TextWriter
- Direct Known Subclasses:
H2InsertWriter,JsonWriter,LatexWriter,LinedTextWriter,MySqlInsertWriter,PostgreSqlInsertWriter,SimpleJsonWriter,SimpleXmlWriter,TemplateWriter,TextTableWriter,XmlWriter
Abstract super-class for writing records to a text stream. Unike
TextStreamWriter, this writer has the concept of
fieldNamesInFirstRow and assumes the output is line based.-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.AbstractWriter
currentRecordFields 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
ConstructorsConstructorDescriptionTextWriter(File file) Creates a writer that overwrites the file, which this constructor opens immediately rather than inopen().TextWriter(File file, boolean append) TextWriter(Writer writer) -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.voidclose()Indicates that this endpoint has finished reading or writing.getFile()Returns the target file or null if this writer was created from aWriter.booleanisAppend()Indicates if writing should start at the end of the file (if it exists).booleanIndicates if the underlying java.io.BufferedWriter should be closed when this stream closes (defaults to true).booleanIndicates if a header row of field names is written before the first record (default is true).booleanIndicates if the underlying java.io.BufferedWriter should be flushed after each record is written.setAutoCloseWriter(boolean autoCloseWriter) Indicates if the underlying java.io.BufferedWriter should be closed when this stream closes (defaults to true).setFlushOnWrite(boolean flushOnWrite) Indicates if the underlying java.io.BufferedWriter should be flushed after each record is written (defaults to false).voidWrites the specified record to thisDataWriterand increases the record-count by 1.Methods inherited from class com.northconcepts.datapipeline.core.AbstractWriter
createHeaderRecord, isHeaderRow, open, setFieldNamesInFirstRow, writeImpl, writeRecordMethods inherited from class com.northconcepts.datapipeline.core.DataWriter
available, getNestedEndpoint, getNestedWriter, getRootEndpoint, getRootWriter, getWriterMethods 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
-
TextWriter
- Parameters:
file-append- Indicates if writing should start at the end of the file (if it exists). If the specified file exists and has contents (more than 0 bytes), then thefieldNamesInFirstRowproperty will be set tofalse.
-
TextWriter
Creates a writer that overwrites the file, which this constructor opens immediately rather than inopen(). -
TextWriter
-
-
Method Details
-
addExceptionProperties
Description copied from class:EndpointAdds this endpoint's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Overrides:
addExceptionPropertiesin classAbstractWriter
-
getWriter
-
getFile
Returns the target file or null if this writer was created from aWriter. -
isFieldNamesInFirstRow
public boolean isFieldNamesInFirstRow()Description copied from class:AbstractWriterIndicates if a header row of field names is written before the first record (default is true).- Overrides:
isFieldNamesInFirstRowin classAbstractWriter
-
isAppend
public boolean isAppend()Indicates if writing should start at the end of the file (if it exists). If the specified file exists and has contents (more than 0 bytes), then thefieldNamesInFirstRowproperty will be set tofalse.- See Also:
-
isAutoCloseWriter
public boolean isAutoCloseWriter()Indicates if the underlying java.io.BufferedWriter should be closed when this stream closes (defaults to true). -
setAutoCloseWriter
Indicates if the underlying java.io.BufferedWriter should be closed when this stream closes (defaults to true). -
isFlushOnWrite
public boolean isFlushOnWrite()Indicates if the underlying java.io.BufferedWriter should be flushed after each record is written. -
setFlushOnWrite
Indicates if the underlying java.io.BufferedWriter should be flushed after each record is written (defaults to false). -
close
public void close()Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classDataEndpoint
-
write
Description copied from class:DataWriterWrites the specified record to thisDataWriterand increases the record-count by 1. Any exception raised while writing will be converted to aDataExceptionusingDataObject.exception(Throwable).Subclasses generally do not need to override this method, instead they should implement
DataWriter.writeImpl(Record).- Overrides:
writein classAbstractWriter- Throws:
DataException
-