org.opencrx.application.uses.org.apache.commons.csv
Class CSVPrinter

java.lang.Object
  extended by org.opencrx.application.uses.org.apache.commons.csv.CSVPrinter
All Implemented Interfaces:
Closeable, Flushable

public class CSVPrinter
extends Object
implements Flushable, Closeable

Prints values in a CSV format.

Version:
$Id: $

Constructor Summary
CSVPrinter(Appendable out, CSVFormat format)
          Creates a printer that will print values to the given stream following the CSVFormat.
 
Method Summary
 void close()
           
 void flush()
          Flushes the underlying stream.
 void print(Object value)
          Prints the string as the next value on the line.
 void printComment(String comment)
          Prints a comment on a new line among the delimiter separated values.
 void println()
          Outputs the line separator.
 void printRecord(Iterable<?> values)
          Prints a single line of delimiter separated values.
 void printRecord(Object... values)
          Prints a single line of delimiter separated values.
 void printRecords(Iterable<?> values)
          Prints all the objects in the given collection.
 void printRecords(Object[] values)
          Prints all the objects in the given array.
 void printRecords(ResultSet resultSet)
          Prints all the objects in the given JDBC result set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVPrinter

public CSVPrinter(Appendable out,
                  CSVFormat format)
Creates a printer that will print values to the given stream following the CSVFormat.

Currently, only a pure encapsulation format or a pure escaping format is supported. Hybrid formats (encapsulation and escaping with a different character) are not supported.

Parameters:
out - stream to which to print.
format - the CSV format. If null the default format is used (CSVFormat.DEFAULT)
Throws:
IllegalArgumentException - thrown if the parameters of the format are inconsistent
Method Detail

println

public void println()
             throws IOException
Outputs the line separator.

Throws:
IOException

flush

public void flush()
           throws IOException
Flushes the underlying stream.

Specified by:
flush in interface Flushable
Throws:
IOException

printRecord

public void printRecord(Object... values)
                 throws IOException
Prints a single line of delimiter separated values. The values will be quoted if needed. Quotes and newLine characters will be escaped.

Parameters:
values - values to output.
Throws:
IOException

printRecord

public void printRecord(Iterable<?> values)
                 throws IOException
Prints a single line of delimiter separated values. The values will be quoted if needed. Quotes and newLine characters will be escaped.

Parameters:
values - values to output.
Throws:
IOException

printComment

public void printComment(String comment)
                  throws IOException
Prints a comment on a new line among the delimiter separated values. Comments will always begin on a new line and occupy a least one full line. The character specified to start comments and a space will be inserted at the beginning of each new line in the comment.

If comments are disabled in the current CSV format this method does nothing.

Parameters:
comment - the comment to output
Throws:
IOException

print

public void print(Object value)
           throws IOException
Prints the string as the next value on the line. The value will be escaped or encapsulated as needed.

Parameters:
value - value to be output.
Throws:
IOException - If an I/O error occurs

printRecords

public void printRecords(Object[] values)
                  throws IOException
Prints all the objects in the given array.

Parameters:
values - the values to print.
Throws:
IOException - If an I/O error occurs

printRecords

public void printRecords(Iterable<?> values)
                  throws IOException
Prints all the objects in the given collection.

Parameters:
values - the values to print.
Throws:
IOException - If an I/O error occurs

printRecords

public void printRecords(ResultSet resultSet)
                  throws SQLException,
                         IOException
Prints all the objects in the given JDBC result set.

Parameters:
resultSet - result set the values to print.
Throws:
IOException - If an I/O error occurs
SQLException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException


This software is published under the BSD license. Copyright © 2003-2013, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.