|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectolg.csv.base.csv.CSVWriter
public class CSVWriter
CSV writer. CSV Implementation of IWriter.
Field Summary | |
---|---|
private String |
charsetName
Charset. |
private int |
currentLine
the index of the current line. |
private String |
ddelimiter
Double Delimiter. |
private char |
delimiter
Cell delimiter. |
private boolean |
forceDelimiter
Default value is CSVSettings.DEFAULT_FORCEDELIMITER . |
private String |
lineSeparator
Line break. |
private static org.slf4j.Logger |
LOGGER
The logger. |
private FileOutputStream |
outFile
the out file. |
private OutputStreamWriter |
outw
the Output writer. |
private char |
separator
Cell separator. |
private int |
size
the size of each CSV row. |
private boolean |
withHeaders
indicate if writing an header line is required? |
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. |
private void |
checkRow(Row row)
check if a row has the correct size and its num is >= the current line. |
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!) |
private String |
formatValue(String value)
add delimiter to a value if necessary or forced. |
boolean |
isWithHeaders()
Indicates if the file has a headers line. |
private StringBuilder |
padding(int begin,
int end)
create a stringBuider with end-begin empty csv fields. |
private void |
writeBlankLine(int num)
writes blank rows until reach a specific row (exclude). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final org.slf4j.Logger LOGGER
private char delimiter
CSVSettings.DEFAULT_DELIMITER
.
private String ddelimiter
private char separator
CSVSettings.DEFAULT_SEPARATOR
.
private String lineSeparator
CSVSettings.DEFAULT_LINESEPARATOR
.
private String charsetName
CSVSettings.DEFAULT_CHARSETNAME
.
private boolean withHeaders
CSVSettings.DEFAULT_WITHHEADERS
.
private final OutputStreamWriter outw
private FileOutputStream outFile
private boolean forceDelimiter
CSVSettings.DEFAULT_FORCEDELIMITER
.
private int size
private int currentLine
Constructor Detail |
---|
public CSVWriter(OutputStream out, CSVSettings settings)
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.for default values
public CSVWriter(File outFile, CSVSettings settings) throws FileNotFoundException
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.
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 reasonfor default values
Method Detail |
---|
public void addLine(String[] values)
IWriter.addRow(Row)
had been used first.
Throws a WriterException when line size differs from initial size.
addLine
in interface IWriter
values
- the row. Must be not null
with length >0. .public void addRow(Row 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.
addRow
in interface IWriter
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.public void close()
close
in interface Closeable
private String formatValue(String value)
value
- the value
private void writeBlankLine(int num)
num
- the row num to reachprivate StringBuilder padding(int begin, int end)
begin
- field index from which beginning the padding.end
- field index
private void checkRow(Row row)
row
- the row.public boolean isWithHeaders()
isWithHeaders
in interface IWriter
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |