|
Copyright © 2008-2011 Ralph Schuster. All Rights Reserved. | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcsv.impl.AbstractTableWriter
csv.impl.AbstractStreamTableWriter
csv.impl.CSVWriter
public class CSVWriter
Implements functionality for writing CSV streams. Example:
java.io.File f = new java.io.File("csv-test.csv");
CSVWriter out = new CSVWriter(f);
out.printRow(new Object[] { "0:0", "0:1", "0:2" });
out.printRow(new Object[] { "1:0", "1:1", "1:2" });
out.close();
| Constructor Summary | |
|---|---|
CSVWriter()
Default constructor. |
|
CSVWriter(java.io.File file)
Constructor for writing into a file. |
|
CSVWriter(java.io.OutputStream out)
Constructor for writing into a stream. |
|
CSVWriter(java.lang.String file)
Constructor for writing into a file. |
|
CSVWriter(java.io.Writer out)
Deprecated. Use CSVWriter(OutputStream) instead. |
|
CSVWriter(java.io.Writer out,
boolean flush)
Deprecated. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the underlying stream. |
protected boolean |
columnNeedsDelimiting(java.lang.String s)
Decides if a column value needs to be wrapped with delimiters. |
int |
getColumnCount()
Returns the columns written to the stream. |
java.lang.String |
getColumnDelimiter()
Returns the column delimiter to be used. |
char |
getColumnSeparator()
Returns the column separator to be used. |
char |
getCommentChar()
Returns the character used for indicating comments |
java.lang.String |
getRowSeparator()
Returns the row separator to be used. |
java.io.PrintWriter |
getWriter()
Returns the underlying stream. |
protected void |
init()
Initializes the writer. |
boolean |
isColumnDelimiterRequired()
Returns whether column delimiters are always required. |
protected java.lang.String |
prepareColumnValue(java.lang.String s)
Replaces all occurrences of the delimiter by doubling it. |
java.lang.String |
prepareComment(java.lang.String comment)
Formats a comment for printing |
java.lang.String |
prepareRow(java.lang.Object[] columns)
Formats a row for CSV output. |
void |
printComment(java.lang.String comment)
Prints a comment into the CSV stream. |
void |
printComment(java.lang.String comment,
int row,
int column)
Prints a comment into the stream. |
void |
printRow(java.util.Collection<?> columns)
Prints a single row into the CSV stream. |
void |
printRow(java.util.Iterator<?> columns)
Prints a new row into the CSV stream. |
void |
printRow(java.util.Iterator<?> columns,
int size)
Prints a single row into the CSV stream. |
void |
printRow(java.lang.Object[] columns)
Prints a new row into the CSV file. |
void |
setColumnDelimiter(java.lang.String s)
Sets the column delimiter to be used. |
void |
setColumnDelimiterRequired(boolean b)
Sets if column separators are always required or not. |
void |
setColumnSeparator(char s)
Sets the column separator to be used. |
void |
setCommentChar(char commentChar)
Sets the character to be used for indicating comments |
void |
setRowSeparator(java.lang.String s)
Sets the row separator to be used. |
| Methods inherited from class csv.impl.AbstractStreamTableWriter |
|---|
getOutputStream, setOutputStream |
| Methods inherited from class csv.impl.AbstractTableWriter |
|---|
convert, convert, getRowCount, getTypeConversionHandler, incrementRowCount, registerTypeConversionHandler, unregisterTypeConversionHandler |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CSVWriter()
public CSVWriter(java.io.File file)
throws java.io.IOException
file - file
java.io.IOException - when an exception occurspublic CSVWriter(java.io.OutputStream out)
out - output stream
java.io.IOException - when an exception occurspublic CSVWriter(java.io.Writer out)
CSVWriter(OutputStream) instead.
out - out writer
public CSVWriter(java.io.Writer out,
boolean flush)
out - out writer
public CSVWriter(java.lang.String file)
throws java.io.IOException
file - file
java.io.IOException - when an exception occurs| Method Detail |
|---|
protected void init()
init in class AbstractTableWriterAbstractTableWriter.init()public java.io.PrintWriter getWriter()
getWriter in class AbstractStreamTableWriterAbstractStreamTableWriter.getWriter()public void close()
close in interface TableWriterclose in class AbstractStreamTableWriterAbstractStreamTableWriter.close()public void setColumnDelimiter(java.lang.String s)
isColumnDelimiterRequired().
s - the new delimiterpublic java.lang.String getColumnDelimiter()
public void setColumnSeparator(char s)
s - new separator characterpublic char getColumnSeparator()
public void setRowSeparator(java.lang.String s)
s - new separatorpublic java.lang.String getRowSeparator()
public void setColumnDelimiterRequired(boolean b)
b - true when delimiters shall always be written.public boolean isColumnDelimiterRequired()
public char getCommentChar()
public void setCommentChar(char commentChar)
commentChar - the commentChar to setpublic java.lang.String prepareRow(java.lang.Object[] columns)
columns - columns to be prepared
public void printRow(java.lang.Object[] columns)
throws java.io.IOException
columns - array of column values.
java.io.IOException - when an exception occurspublic java.lang.String prepareComment(java.lang.String comment)
comment - comment to be printed
public void printComment(java.lang.String comment)
throws java.io.IOException
printComment in interface TableWriterprintComment in class AbstractTableWritercomment - comment to write
java.io.IOException - when an exception occurs
public void printComment(java.lang.String comment,
int row,
int column)
throws java.io.IOException
printComment in interface TableWriterprintComment in class AbstractTableWritercomment - comment to writerow - index of row for commentcolumn - index of column for comment
java.io.IOException - when an exception occursprotected boolean columnNeedsDelimiting(java.lang.String s)
s - column value to check
protected java.lang.String prepareColumnValue(java.lang.String s)
s - column value to parse
public void printRow(java.util.Collection<?> columns)
throws java.io.IOException
columns - collection of column values. An iterator will be used to retrieve values from the collection.
java.io.IOException
public void printRow(java.util.Iterator<?> columns,
int size)
throws java.io.IOException
columns - iterator that returns column values.size - number of values to retrieve from iterator. Method will abort at this size.
java.io.IOException
public void printRow(java.util.Iterator<?> columns)
throws java.io.IOException
columns - iterator that returns column values.
java.io.IOExceptionpublic int getColumnCount()
|
Copyright © 2008-2011 Ralph Schuster. All Rights Reserved. | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||