|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.Ostermiller.util.CSVPrinter
public class CSVPrinter
Print values as a comma separated list. More information about this class is available from ostermiller.org.
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 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 Summary | |
---|---|
CSVPrinter(java.io.OutputStream out)
Create a printer that will print values to the given stream. |
|
CSVPrinter(java.io.OutputStream out,
char commentStart)
Create a printer that will print values to the given stream. |
|
CSVPrinter(java.io.Writer out)
Create a printer that will print values to the given stream. |
|
CSVPrinter(java.io.Writer out,
boolean alwaysQuote,
boolean autoFlush)
Create a printer that will print values to the given stream. |
|
CSVPrinter(java.io.Writer out,
char commentStart)
Create a printer that will print values to the given stream. |
|
CSVPrinter(java.io.Writer out,
char commentStart,
char quote,
char delimiter)
Create a printer that will print values to the given stream. |
|
CSVPrinter(java.io.Writer out,
char commentStart,
char quote,
char delimiter,
boolean alwaysQuote,
boolean autoFlush)
Create a printer that will print values to the given stream. |
|
CSVPrinter(java.io.Writer out,
char commentStart,
char quote,
char delimiter,
java.lang.String lineEnding)
Create a printer that will print values to the given stream. |
|
CSVPrinter(java.io.Writer out,
char commentStart,
char quote,
char delimiter,
java.lang.String lineEnding,
boolean alwaysQuote,
boolean autoFlush)
Create a printer that will print values to the given stream. |
Method Summary | |
---|---|
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)
Put a comment among the comma separated values. |
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)
Put a comment among the comma separated values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean autoFlush
protected boolean alwaysQuote
protected boolean error
protected char delimiterChar
protected char quoteChar
protected java.io.Writer out
protected boolean newLine
protected char commentStart
protected java.lang.String lineEnding
Constructor Detail |
---|
public CSVPrinter(java.io.OutputStream out)
out
- stream to which to print.public CSVPrinter(java.io.Writer out)
out
- stream to which to print.public CSVPrinter(java.io.OutputStream out, char commentStart)
out
- stream to which to print.commentStart
- Character used to start comments.public CSVPrinter(java.io.Writer out, char commentStart)
out
- stream to which to print.commentStart
- Character used to start comments.public CSVPrinter(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 CSVPrinter(java.io.Writer out, char commentStart, char quote, char delimiter) throws BadDelimiterException, BadQuoteException
out
- stream to which to print.commentStart
- Character used to start comments.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 CSVPrinter(java.io.Writer out, char commentStart, char quote, char delimiter, java.lang.String lineEnding) throws BadDelimiterException, BadQuoteException, BadLineEndingException
out
- stream to which to print.commentStart
- Character used to start comments.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 CSVPrinter(java.io.Writer out, char commentStart, char quote, char delimiter, boolean alwaysQuote, boolean autoFlush) throws BadDelimiterException, BadQuoteException
out
- stream to which to print.commentStart
- Character used to start comments.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 CSVPrinter(java.io.Writer out, char commentStart, char quote, char delimiter, java.lang.String lineEnding, boolean alwaysQuote, boolean autoFlush) throws BadDelimiterException, BadQuoteException, BadLineEndingException
out
- stream to which to print.commentStart
- Character used to start comments.delimiter
- The new delimiter character to use.lineEnding
- The new line ending, or null to use the default line ending.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.
BadLineEndingException
- if the line ending is not one of the three legal line endings.Method Detail |
---|
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.
println
in interface CSVPrint
value
- value to be outputted.public void writeln(java.lang.String value) throws java.io.IOException
writeln
in interface CSVPrint
value
- value to be outputted.
java.io.IOException
- if an error occurs while writing.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.
println
in interface CSVPrint
public void writeln() throws java.io.IOException
writeln
in interface CSVPrint
java.io.IOException
- if an error occurs while writing.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.
println
in interface CSVPrint
values
- values to be outputted.public void writeln(java.lang.String[] values) throws java.io.IOException
writeln
in interface CSVPrint
values
- values to be outputted.
java.io.IOException
- if an error occurs while writing.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.
print
in interface CSVPrint
values
- values to be outputted.public void write(java.lang.String[] values) throws java.io.IOException
write
in interface CSVPrint
values
- values to be outputted.
java.io.IOException
- if an error occurs while writing.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.
println
in interface CSVPrint
values
- values to be outputted.public void writeln(java.lang.String[][] values) throws java.io.IOException
writeln
in interface CSVPrint
values
- values to be outputted.
java.io.IOException
- if an error occurs while writing.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.public void writelnComment(java.lang.String comment) throws java.io.IOException
writelnComment
in interface CSVPrint
comment
- the comment to output.
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.
print
in interface CSVPrint
value
- value to be outputted.public void write(java.lang.String value) throws java.io.IOException
write
in interface CSVPrint
value
- value to be outputted.
java.io.IOException
- if an error occurs while writing.public void flush() throws java.io.IOException
flush
in interface CSVPrint
java.io.IOException
- if IO error occurspublic void close() throws java.io.IOException
close
in interface CSVPrint
java.io.IOException
- if IO error occurspublic boolean checkError()
checkError
in interface CSVPrint
public void setAutoFlush(boolean autoFlush)
setAutoFlush
in interface CSVPrint
autoFlush
- should auto flushing be enabled.public void setAlwaysQuote(boolean alwaysQuote)
setAlwaysQuote
in interface CSVPrint
alwaysQuote
- true if quotes should be used even when not strictly needed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |