org.apache.commons.csv
Class CSVPrinter
java.lang.Object
org.apache.commons.csv.CSVPrinter
public class CSVPrinter
extends java.lang.Object
Print values as a comma separated list.
protected boolean | newLine - True if we just began a new line.
|
protected PrintWriter | out - The place that the values get written.
|
private CSVStrategy | strategy
|
CSVPrinter(OutputStream out) - Create a printer that will print values to the given
stream.
|
CSVPrinter(Writer out) - Create a printer that will print values to the given
stream.
|
private String | escapeAndQuote(String value) - Enclose the value in quotes and escape the quote
and comma characters that are inside.
|
CSVStrategy | getStrategy() - Obtain the specified CSV Strategy
|
void | print(String value) - Print the string as the next value on the line.
|
void | println() - Output a blank line
|
void | println(String value) - Print the string as the last value on the line.
|
void | println(String[] values) - Print a single line of comma separated values.
|
void | println(String[][] values) - Print several lines of comma separated values.
|
void | printlnComment(String comment) - Put a comment among the comma separated values.
|
CSVPrinter | setStrategy(CSVStrategy strategy) - Sets the specified CSV Strategy
|
newLine
protected boolean newLine
True if we just began a new line.
out
protected PrintWriter out
The place that the values get written.
CSVPrinter
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 '#'.
out
- stream to which to print.
CSVPrinter
public CSVPrinter(Writer out)
Create a printer that will print values to the given
stream. Comments will be
written using the default comment character '#'.
out
- stream to which to print.
escapeAndQuote
private String escapeAndQuote(String value)
Enclose the value in quotes and escape the quote
and comma characters that are inside.
value
- needs to be escaped and quoted
- the value, escaped and quoted
getStrategy
public CSVStrategy getStrategy()
Obtain the specified CSV Strategy
- strategy currently being used
print
public void print(String value)
Print the string as the next value on the line. The value
will be quoted if needed.
value
- value to be outputted.
println
public void println()
Output a blank line
println
public void println(String value)
Print the string as the last value on the line. The value
will be quoted if needed.
value
- value to be outputted.
println
public void println(String[] values)
Print a single line of comma separated values.
The values will be quoted if needed. Quotes and
newLine characters will be escaped.
values
- values to be outputted.
println
public void println(String[][] values)
Print several lines of comma separated values.
The values will be quoted if needed. Quotes and
newLine characters will be escaped.
values
- values to be outputted.
printlnComment
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. The character specified to star
comments and a space will be inserted at the beginning of
each new line in the comment.
comment
- the comment to output
setStrategy
public CSVPrinter setStrategy(CSVStrategy strategy)
Sets the specified CSV Strategy
- current instance of CSVParser to allow chained method calls