Class CSVWriter
java.lang.Object
Writes records to a Comma Separated Value (CSV) stream.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe interface used by null and empty string writers.static enumThe default implementation used to write null and empty string.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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.protected voidassembleLine(Record record, StringBuilder lineBuffer) Appends the record's output line, without a line terminator, to the empty buffer; also called for the header row (seeAbstractWriter.isHeaderRow()).Returns the object responsible for writing empty string values (defaults to ValuePolicy.QUOTED_EMPTY_STRING).Returns the string used to mark the ending of text values that may contain commas and other special characters (defaults to double quote - ").Returns the string used between each field value (defaults to comma).Returns the object responsible for writing null values (defaults to ValuePolicy.EMPTY_STRING).Returns the starting quote - same as calling getStartingQuote() (defaults to double quote - ").Returns the string used to mark the beginning of text values that may contain commas and other special characters (defaults to double quote - ").booleanReturns true if all values will be quoted, even if they are not null or empty strings.setAutoCloseWriter(boolean autoCloseWriter) Indicates if the underlying java.io.BufferedWriter should be closed when this stream closes (defaults to true).setDescription(String description) Sets the optional text shown for this endpoint inEndpoint.toString()and exception properties.setEmptyStringValuePolicy(CSVWriter.IValuePolicy emptyStringValuePolicy) Assigns the object responsible for writing empty string values (defaults to ValuePolicy.QUOTED_EMPTY_STRING).setEndingQuote(String endingQuote) Assigns the string used to mark the ending of text values that may contain commas and other special characters (defaults to double quote - ").setFieldNamesInFirstRow(boolean fieldNamesInFirstRow) Indicates if a header row of field names is written before the first record (default is true); must be called beforeAbstractWriter.open().setFieldSeparator(char fieldSeparator) Assigns the string used between each field value (defaults to comma).setFieldSeparator(String fieldSeparator) Assigns the string used between each field value (defaults to comma).setFlushOnWrite(boolean flushOnWrite) Indicates if the underlying java.io.BufferedWriter should be flushed after each record is written (defaults to false).setForceQuote(boolean force) Indicates if all values should be quoted, even if they are not null or empty strings.setNewLine(String newLine) Assigns the string used between each line (defaults to "\n" on Linux and "\r\n" on Windows).setNullValuePolicy(CSVWriter.IValuePolicy nullValuePolicy) Assigns the object responsible for writing null values (defaults to ValuePolicy.EMPTY_STRING).setQuoteChar(String quoteChar) Assigns startingQuote and endingQuote to the same value (defaults to double quote - ").setStartingQuote(String startingQuote) Assigns the string used to mark the beginning of text values that may contain commas and other special characters (defaults to double quote - ").Methods inherited from class com.northconcepts.datapipeline.core.LinedTextWriter
getNewLine, writeRecordMethods inherited from class com.northconcepts.datapipeline.core.TextWriter
close, getFile, getWriter, isAppend, isAutoCloseWriter, isFieldNamesInFirstRow, isFlushOnWrite, writeMethods inherited from class com.northconcepts.datapipeline.core.AbstractWriter
createHeaderRecord, isHeaderRow, open, writeImplMethods 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
-
Constructor Details
-
CSVWriter
- 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.
-
CSVWriter
-
CSVWriter
-
-
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 classLinedTextWriter
-
setNewLine
Assigns the string used between each line (defaults to "\n" on Linux and "\r\n" on Windows).- Overrides:
setNewLinein classLinedTextWriter
-
setForceQuote
Indicates if all values should be quoted, even if they are not null or empty strings. -
isForceQuote
public boolean isForceQuote()Returns true if all values will be quoted, even if they are not null or empty strings.- Returns:
- True if enabled, false otherwise
-
getFieldSeparator
Returns the string used between each field value (defaults to comma). -
setFieldSeparator
Assigns the string used between each field value (defaults to comma). -
setFieldSeparator
Assigns the string used between each field value (defaults to comma). -
getQuoteChar
Returns the starting quote - same as calling getStartingQuote() (defaults to double quote - ").getStartingQuote() -
setQuoteChar
Assigns startingQuote and endingQuote to the same value (defaults to double quote - ").setStartingQuote(String)setEndingQuote(String) -
getStartingQuote
Returns the string used to mark the beginning of text values that may contain commas and other special characters (defaults to double quote - "). -
setStartingQuote
Assigns the string used to mark the beginning of text values that may contain commas and other special characters (defaults to double quote - "). -
getEndingQuote
Returns the string used to mark the ending of text values that may contain commas and other special characters (defaults to double quote - "). -
setEndingQuote
Assigns the string used to mark the ending of text values that may contain commas and other special characters (defaults to double quote - "). -
getNullValuePolicy
Returns the object responsible for writing null values (defaults to ValuePolicy.EMPTY_STRING).- See Also:
-
setNullValuePolicy
Assigns the object responsible for writing null values (defaults to ValuePolicy.EMPTY_STRING).- See Also:
-
getEmptyStringValuePolicy
Returns the object responsible for writing empty string values (defaults to ValuePolicy.QUOTED_EMPTY_STRING).- See Also:
-
setEmptyStringValuePolicy
Assigns the object responsible for writing empty string values (defaults to ValuePolicy.QUOTED_EMPTY_STRING).- See Also:
-
setAutoCloseWriter
Description copied from class:TextWriterIndicates if the underlying java.io.BufferedWriter should be closed when this stream closes (defaults to true).- Overrides:
setAutoCloseWriterin classTextWriter
-
setFlushOnWrite
Description copied from class:TextWriterIndicates if the underlying java.io.BufferedWriter should be flushed after each record is written (defaults to false).- Overrides:
setFlushOnWritein classTextWriter
-
setFieldNamesInFirstRow
Description copied from class:AbstractWriterIndicates if a header row of field names is written before the first record (default is true); must be called beforeAbstractWriter.open().- Overrides:
setFieldNamesInFirstRowin classAbstractWriter
-
setDescription
Description copied from class:EndpointSets the optional text shown for this endpoint inEndpoint.toString()and exception properties.- Overrides:
setDescriptionin classEndpoint
-
assembleLine
Description copied from class:LinedTextWriterAppends the record's output line, without a line terminator, to the empty buffer; also called for the header row (seeAbstractWriter.isHeaderRow()).- Specified by:
assembleLinein classLinedTextWriter- Throws:
Throwable
-