Class FileWriter
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.file.FileWriter
Writes records to a binary stream that can be later read using a
FileReader.-
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.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
ConstructorsConstructorDescriptionFileWriter(DataOutput out) Creates an uncompressed writer that writes directly to the given output.FileWriter(File file) Creates an uncompressed writer that replaces the file's contents.FileWriter(File file, boolean append) Creates an uncompressed writer that appends to the file (if it exists) whenappendis true.FileWriter(File file, boolean append, boolean compressed) FileWriter(OutputStream outputStream, boolean compressed) -
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.booleanisAppend()Indicates if writing should start at the end of the file (if it exists).booleanIndicates if the underlying output stream should be closed when this stream closes (defaults to true).booleanIndicates if the data should be compressed as it is being written (default false).booleanIndicates if the underlying java.io.BufferedWriter should be flushed after each record is written.setAutoCloseWriter(boolean autoCloseWriter) Indicates if the underlying output stream 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.static Recordwrite(DataOutput out, Record record) Writes one record to the given output, flushing but not closing it, and returns the record.protected voidOverridden by subclasses to write the specified record to thisDataWriter.Methods inherited from class com.northconcepts.datapipeline.core.DataWriter
available, getNestedEndpoint, getNestedWriter, getRootEndpoint, getRootWriter, getWriter, writeMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, open, 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
-
FileWriter
- Parameters:
file- the file to write or append to.append- Indicates if writing should start at the end of the file (if it exists).compressed- Indicates if the data should be compressed as it is being written (default false).
-
FileWriter
- Parameters:
outputStream- the stream to write to.compressed- Indicates if the data should be compressed as it is being written.
-
FileWriter
Creates an uncompressed writer that appends to the file (if it exists) whenappendis true. -
FileWriter
Creates an uncompressed writer that replaces the file's contents. -
FileWriter
Creates an uncompressed writer that writes directly to the given output.
-
-
Method Details
-
write
Writes one record to the given output, flushing but not closing it, and returns the record. -
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 classDataWriter
-
isAppend
public boolean isAppend()Indicates if writing should start at the end of the file (if it exists). -
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. -
isAutoCloseWriter
public boolean isAutoCloseWriter()Indicates if the underlying output stream should be closed when this stream closes (defaults to true). -
setAutoCloseWriter
Indicates if the underlying output stream should be closed when this stream closes (defaults to true). -
isCompressed
public boolean isCompressed()Indicates if the data should be compressed as it is being written (default false). -
close
public void close()Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classDataEndpoint
-
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 —
-