Class CSVWriter
- java.lang.Object
- 
- com.inductiveautomation.ignition.common.util.csv.CSVWriter
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.lang.AutoCloseable
 
 public class CSVWriter extends java.lang.Object implements java.io.CloseableA very simple CSV writer released under a commercial-friendly license.
- 
- 
Field SummaryFields Modifier and Type Field Description static charDEFAULT_ESCAPE_CHARACTERThe character used for escaping quotes.static java.lang.StringDEFAULT_LINE_ENDDefault line terminator uses platform encoding.static charDEFAULT_QUOTE_CHARACTERThe default quote character to use if none is supplied to the constructor.static charDEFAULT_SEPARATORThe default separator to use if none is supplied to the constructor.static intINITIAL_STRING_SIZEstatic charNO_ESCAPE_CHARACTERThe escape constant to use when you wish to suppress all escaping.static charNO_QUOTE_CHARACTERThe quote constant to use when you wish to suppress all quoting.
 - 
Constructor SummaryConstructors Constructor Description CSVWriter(java.io.Writer writer)Constructs CSVWriter using a comma for the separator.CSVWriter(java.io.Writer writer, char separator)Constructs CSVWriter with supplied separator.CSVWriter(java.io.Writer writer, char separator, char quotechar)Constructs CSVWriter with supplied separator and quote char.CSVWriter(java.io.Writer writer, char separator, char quotechar, char escapechar)Constructs CSVWriter with supplied separator and quote char.CSVWriter(java.io.Writer writer, char separator, char quotechar, char escapechar, java.lang.String lineEnd)Constructs CSVWriter with supplied separator, quote char, escape char and line ending.CSVWriter(java.io.Writer writer, char separator, char quotechar, java.lang.String lineEnd)Constructs CSVWriter with supplied separator and quote char.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckError()Checks to see if the there has been an error in the printstream.voidclose()Close the underlying stream writer flushing any buffered content.voidflush()Flush underlying stream to writer.protected java.lang.StringBuilderprocessLine(java.lang.String nextElement)voidsetResultService(ResultSetHelper resultService)voidwriteAll(java.sql.ResultSet rs, boolean includeColumnNames)Writes the entire ResultSet to a CSV file.voidwriteAll(java.util.List<java.lang.String[]> allLines)Writes the entire list to a CSV file.protected voidwriteColumnNames(java.sql.ResultSet rs)voidwriteNext(java.lang.String[] nextLine)Writes the next line to the file.voidwriteNext(java.util.List<java.lang.String> nextLine)
 
- 
- 
- 
Field Detail- 
INITIAL_STRING_SIZEpublic static final int INITIAL_STRING_SIZE - See Also:
- Constant Field Values
 
 - 
DEFAULT_ESCAPE_CHARACTERpublic static final char DEFAULT_ESCAPE_CHARACTER The character used for escaping quotes.- See Also:
- Constant Field Values
 
 - 
DEFAULT_SEPARATORpublic static final char DEFAULT_SEPARATOR The default separator to use if none is supplied to the constructor.- See Also:
- Constant Field Values
 
 - 
DEFAULT_QUOTE_CHARACTERpublic static final char DEFAULT_QUOTE_CHARACTER The default quote character to use if none is supplied to the constructor.- See Also:
- Constant Field Values
 
 - 
NO_QUOTE_CHARACTERpublic static final char NO_QUOTE_CHARACTER The quote constant to use when you wish to suppress all quoting.- See Also:
- Constant Field Values
 
 - 
NO_ESCAPE_CHARACTERpublic static final char NO_ESCAPE_CHARACTER The escape constant to use when you wish to suppress all escaping.- See Also:
- Constant Field Values
 
 - 
DEFAULT_LINE_ENDpublic static final java.lang.String DEFAULT_LINE_END Default line terminator uses platform encoding.- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
CSVWriterpublic CSVWriter(java.io.Writer writer) Constructs CSVWriter using a comma for the separator.- Parameters:
- writer- the writer to an underlying CSV source.
 
 - 
CSVWriterpublic CSVWriter(java.io.Writer writer, char separator)Constructs CSVWriter with supplied separator.- Parameters:
- writer- the writer to an underlying CSV source.
- separator- the delimiter to use for separating entries.
 
 - 
CSVWriterpublic CSVWriter(java.io.Writer writer, char separator, char quotechar)Constructs CSVWriter with supplied separator and quote char.- Parameters:
- writer- the writer to an underlying CSV source.
- separator- the delimiter to use for separating entries
- quotechar- the character to use for quoted elements
 
 - 
CSVWriterpublic CSVWriter(java.io.Writer writer, char separator, char quotechar, char escapechar)Constructs CSVWriter with supplied separator and quote char.- Parameters:
- writer- the writer to an underlying CSV source.
- separator- the delimiter to use for separating entries
- quotechar- the character to use for quoted elements
- escapechar- the character to use for escaping quotechars or escapechars
 
 - 
CSVWriterpublic CSVWriter(java.io.Writer writer, char separator, char quotechar, java.lang.String lineEnd)Constructs CSVWriter with supplied separator and quote char.- Parameters:
- writer- the writer to an underlying CSV source.
- separator- the delimiter to use for separating entries
- quotechar- the character to use for quoted elements
- lineEnd- the line feed terminator to use
 
 - 
CSVWriterpublic CSVWriter(java.io.Writer writer, char separator, char quotechar, char escapechar, java.lang.String lineEnd)Constructs CSVWriter with supplied separator, quote char, escape char and line ending.- Parameters:
- writer- the writer to an underlying CSV source.
- separator- the delimiter to use for separating entries
- quotechar- the character to use for quoted elements
- escapechar- the character to use for escaping quotechars or escapechars
- lineEnd- the line feed terminator to use
 
 
- 
 - 
Method Detail- 
writeAllpublic void writeAll(java.util.List<java.lang.String[]> allLines) Writes the entire list to a CSV file. The list is assumed to be a String[]- Parameters:
- allLines- a List of String[], with each String[] representing a line of the file.
 
 - 
writeColumnNamesprotected void writeColumnNames(java.sql.ResultSet rs) throws java.sql.SQLException- Throws:
- java.sql.SQLException
 
 - 
writeAllpublic void writeAll(java.sql.ResultSet rs, boolean includeColumnNames) throws java.sql.SQLException, java.io.IOExceptionWrites the entire ResultSet to a CSV file.The caller is responsible for closing the ResultSet. - Parameters:
- rs- the recordset to write
- includeColumnNames- true if you want column names in the output, false otherwise
- Throws:
- java.io.IOException- thrown by getColumnValue
- java.sql.SQLException- thrown by getColumnValue
 
 - 
writeNextpublic void writeNext(java.util.List<java.lang.String> nextLine) 
 - 
writeNextpublic void writeNext(java.lang.String[] nextLine) Writes the next line to the file.- Parameters:
- nextLine- a string array with each comma-separated element as a separate entry.
 
 - 
processLineprotected java.lang.StringBuilder processLine(java.lang.String nextElement) 
 - 
flushpublic void flush() throws java.io.IOExceptionFlush underlying stream to writer.- Throws:
- java.io.IOException- if bad things happen
 
 - 
closepublic void close() throws java.io.IOExceptionClose the underlying stream writer flushing any buffered content.- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
- Throws:
- java.io.IOException- if bad things happen
 
 - 
checkErrorpublic boolean checkError() Checks to see if the there has been an error in the printstream.
 - 
setResultServicepublic void setResultService(ResultSetHelper resultService) 
 
- 
 
-