olg.csv.base.csv
Class CSVWriter

java.lang.Object
  extended by olg.csv.base.csv.CSVWriter
All Implemented Interfaces:
Closeable, IWriter

public class CSVWriter
extends Object
implements IWriter

CSV writer. CSV Implementation of IWriter.

Author:
Olivier Godineau

Constructor Summary
CSVWriter(File outFile, CSVSettings settings)
          Constructor.
CSVWriter(OutputStream out, CSVSettings settings)
          Constructor.
 
Method Summary
 void addLine(String[] values)
          Adds a row from the given String array.
 void addRow(Row row)
          Adds a row.
 void close()
          Close this stream and caught and logged IOException. if the parent stream is provided and passed to CSVWriter constructor by user, user must close it (close what you open!)
 boolean isWithHeaders()
          Indicates if the file has a headers line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVWriter

public CSVWriter(OutputStream out,
                 CSVSettings settings)
Constructor.

Parameters:
out - the stream on which to write. Must be not null.
settings - the CSV settings to use to write on the stream. Must be not null and must have a not null lineSeparator setting.
See Also:
for default values

CSVWriter

public CSVWriter(File outFile,
                 CSVSettings settings)
          throws FileNotFoundException
Constructor.

Parameters:
outFile - the file to write. Must be not null.
settings - the CSV settings to use to write on the file. Must be not null and have a not null lineSeparator setting.
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
See Also:
for default values
Method Detail

addLine

public void addLine(String[] values)
Adds a row from the given String array. The first time this method define the size ( as the given string array length) used along writing unless IWriter.addRow(Row) had been used first.

Throws a WriterException when line size differs from initial size.

Specified by:
addLine in interface IWriter
Parameters:
values - the row. Must be not null with length >0. .

addRow

public void addRow(Row row)
Adds a row.

The first row allows to define the size used along writing unless IWriter.addLine(String[]) had been used first.

Throws a WriterException when row size differs from initial size or row num is lesser than the expected next number line. Or if I/O error occurs during writing.

Specified by:
addRow in interface IWriter
Parameters:
row - the row. It's possible to use a row with no cells. In this case, an empty line(a line wich all fields are null) is added. It's possible to use a row with a num greater than the expected number. In this case, empty lines are wroten as much as necessary. It's possible to use row which all cells are not specified. In this case the missing cells are added as empty cells. Must be not null with cells correctly ordered and size>0.

close

public void close()
Close this stream and caught and logged IOException. if the parent stream is provided and passed to CSVWriter constructor by user, user must close it (close what you open!)

Specified by:
close in interface Closeable

isWithHeaders

public boolean isWithHeaders()
Indicates if the file has a headers line.

Specified by:
isWithHeaders in interface IWriter
Returns:
true if the file has a headers line.


Copyright © 2014. All rights reserved.