| java.lang.Object com.Ostermiller.util.CSVPrinter
CSVPrinter | public class CSVPrinter implements CSVPrint(Code) | | Print values as a comma separated list.
More information about this class is available from ostermiller.org.
author: Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities author: Pierre Dittgen since: ostermillerutils 1.00.00 |
Field Summary | |
protected boolean | alwaysQuote If auto flushing is enabled. | protected boolean | autoFlush If auto flushing is enabled. | protected char | commentStart Character used to start comments. | protected char | delimiterChar Character written as field delimiter. | protected boolean | error true iff an error has occurred. | protected String | lineEnding | protected boolean | newLine True iff we just began a new line. | protected Writer | out The place that the values get written. | protected char | quoteChar Quoting character. |
Constructor Summary | |
public | CSVPrinter(OutputStream out) Create a printer that will print values to the given
stream. Character to byte conversion is done using
the default character encoding. Comments will be
written using the default comment character '#', the delimiter will
be the comma, the line ending will be the default system line ending,
the quote character will be double quotes,
quotes will be used when needed, and auto flushing
will be enabled. | public | CSVPrinter(Writer out) Create a printer that will print values to the given
stream. Comments will be
written using the default comment character '#', the delimiter will
be the comma, the line ending will be the default
system line ending, the quote character will be double quotes,
quotes will be used when needed, and auto flushing
will be enabled. | public | CSVPrinter(OutputStream out, char commentStart) Create a printer that will print values to the given
stream. Character to byte conversion is done using
the default character encoding. | public | CSVPrinter(Writer out, char commentStart) Create a printer that will print values to the given
stream. | public | CSVPrinter(Writer out, boolean alwaysQuote, boolean autoFlush) Create a printer that will print values to the given
stream. The comment character will be the number sign, the delimiter will
be the comma, the line ending will be the default
system line ending, and the quote character will be double quotes. | public | CSVPrinter(Writer out, char commentStart, char quote, char delimiter) Create a printer that will print values to the given
stream. The line ending will be the default system line
ending, quotes will be used when needed, and auto flushing
will be enabled. | public | CSVPrinter(Writer out, char commentStart, char quote, char delimiter, String lineEnding) Create a printer that will print values to the given
stream. Quotes will be used when needed, and auto flushing
will be enabled. | public | CSVPrinter(Writer out, char commentStart, char quote, char delimiter, boolean alwaysQuote, boolean autoFlush) Create a printer that will print values to the given
stream. | public | CSVPrinter(Writer out, char commentStart, char quote, char delimiter, String lineEnding, boolean alwaysQuote, boolean autoFlush) Create a printer that will print values to the given
stream. |
Method Summary | |
public void | changeDelimiter(char newDelimiter) Change this printer so that it uses a new delimiter. | public void | changeQuote(char newQuote) Change this printer so that it uses a new character for quoting. | public boolean | checkError() Flush the stream if it's not closed and check its error state. | public void | close() Close any underlying streams. | public void | flush() Flush any data written out to underlying streams. | public void | print(String[] values) Print a single line of comma separated values.
The values will be quoted if needed. | public void | print(String value) Print the string as the next value on the line. The value
will be quoted if needed. | public void | println(String value) Print the string as the last value on the line. The value
will be quoted if needed.
This method never throws an I/O exception. | public void | println() Output a blank line.
This method never throws an I/O exception. | public void | println(String[] values) Print a single line of comma separated values.
The values will be quoted if needed. | public void | println(String[][] values) Print several lines of comma separated values.
The values will be quoted if needed. | public void | printlnComment(String comment) Put a comment among the comma separated values.
Comments will always begin on a new line and occupy a
least one full line. | public void | setAlwaysQuote(boolean alwaysQuote) Set whether values printers should always be quoted, or
whether the printer may, at its discretion, omit quotes
around the value. | public void | setAutoFlush(boolean autoFlush) Set flushing behavior. | public void | setLineEnding(String lineEnding) Change this printer so that it uses a new line ending. | public void | write(String[] values) Print a single line of comma separated values.
The values will be quoted if needed. | public void | write(String value) Print the string as the next value on the line. The value
will be quoted if needed. | public void | writeln(String value) Print the string as the last value on the line. The value
will be quoted if needed. | public void | writeln() Output a blank line. | public void | writeln(String[] values) Print a single line of comma separated values.
The values will be quoted if needed. | public void | writeln(String[][] values) Print several lines of comma separated values.
The values will be quoted if needed. | public void | writelnComment(String comment) Put a comment among the comma separated values.
Comments will always begin on a new line and occupy a
least one full line. |
alwaysQuote | protected boolean alwaysQuote(Code) | | If auto flushing is enabled.
since: ostermillerutils 1.02.26 |
autoFlush | protected boolean autoFlush(Code) | | If auto flushing is enabled.
since: ostermillerutils 1.02.26 |
commentStart | protected char commentStart(Code) | | Character used to start comments. (Default is '#')
since: ostermillerutils 1.00.00 |
delimiterChar | protected char delimiterChar(Code) | | Character written as field delimiter.
since: ostermillerutils 1.02.18 |
error | protected boolean error(Code) | | true iff an error has occurred.
since: ostermillerutils 1.02.26 |
lineEnding | protected String lineEnding(Code) | | The line ending, must be one of "\n", "\r", or "\r\n"
since: ostermillerutils 1.06.01 |
newLine | protected boolean newLine(Code) | | True iff we just began a new line.
since: ostermillerutils 1.00.00 |
out | protected Writer out(Code) | | The place that the values get written.
since: ostermillerutils 1.00.00 |
quoteChar | protected char quoteChar(Code) | | Quoting character.
since: ostermillerutils 1.02.18 |
CSVPrinter | public CSVPrinter(OutputStream out)(Code) | | Create a printer that will print values to the given
stream. Character to byte conversion is done using
the default character encoding. Comments will be
written using the default comment character '#', the delimiter will
be the comma, the line ending will be the default system line ending,
the quote character will be double quotes,
quotes will be used when needed, and auto flushing
will be enabled.
Parameters: out - stream to which to print. since: ostermillerutils 1.00.00 |
CSVPrinter | public CSVPrinter(Writer out)(Code) | | Create a printer that will print values to the given
stream. Comments will be
written using the default comment character '#', the delimiter will
be the comma, the line ending will be the default
system line ending, the quote character will be double quotes,
quotes will be used when needed, and auto flushing
will be enabled.
Parameters: out - stream to which to print. since: ostermillerutils 1.00.00 |
CSVPrinter | public CSVPrinter(OutputStream out, char commentStart)(Code) | | Create a printer that will print values to the given
stream. Character to byte conversion is done using
the default character encoding. The delimiter will
be the comma, the line ending will be the default system
line ending, the quote character will be double quotes,
quotes will be used when needed, and auto flushing
will be enabled.
Parameters: out - stream to which to print. Parameters: commentStart - Character used to start comments. since: ostermillerutils 1.00.00 |
CSVPrinter | public CSVPrinter(Writer out, char commentStart)(Code) | | Create a printer that will print values to the given
stream. The delimiter will
be the comma, the line ending will be the default
system line ending, the quote character will be double quotes,
quotes will be used when needed, and auto flushing
will be enabled.
Parameters: out - stream to which to print. Parameters: commentStart - Character used to start comments. since: ostermillerutils 1.00.00 |
CSVPrinter | public CSVPrinter(Writer out, boolean alwaysQuote, boolean autoFlush)(Code) | | Create a printer that will print values to the given
stream. The comment character will be the number sign, the delimiter will
be the comma, the line ending will be the default
system line ending, and the quote character will be double quotes.
Parameters: out - stream to which to print. Parameters: alwaysQuote - true if quotes should be used even when not strictly needed. Parameters: autoFlush - should auto flushing be enabled. since: ostermillerutils 1.02.26 |
CSVPrinter | public CSVPrinter(Writer out, char commentStart, char quote, char delimiter) throws BadDelimiterException, BadQuoteException(Code) | | Create a printer that will print values to the given
stream. The line ending will be the default system line
ending, quotes will be used when needed, and auto flushing
will be enabled.
Parameters: out - stream to which to print. Parameters: commentStart - Character used to start comments. Parameters: delimiter - The new delimiter character to use. Parameters: quote - The new character to use for quoting. throws: BadQuoteException - if the character cannot be used as a quote. throws: BadDelimiterException - if the character cannot be used as a delimiter. since: ostermillerutils 1.02.26 |
CSVPrinter | public CSVPrinter(Writer out, char commentStart, char quote, char delimiter, String lineEnding) throws BadDelimiterException, BadQuoteException, BadLineEndingException(Code) | | Create a printer that will print values to the given
stream. Quotes will be used when needed, and auto flushing
will be enabled.
Parameters: out - stream to which to print. Parameters: commentStart - Character used to start comments. Parameters: delimiter - The new delimiter character to use. Parameters: quote - The new character to use for quoting. Parameters: lineEnding - The new line ending, or null to use the default line ending. throws: BadQuoteException - if the character cannot be used as a quote. throws: BadDelimiterException - if the character cannot be used as a delimiter. throws: BadLineEndingException - if the line ending is not one of the three legal line endings. since: ostermillerutils 1.06.01 |
CSVPrinter | public CSVPrinter(Writer out, char commentStart, char quote, char delimiter, boolean alwaysQuote, boolean autoFlush) throws BadDelimiterException, BadQuoteException(Code) | | Create a printer that will print values to the given
stream. The line ending will be the default system line ending,
Parameters: out - stream to which to print. Parameters: commentStart - Character used to start comments. Parameters: delimiter - The new delimiter character to use. Parameters: quote - The new character to use for quoting. Parameters: alwaysQuote - true if quotes should be used even when not strictly needed. Parameters: autoFlush - should auto flushing be enabled. throws: BadQuoteException - if the character cannot be used as a quote. throws: BadDelimiterException - if the character cannot be used as a delimiter. since: ostermillerutils 1.02.26 |
CSVPrinter | public CSVPrinter(Writer out, char commentStart, char quote, char delimiter, String lineEnding, boolean alwaysQuote, boolean autoFlush) throws BadDelimiterException, BadQuoteException, BadLineEndingException(Code) | | Create a printer that will print values to the given
stream.
Parameters: out - stream to which to print. Parameters: commentStart - Character used to start comments. Parameters: delimiter - The new delimiter character to use. Parameters: lineEnding - The new line ending, or null to use the default line ending. Parameters: quote - The new character to use for quoting. Parameters: alwaysQuote - true if quotes should be used even when not strictly needed. Parameters: autoFlush - should auto flushing be enabled. throws: BadQuoteException - if the character cannot be used as a quote. throws: BadDelimiterException - if the character cannot be used as a delimiter. throws: BadLineEndingException - if the line ending is not one of the three legal line endings. since: ostermillerutils 1.06.01 |
changeDelimiter | public void changeDelimiter(char newDelimiter) throws BadDelimiterException(Code) | | Change this printer so that it uses a new delimiter.
Parameters: newDelimiter - The new delimiter character to use. throws: BadDelimiterException - if the character cannot be used as a delimiter. author: Pierre Dittgen since: ostermillerutils 1.02.18 |
changeQuote | public void changeQuote(char newQuote) throws BadQuoteException(Code) | | Change this printer so that it uses a new character for quoting.
Parameters: newQuote - The new character to use for quoting. throws: BadQuoteException - if the character cannot be used as a quote. author: Pierre Dittgen since: ostermillerutils 1.02.18 |
checkError | public boolean checkError()(Code) | | Flush the stream if it's not closed and check its error state.
Errors are cumulative; once the stream encounters an error,
this routine will return true on all successive calls.
True if the print stream has encountered an error,either on the underlying output stream or during a format conversion. since: ostermillerutils 1.02.26 |
close | public void close() throws IOException(Code) | | Close any underlying streams.
throws: IOException - if IO error occurs since: ostermillerutils 1.02.26 |
flush | public void flush() throws IOException(Code) | | Flush any data written out to underlying streams.
throws: IOException - if IO error occurs since: ostermillerutils 1.02.26 |
print | public void print(String[] values)(Code) | | Print a single line of comma separated values.
The values will be quoted if needed. Quotes and
and other characters that need it will be escaped.
This method never throws an I/O exception. The client may inquire as to whether
any errors have occurred by invoking checkError(). If an I/O Exception is
desired, the client should use the corresponding writeln method.
Parameters: values - values to be outputted. since: ostermillerutils 1.00.00 |
print | public void print(String value)(Code) | | Print the string as the next value on the line. The value
will be quoted if needed. If value is null, an empty value is printed.
This method never throws an I/O exception. The client may inquire as to whether
any errors have occurred by invoking checkError(). If an I/O Exception is
desired, the client should use the corresponding println method.
Parameters: value - value to be outputted. since: ostermillerutils 1.00.00 |
println | public void println(String value)(Code) | | Print the string as the last value on the line. The value
will be quoted if needed.
This method never throws an I/O exception. The client may inquire as to whether
any errors have occurred by invoking checkError(). If an I/O Exception is
desired, the client should use the corresponding writeln method.
Parameters: value - value to be outputted. since: ostermillerutils 1.00.00 |
println | public void println()(Code) | | Output a blank line.
This method never throws an I/O exception. The client may inquire as to whether
any errors have occurred by invoking checkError(). If an I/O Exception is
desired, the client should use the corresponding writeln method.
since: ostermillerutils 1.00.00 |
println | public void println(String[] values)(Code) | | Print a single line of comma separated values.
The values will be quoted if needed. Quotes and
and other characters that need it will be escaped.
This method never throws an I/O exception. The client may inquire as to whether
any errors have occurred by invoking checkError(). If an I/O Exception is
desired, the client should use the corresponding writeln method.
Parameters: values - values to be outputted. since: ostermillerutils 1.00.00 |
println | public void println(String[][] values)(Code) | | Print several lines of comma separated values.
The values will be quoted if needed. Quotes and
newLine characters will be escaped.
This method never throws an I/O exception. The client may inquire as to whether
any errors have occurred by invoking checkError(). If an I/O Exception is
desired, the client should use the corresponding writeln method.
Parameters: values - values to be outputted. since: ostermillerutils 1.00.00 |
printlnComment | public void printlnComment(String comment)(Code) | | Put a comment among the comma separated values.
Comments will always begin on a new line and occupy a
least one full line. The character specified to star
comments and a space will be inserted at the beginning of
each new line in the comment. If the comment is null,
an empty comment is outputted.
This method never throws an I/O exception. The client may inquire as to whether
any errors have occurred by invoking checkError(). If an I/O Exception is
desired, the client should use the corresponding writelnComment method.
Parameters: comment - the comment to output. since: ostermillerutils 1.00.00 |
setAlwaysQuote | public void setAlwaysQuote(boolean alwaysQuote)(Code) | | Set whether values printers should always be quoted, or
whether the printer may, at its discretion, omit quotes
around the value.
Parameters: alwaysQuote - true if quotes should be used even when not strictly needed. since: ostermillerutils 1.02.26 |
setAutoFlush | public void setAutoFlush(boolean autoFlush)(Code) | | Set flushing behavior. Iff set, a flush command
will be issued to any underlying stream after each
print or write command.
Parameters: autoFlush - should auto flushing be enabled. since: ostermillerutils 1.02.26 |
setLineEnding | public void setLineEnding(String lineEnding) throws BadLineEndingException(Code) | | Change this printer so that it uses a new line ending.
A line ending must be one of "\n", "\r", or "\r\n".
The default line ending is the system line separator as specified by
System.getProperty("line.separator") , or "\n" if the system
line separator is not a legal line ending.
Parameters: lineEnding - The new line ending, or null to use the default line ending. throws: BadLineEndingException - if the line ending is not one of the three legal line endings. since: ostermillerutils 1.06.01 |
write | public void write(String[] values) throws IOException(Code) | | Print a single line of comma separated values.
The values will be quoted if needed. Quotes and
and other characters that need it will be escaped.
Parameters: values - values to be outputted. throws: IOException - if an error occurs while writing. since: ostermillerutils 1.02.26 |
write | public void write(String value) throws IOException(Code) | | Print the string as the next value on the line. The value
will be quoted if needed. If value is null, an empty value is printed.
Parameters: value - value to be outputted. throws: IOException - if an error occurs while writing. since: ostermillerutils 1.02.26 |
writeln | public void writeln(String value) throws IOException(Code) | | Print the string as the last value on the line. The value
will be quoted if needed.
Parameters: value - value to be outputted. throws: IOException - if an error occurs while writing. since: ostermillerutils 1.02.26 |
writeln | public void writeln() throws IOException(Code) | | Output a blank line.
throws: IOException - if an error occurs while writing. since: ostermillerutils 1.02.26 |
writeln | public void writeln(String[] values) throws IOException(Code) | | Print a single line of comma separated values.
The values will be quoted if needed. Quotes and
and other characters that need it will be escaped.
Parameters: values - values to be outputted. throws: IOException - if an error occurs while writing. since: ostermillerutils 1.02.26 |
writeln | public void writeln(String[][] values) throws IOException(Code) | | Print several lines of comma separated values.
The values will be quoted if needed. Quotes and
newLine characters will be escaped.
Parameters: values - values to be outputted. throws: IOException - if an error occurs while writing. since: ostermillerutils 1.02.26 |
writelnComment | public void writelnComment(String comment) throws IOException(Code) | | Put a comment among the comma separated values.
Comments will always begin on a new line and occupy a
least one full line. The character specified to star
comments and a space will be inserted at the beginning of
each new line in the comment. If the comment is null,
an empty comment is outputted.
Parameters: comment - the comment to output. throws: IOException - if an error occurs while writing. since: ostermillerutils 1.02.26 |
|
|