org.apache.commons.csv
Class CSVPrinter

java.lang.Object
  extended by org.apache.commons.csv.CSVPrinter

public class CSVPrinter
extends java.lang.Object

Print values as a comma separated list.


Field Summary
protected  boolean newLine
          True if we just began a new line.
protected  java.io.PrintWriter out
          The place that the values get written.
private  CSVStrategy strategy
           
 
Constructor Summary
CSVPrinter(java.io.OutputStream out)
          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.
 
Method Summary
private  java.lang.String escapeAndQuote(java.lang.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(java.lang.String value)
          Print the string as the next value on the line.
 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.
 CSVPrinter setStrategy(CSVStrategy strategy)
          Sets the specified CSV Strategy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.PrintWriter out
The place that the values get written.


newLine

protected boolean newLine
True if we just began a new line.


strategy

private CSVStrategy strategy
Constructor Detail

CSVPrinter

public CSVPrinter(java.io.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 '#'.

Parameters:
out - stream to which to print.

CSVPrinter

public CSVPrinter(java.io.Writer out)
Create a printer that will print values to the given stream. Comments will be written using the default comment character '#'.

Parameters:
out - stream to which to print.
Method Detail

setStrategy

public CSVPrinter setStrategy(CSVStrategy strategy)
Sets the specified CSV Strategy

Returns:
current instance of CSVParser to allow chained method calls

getStrategy

public CSVStrategy getStrategy()
Obtain the specified CSV Strategy

Returns:
strategy currently being used

println

public void println(java.lang.String value)
Print the string as the last value on the line. The value will be quoted if needed.

Parameters:
value - value to be outputted.

println

public void println()
Output a blank line


println

public void println(java.lang.String[] values)
Print a single line of comma separated values. The values will be quoted if needed. Quotes and newLine characters will be escaped.

Parameters:
values - values to be outputted.

println

public void println(java.lang.String[][] values)
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.

printlnComment

public void printlnComment(java.lang.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.

Parameters:
comment - the comment to output

print

public void print(java.lang.String value)
Print the string as the next value on the line. The value will be quoted if needed.

Parameters:
value - value to be outputted.

escapeAndQuote

private java.lang.String escapeAndQuote(java.lang.String value)
Enclose the value in quotes and escape the quote and comma characters that are inside.

Parameters:
value - needs to be escaped and quoted
Returns:
the value, escaped and quoted