Class CSVWriter
java.lang.Object
com.inductiveautomation.ignition.common.util.csv.CSVWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
A very simple CSV writer released under a commercial-friendly license.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char
The character used for escaping quotes.static final String
Default line terminator uses platform encoding.static final char
The default quote character to use if none is supplied to the constructor.static final char
The default separator to use if none is supplied to the constructor.static final int
static final char
The escape constant to use when you wish to suppress all escaping.static final char
The quote constant to use when you wish to suppress all quoting. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs CSVWriter using a comma for the separator.Constructs CSVWriter with supplied separator.Constructs CSVWriter with supplied separator and quote char.Constructs CSVWriter with supplied separator and quote char.Constructs CSVWriter with supplied separator, quote char, escape char and line ending.Constructs CSVWriter with supplied separator and quote char. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks to see if the there has been an error in the printstream.void
close()
Close the underlying stream writer flushing any buffered content.void
flush()
Flush underlying stream to writer.protected StringBuilder
processLine
(String nextElement) void
setResultService
(ResultSetHelper resultService) void
Writes the entire ResultSet to a CSV file.void
Writes the entire list to a CSV file.protected void
void
Writes the next line to the file.void
-
Field Details
-
INITIAL_STRING_SIZE
public static final int INITIAL_STRING_SIZE- See Also:
-
DEFAULT_ESCAPE_CHARACTER
public static final char DEFAULT_ESCAPE_CHARACTERThe character used for escaping quotes.- See Also:
-
DEFAULT_SEPARATOR
public static final char DEFAULT_SEPARATORThe default separator to use if none is supplied to the constructor.- See Also:
-
DEFAULT_QUOTE_CHARACTER
public static final char DEFAULT_QUOTE_CHARACTERThe default quote character to use if none is supplied to the constructor.- See Also:
-
NO_QUOTE_CHARACTER
public static final char NO_QUOTE_CHARACTERThe quote constant to use when you wish to suppress all quoting.- See Also:
-
NO_ESCAPE_CHARACTER
public static final char NO_ESCAPE_CHARACTERThe escape constant to use when you wish to suppress all escaping.- See Also:
-
DEFAULT_LINE_END
Default line terminator uses platform encoding.- See Also:
-
-
Constructor Details
-
CSVWriter
Constructs CSVWriter using a comma for the separator.- Parameters:
writer
- the writer to an underlying CSV source.
-
CSVWriter
Constructs CSVWriter with supplied separator.- Parameters:
writer
- the writer to an underlying CSV source.separator
- the delimiter to use for separating entries.
-
CSVWriter
Constructs CSVWriter with supplied separator and quote char.- Parameters:
writer
- the writer to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elements
-
CSVWriter
Constructs CSVWriter with supplied separator and quote char.- Parameters:
writer
- the writer to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementsescapechar
- the character to use for escaping quotechars or escapechars
-
CSVWriter
Constructs CSVWriter with supplied separator and quote char.- Parameters:
writer
- the writer to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementslineEnd
- the line feed terminator to use
-
CSVWriter
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 entriesquotechar
- the character to use for quoted elementsescapechar
- the character to use for escaping quotechars or escapecharslineEnd
- the line feed terminator to use
-
-
Method Details
-
writeAll
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.
-
writeColumnNames
- Throws:
SQLException
-
writeAll
Writes the entire ResultSet to a CSV file.The caller is responsible for closing the ResultSet.
- Parameters:
rs
- the recordset to writeincludeColumnNames
- true if you want column names in the output, false otherwise- Throws:
IOException
- thrown by getColumnValueSQLException
- thrown by getColumnValue
-
writeNext
-
writeNext
Writes the next line to the file.- Parameters:
nextLine
- a string array with each comma-separated element as a separate entry.
-
processLine
-
flush
Flush underlying stream to writer.- Throws:
IOException
- if bad things happen
-
close
Close the underlying stream writer flushing any buffered content.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if bad things happen
-
checkError
public boolean checkError()Checks to see if the there has been an error in the printstream. -
setResultService
-