Class ExcelCSVPrinter
- All Implemented Interfaces:
CSVPrint
- Since:
- ostermillerutils 1.00.00
- Author:
- Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities, Pierre Dittgen <pierre dot dittgen at pass-tech dot fr>
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a printer that will print values to the given stream.ExcelCSVPrinter(Writer out) Create a printer that will print values to the given stream.ExcelCSVPrinter(Writer out, boolean alwaysQuote, boolean autoFlush) Create a printer that will print values to the given stream.ExcelCSVPrinter(Writer out, char quote, char delimiter) Create a printer that will print values to the given stream.ExcelCSVPrinter(Writer out, char quote, char delimiter, boolean alwaysQuote, boolean autoFlush) Create a printer that will print values to the given stream.ExcelCSVPrinter(Writer out, char quote, char delimiter, String lineEnding) Create a printer that will print values to the given stream.ExcelCSVPrinter(Writer out, char quote, char delimiter, String lineEnding, boolean alwaysQuote, boolean autoFlush) Create a printer that will print values to the given stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeDelimiter(char newDelimiter) Change this printer so that it uses a new delimiter.voidchangeQuote(char newQuote) Change this printer so that it uses a new character for quoting.booleanFlush the stream if it's not closed and check its error state.voidclose()Close any underlying streams.voidflush()Flush any data written out to underlying streams.voidPrint the string as the next value on the line.voidPrint a single line of comma separated values.voidprintln()Output a blank line.voidPrint the string as the last value on the line.voidPrint a single line of comma separated values.voidPrint several lines of comma separated values.voidprintlnComment(String comment) Since ExcelCSV format does not support comments, this method will ignore the comment and start a new row.voidsetAlwaysQuote(boolean alwaysQuote) Set whether values printers should always be quoted, or whether the printer may, at its discretion, omit quotes around the value.voidsetAutoFlush(boolean autoFlush) Set flushing behavior.voidsetLineEnding(String lineEnding) Change this printer so that it uses a new line ending.voidPrint the string as the next value on the line.voidPrint a single line of comma separated values.voidwriteln()Output a blank line.voidPrint the string as the last value on the line.voidPrint a single line of comma separated values.voidPrint several lines of comma separated values.voidwritelnComment(String comment) Since ExcelCSV format does not support comments, this method will ignore the comment and start a new row.
-
Constructor Details
-
ExcelCSVPrinter
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.- Since:
- ostermillerutils 1.00.00
-
ExcelCSVPrinter
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.- Since:
- ostermillerutils 1.00.00
-
ExcelCSVPrinter
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, and the quote character will be double quotes.- Parameters:
out- stream to which to print.alwaysQuote- true if quotes should be used even when not strictly needed.autoFlush- should auto flushing be enabled.- Since:
- ostermillerutils 1.02.26
-
ExcelCSVPrinter
public ExcelCSVPrinter(Writer out, char quote, char delimiter) throws BadDelimiterException, BadQuoteException 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.quote- The new character to use for quoting.delimiter- The new delimiter character to use.- Throws:
BadQuoteException- if the character cannot be used as a quote.BadDelimiterException- if the character cannot be used as a delimiter.- Since:
- ostermillerutils 1.02.26
-
ExcelCSVPrinter
public ExcelCSVPrinter(Writer out, char quote, char delimiter, String lineEnding) throws BadDelimiterException, BadQuoteException, BadLineEndingException 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.quote- The new character to use for quoting.delimiter- The new delimiter character to use.lineEnding- The new line ending, or null to use the default line ending.- Throws:
BadQuoteException- if the character cannot be used as a quote.BadDelimiterException- if the character cannot be used as a delimiter.BadLineEndingException- if the line ending is not one of the three legal line endings.- Since:
- ostermillerutils 1.06.01
-
ExcelCSVPrinter
public ExcelCSVPrinter(Writer out, char quote, char delimiter, boolean alwaysQuote, boolean autoFlush) throws BadDelimiterException, BadQuoteException 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.quote- The new character to use for quoting.delimiter- The new delimiter character to use.alwaysQuote- true if quotes should be used even when not strictly needed.autoFlush- should auto flushing be enabled.- Throws:
BadQuoteException- if the character cannot be used as a quote.BadDelimiterException- if the character cannot be used as a delimiter.- Since:
- ostermillerutils 1.02.26
-
ExcelCSVPrinter
public ExcelCSVPrinter(Writer out, char quote, char delimiter, String lineEnding, boolean alwaysQuote, boolean autoFlush) throws BadDelimiterException, BadQuoteException, BadLineEndingException Create a printer that will print values to the given stream.- Parameters:
out- stream to which to print.quote- The new character to use for quoting.delimiter- The new delimiter character to use.lineEnding- The new line ending, or null to use the default line ending.alwaysQuote- true if quotes should be used even when not strictly needed.autoFlush- should auto flushing be enabled.- Throws:
BadQuoteException- if the character cannot be used as a quote.BadDelimiterException- if the character cannot be used as a delimiter.BadLineEndingException- if the line ending is not one of the three legal line endings.- Since:
- ostermillerutils 1.06.01
-
-
Method Details
-
changeDelimiter
Change this printer so that it uses a new delimiter.- Specified by:
changeDelimiterin interfaceCSVPrint- Parameters:
newDelimiter- The new delimiter character to use.- Throws:
BadDelimiterException- if the character cannot be used as a delimiter.- Since:
- ostermillerutils 1.02.18
-
changeQuote
Change this printer so that it uses a new character for quoting.- Specified by:
changeQuotein interfaceCSVPrint- Parameters:
newQuote- The new character to use for quoting.- Throws:
BadQuoteException- if the character cannot be used as a quote.- Since:
- ostermillerutils 1.02.18
-
setLineEnding
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
-
println
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.
-
writeln
Print the string as the last value on the line. The value will be quoted if needed.- Specified by:
writelnin interfaceCSVPrint- Parameters:
value- value to be outputted.- Throws:
IOException- if an error occurs while writing.- Since:
- ostermillerutils 1.02.26
-
println
public void println()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.
-
writeln
Output a blank line.- Specified by:
writelnin interfaceCSVPrint- Throws:
IOException- if an error occurs while writing.- Since:
- ostermillerutils 1.02.26
-
println
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.
-
writeln
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.- Specified by:
writelnin interfaceCSVPrint- Parameters:
values- values to be outputted.- Throws:
IOException- if an error occurs while writing.- Since:
- ostermillerutils 1.02.26
-
print
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.
-
write
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.- Specified by:
writein interfaceCSVPrint- Parameters:
values- values to be outputted.- Throws:
IOException- if an error occurs while writing.- Since:
- ostermillerutils 1.02.26
-
println
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.
-
writeln
Print several lines of comma separated values. The values will be quoted if needed. Quotes and newLine characters will be escaped.- Specified by:
writelnin interfaceCSVPrint- Parameters:
values- values to be outputted.- Throws:
IOException- if an error occurs while writing.- Since:
- ostermillerutils 1.02.26
-
printlnComment
Since ExcelCSV format does not support comments, this method will ignore the comment and start a new row.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.
- Specified by:
printlnCommentin interfaceCSVPrint- Parameters:
comment- the comment to output (ignored).- Since:
- ostermillerutils 1.00.00
-
writelnComment
Since ExcelCSV format does not support comments, this method will ignore the comment and start a new row.- Specified by:
writelnCommentin interfaceCSVPrint- Parameters:
comment- the comment to output (ignored).- Throws:
IOException- if an error occurs while writing.- Since:
- ostermillerutils 1.02.26
-
print
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.
-
write
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.- Specified by:
writein interfaceCSVPrint- Parameters:
value- value to be outputted.- Throws:
IOException- if an error occurs while writing.- Since:
- ostermillerutils 1.02.26
-
flush
Flush any data written out to underlying streams.- Specified by:
flushin interfaceCSVPrint- Throws:
IOException- if an error occurs while writing.- Since:
- ostermillerutils 1.02.26
-
close
Close any underlying streams.- Specified by:
closein interfaceCSVPrint- Throws:
IOException- if an error occurs while writing.- Since:
- ostermillerutils 1.02.26
-
checkError
public boolean checkError()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.- Specified by:
checkErrorin interfaceCSVPrint- Returns:
- 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
-
setAlwaysQuote
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.- Specified by:
setAlwaysQuotein interfaceCSVPrint- Parameters:
alwaysQuote- true if quotes should be used even when not strictly needed.- Since:
- ostermillerutils 1.02.26
-
setAutoFlush
public void setAutoFlush(boolean autoFlush) Set flushing behavior. Iff set, a flush command will be issued to any underlying stream after each print or write command.- Specified by:
setAutoFlushin interfaceCSVPrint- Parameters:
autoFlush- should auto flushing be enabled.- Since:
- ostermillerutils 1.02.26
-