com.sparsity.dex.io
Class CSVWriter

java.lang.Object
  extended by com.sparsity.dex.io.RowWriter
      extended by com.sparsity.dex.io.CSVWriter

public class CSVWriter
extends RowWriter

CSVWriter interface.

A very simple CSV writer implementing RowWriter.

It works as any other RowWriter, but open must be called once before the first write operation.

It uses the format RFC 4180: http://tools.ietf.org/html/rfc4180

You can use your own separators and quote characters. By default the separator is the comma (,) and the quote character is the double quotes (") and autoquote is enabled.

See the CSVReader locale documentation or the DEX User Manual.

Check out the 'Data export' section in the DEX User Manual for more details on this.

Author:
Sparsity Technologies http://www.sparsity-technologies.com

Constructor Summary
CSVWriter()
          Creates a new instance.
 
Method Summary
 void close()
          Closes the writer.
 void open(java.lang.String f)
          Opens the output file path.
 void setAutoQuotes(boolean autoquotes)
          Sets on/off the automatic quote mode.
 void setForcedQuotes(BooleanList forcequotes)
          Disables the automatic quote mode and forces to be quoted those positions set to TRUE in the given vector.
 void setLocale(java.lang.String localeStr)
          Sets the locale that will be used to write the file.
 void setQuotes(java.lang.String quotes)
          Sets the character used to quote fields.
 void setSeparator(java.lang.String sep)
          Sets the character used to separate fields in the file.
 void write(StringList row)
          Writes the next row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVWriter

public CSVWriter()
Creates a new instance.

Method Detail

setSeparator

public void setSeparator(java.lang.String sep)
                  throws java.lang.RuntimeException
Sets the character used to separate fields in the file.

Parameters:
sep - [in] Separator character.
Throws:
java.lang.RuntimeException - null

setQuotes

public void setQuotes(java.lang.String quotes)
               throws java.lang.RuntimeException
Sets the character used to quote fields.

Parameters:
quotes - [in] Quote character.
Throws:
java.lang.RuntimeException - null

setLocale

public void setLocale(java.lang.String localeStr)
Sets the locale that will be used to write the file.

Parameters:
localeStr - [in] The locale string for the file encoding.

setForcedQuotes

public void setForcedQuotes(BooleanList forcequotes)
Disables the automatic quote mode and forces to be quoted those positions set to TRUE in the given vector.

Parameters:
forcequotes - [in] A booleanList with the position for each column that must be quoted set to true.

setAutoQuotes

public void setAutoQuotes(boolean autoquotes)
Sets on/off the automatic quote mode.

If there are forced quotes, setting autoquotes on will clear them. If the autoquotes is set to off and no forced quotes are provided, there will not be any quote.

Parameters:
autoquotes - [in] If TRUE it enables the automatic quote mode, if FALSE it disables it.

close

public void close()
           throws java.io.IOException,
                  java.lang.RuntimeException
Closes the writer.

Overrides:
close in class RowWriter
Throws:
java.io.IOException - If the close fails.
java.lang.RuntimeException - null

write

public void write(StringList row)
           throws java.io.IOException,
                  java.lang.RuntimeException
Writes the next row.

Overrides:
write in class RowWriter
Parameters:
row - [in] Row of data.
Throws:
java.io.IOException - If bad things happen during the write.
java.lang.RuntimeException - null

open

public void open(java.lang.String f)
          throws java.io.IOException
Opens the output file path.

Parameters:
f - [in] Output file path.
Throws:
java.io.IOException - If bad things happen opening the file.