edu.upc.dama.dex.io
Class CSVWriter

java.lang.Object
  extended by edu.upc.dama.dex.io.CSVWriter
All Implemented Interfaces:
RowWriter

public class CSVWriter
extends java.lang.Object
implements RowWriter

A very simple CSV writer. Using the format RFC 4180

Default values:
Separator = ','
Quote Character = '"'
Automatic quote = true

Author:
Sparsity Technologies

Field Summary
static boolean DEFAULT_AUTO_QUOTE
          Default autoquoted option
static char DEFAULT_QUOTE_CHARACTER
          The default quote character to use if none is supplied to the constructor.
static char DEFAULT_SEPARATOR
          Default separator character.
 
Constructor Summary
CSVWriter(java.io.Writer writer)
          Create a new instance of CSVWriter.
CSVWriter(java.io.Writer writer, char separator)
          Create a new instance of CSVWriter.
CSVWriter(java.io.Writer writer, char separator, char quotechar)
          Create a new instance of CSVWriter.
CSVWriter(java.io.Writer writer, char separator, char quotechar, boolean autoquote)
          Create a new instance of CSVWriter.
CSVWriter(java.io.Writer writer, char separator, char quotechar, boolean[] selectedquotes)
          Create a new instance of CSVWriter.
 
Method Summary
 void close()
          Closes the underlying writer.
 void writeNext(java.lang.String[] row)
          Writes the next row as a string array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SEPARATOR

public static final char DEFAULT_SEPARATOR
Default separator character.

See Also:
Constant Field Values

DEFAULT_QUOTE_CHARACTER

public static final char DEFAULT_QUOTE_CHARACTER
The default quote character to use if none is supplied to the constructor.

See Also:
Constant Field Values

DEFAULT_AUTO_QUOTE

public static final boolean DEFAULT_AUTO_QUOTE
Default autoquoted option

See Also:
Constant Field Values
Constructor Detail

CSVWriter

public CSVWriter(java.io.Writer writer)
Create a new instance of CSVWriter.

Parameters:
writer - Writer used to write the data.

CSVWriter

public CSVWriter(java.io.Writer writer,
                 char separator)
Create a new instance of CSVWriter.

Parameters:
writer - Writer used to write the data.
separator - Character used to separate the values.

CSVWriter

public CSVWriter(java.io.Writer writer,
                 char separator,
                 char quotechar,
                 boolean autoquote)
Create a new instance of CSVWriter.

Parameters:
writer - Writer used to write the data.
separator - Character used to separate the values.
quotechar - The character to use for quoted elements
autoquote - It allows the automatic quote in all the fields

CSVWriter

public CSVWriter(java.io.Writer writer,
                 char separator,
                 char quotechar,
                 boolean[] selectedquotes)
Create a new instance of CSVWriter.

Parameters:
writer - Writer used to write the data.
separator - Character used to separate the values.
quotechar - The character to use for quoted elements
selectedquotes - All fields mark as True are quoted.

CSVWriter

public CSVWriter(java.io.Writer writer,
                 char separator,
                 char quotechar)
Create a new instance of CSVWriter.

Parameters:
writer - Writer used to write the data.
separator - Character used to separate the values.
quotechar - The character to use for quoted elements
Method Detail

writeNext

public void writeNext(java.lang.String[] row)
               throws java.io.IOException
Writes the next row as a string array.

Specified by:
writeNext in interface RowWriter
Parameters:
row - Row of data as a string array.
Throws:
java.io.IOException - If bad things happen during the write.

close

public void close()
           throws java.io.IOException
Closes the underlying writer.

Specified by:
close in interface RowWriter
Throws:
java.io.IOException - If the close fails.