public class ExcelCSVPrinter extends java.lang.Object implements CSVPrint
Modifier and Type | Field and Description |
---|---|
protected boolean |
alwaysQuote
If auto flushing is enabled.
|
protected boolean |
autoFlush
If auto flushing is enabled.
|
protected char |
delimiterChar
Character written as field delimiter.
|
protected boolean |
error
true iff an error has occurred.
|
protected java.lang.String |
lineEnding
The line ending, must be one of "\n", "\r", or "\r\n"
|
protected boolean |
newLine
True iff we just began a new line.
|
protected java.io.Writer |
out
The place that the values get written.
|
protected char |
quoteChar
Quoting character.
|
Constructor and Description |
---|
ExcelCSVPrinter(java.io.OutputStream out)
Create a printer that will print values to the given
stream.
|
ExcelCSVPrinter(java.io.Writer out)
Create a printer that will print values to the given
stream.
|
ExcelCSVPrinter(java.io.Writer out,
boolean alwaysQuote,
boolean autoFlush)
Create a printer that will print values to the given
stream.
|
ExcelCSVPrinter(java.io.Writer out,
char quote,
char delimiter)
Create a printer that will print values to the given
stream.
|
ExcelCSVPrinter(java.io.Writer out,
char quote,
char delimiter,
boolean alwaysQuote,
boolean autoFlush)
Create a printer that will print values to the given
stream.
|
ExcelCSVPrinter(java.io.Writer out,
char quote,
char delimiter,
java.lang.String lineEnding)
Create a printer that will print values to the given
stream.
|
ExcelCSVPrinter(java.io.Writer out,
char quote,
char delimiter,
java.lang.String lineEnding,
boolean alwaysQuote,
boolean autoFlush)
Create a printer that will print values to the given
stream.
|
Modifier and Type | Method and Description |
---|---|
void |
changeDelimiter(char newDelimiter)
Change this printer so that it uses a new delimiter.
|
void |
changeQuote(char newQuote)
Change this printer so that it uses a new character for quoting.
|
boolean |
checkError()
Flush the stream if it's not closed and check its error state.
|
void |
close()
Close any underlying streams.
|
void |
flush()
Flush any data written out to underlying streams.
|
void |
print(java.lang.String value)
Print the string as the next value on the line.
|
void |
print(java.lang.String[] values)
Print a single line of comma separated values.
|
void |
println()
Output a blank line.
|
void |
println(java.lang.String value)
Print the string as the last value on the line.
|
void |
println(java.lang.String[] values)
Print a single line of comma separated values.
|
void |
println(java.lang.String[][] values)
Print several lines of comma separated values.
|
void |
printlnComment(java.lang.String comment)
Since ExcelCSV format does not support comments,
this method will ignore the comment and start
a new row.
|
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.
|
void |
setAutoFlush(boolean autoFlush)
Set flushing behavior.
|
void |
setLineEnding(java.lang.String lineEnding)
Change this printer so that it uses a new line ending.
|
void |
write(java.lang.String value)
Print the string as the next value on the line.
|
void |
write(java.lang.String[] values)
Print a single line of comma separated values.
|
void |
writeln()
Output a blank line.
|
void |
writeln(java.lang.String value)
Print the string as the last value on the line.
|
void |
writeln(java.lang.String[] values)
Print a single line of comma separated values.
|
void |
writeln(java.lang.String[][] values)
Print several lines of comma separated values.
|
void |
writelnComment(java.lang.String comment)
Since ExcelCSV format does not support comments,
this method will ignore the comment and start
a new row.
|
protected boolean autoFlush
protected boolean alwaysQuote
protected boolean error
protected char delimiterChar
protected char quoteChar
protected java.io.Writer out
protected boolean newLine
protected java.lang.String lineEnding
public ExcelCSVPrinter(java.io.OutputStream out)
out
- stream to which to print.public ExcelCSVPrinter(java.io.Writer out)
out
- stream to which to print.public ExcelCSVPrinter(java.io.Writer out, boolean alwaysQuote, boolean autoFlush)
out
- stream to which to print.alwaysQuote
- true if quotes should be used even when not strictly needed.autoFlush
- should auto flushing be enabled.public ExcelCSVPrinter(java.io.Writer out, char quote, char delimiter) throws BadDelimiterException, BadQuoteException
out
- stream to which to print.delimiter
- The new delimiter character to use.quote
- The new character to use for quoting.BadQuoteException
- if the character cannot be used as a quote.BadDelimiterException
- if the character cannot be used as a delimiter.public ExcelCSVPrinter(java.io.Writer out, char quote, char delimiter, java.lang.String lineEnding) throws BadDelimiterException, BadQuoteException, BadLineEndingException
out
- stream to which to print.delimiter
- The new delimiter character to use.quote
- The new character to use for quoting.lineEnding
- The new line ending, or null to use the default line ending.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.public ExcelCSVPrinter(java.io.Writer out, char quote, char delimiter, boolean alwaysQuote, boolean autoFlush) throws BadDelimiterException, BadQuoteException
out
- stream to which to print.delimiter
- The new delimiter character to use.quote
- The new character to use for quoting.alwaysQuote
- true if quotes should be used even when not strictly needed.autoFlush
- should auto flushing be enabled.BadQuoteException
- if the character cannot be used as a quote.BadDelimiterException
- if the character cannot be used as a delimiter.public ExcelCSVPrinter(java.io.Writer out, char quote, char delimiter, java.lang.String lineEnding, boolean alwaysQuote, boolean autoFlush) throws BadDelimiterException, BadQuoteException, BadLineEndingException
out
- stream to which to print.delimiter
- The new delimiter character to use.quote
- The new character to use for quoting.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.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.public void changeDelimiter(char newDelimiter) throws BadDelimiterException
changeDelimiter
in interface CSVPrint
newDelimiter
- The new delimiter character to use.BadDelimiterException
- if the character cannot be used as a delimiter.public void changeQuote(char newQuote) throws BadQuoteException
changeQuote
in interface CSVPrint
newQuote
- The new character to use for quoting.BadQuoteException
- if the character cannot be used as a quote.public void setLineEnding(java.lang.String lineEnding) throws BadLineEndingException
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.
lineEnding
- The new line ending, or null to use the default line ending.BadLineEndingException
- if the line ending is not one of the three legal line endings.public void println(java.lang.String value)
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.
public void writeln(java.lang.String value) throws java.io.IOException
public void println()
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.
public void writeln() throws java.io.IOException
public void println(java.lang.String[] values)
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.
public void writeln(java.lang.String[] values) throws java.io.IOException
public void print(java.lang.String[] values)
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.
public void write(java.lang.String[] values) throws java.io.IOException
public void println(java.lang.String[][] values)
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.
public void writeln(java.lang.String[][] values) throws java.io.IOException
public void printlnComment(java.lang.String comment)
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.
printlnComment
in interface CSVPrint
comment
- the comment to output (ignored).public void writelnComment(java.lang.String comment) throws java.io.IOException
writelnComment
in interface CSVPrint
comment
- the comment to output (ignored).java.io.IOException
- if an error occurs while writing.public void print(java.lang.String value)
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.
public void write(java.lang.String value) throws java.io.IOException
public void flush() throws java.io.IOException
public void close() throws java.io.IOException
public boolean checkError()
checkError
in interface CSVPrint
public void setAlwaysQuote(boolean alwaysQuote)
setAlwaysQuote
in interface CSVPrint
alwaysQuote
- true if quotes should be used even when not strictly needed.public void setAutoFlush(boolean autoFlush)
setAutoFlush
in interface CSVPrint
autoFlush
- should auto flushing be enabled.Copyright (c) 2001-2020 by Stephen Ostermiller