|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.continuent.tungsten.common.csv.CsvWriter
public class CsvWriter
Writes CSV output. This class implements CSV formatting roughly as described in RFC4180 (http://tools.ietf.org/html/rfc4180) with practical alterations to match specify DBMS implementations.
| Constructor Summary | |
|---|---|
CsvWriter(java.io.BufferedWriter writer)
Instantiate a new instance with output to provided buffered writer. |
|
CsvWriter(java.io.Writer writer)
Instantiate a new instance with output to provided writer. |
|
| Method Summary | |
|---|---|
void |
addColumnName(java.lang.String name)
Add a column name. |
void |
addRowIdName(java.lang.String name)
Add a row id name. |
CsvWriter |
flush()
Forces a write of any pending row(s) and flushes data on writer. |
char |
getEscapeChar()
Returns the escape character. |
java.lang.String |
getEscapedChars()
Returns a string of characters that must be preceded by escape character. |
java.util.List<java.lang.String> |
getNames()
Return names in column order. |
NullPolicy |
getNullPolicy()
Returns the policy for handling null values. |
java.lang.String |
getNullValue()
Gets the null value identifier string. |
char |
getQuoteChar()
Returns the quote character. |
int |
getRowCount()
Returns the current count of rows written. |
char |
getSeparator()
Returns separator character. |
java.lang.String |
getSuppressedChars()
Returns a string of characters that are suppressed in CSV output. |
int |
getWidth()
Return the number of columns. |
java.io.Writer |
getWriter()
Get the underlying writer. |
boolean |
isNullAutofill()
Returns true to fill nulls automatically. |
boolean |
isQuoted()
Returns true if values will be enclosed by a quote character. |
boolean |
isWriteHeaders()
If true, write headers. |
CsvWriter |
put(int index,
java.lang.String value)
Writes value to current row. |
CsvWriter |
put(java.lang.String key,
java.lang.String value)
Writes value to key in current row. |
void |
setEscapeChar(char quoteEscapeChar)
Sets character used to escape quotes and other escaped characters. |
void |
setEscapedChars(java.lang.String escapedChars)
Defines zero or more characters that must be preceded by escape character. |
void |
setNullAutofill(boolean nullAutofill)
Sets the null autofill policy for columns that have no value (partial rows). |
void |
setNullPolicy(NullPolicy nullPolicy)
Sets the policy for handling null values. |
void |
setNullValue(java.lang.String nullValue)
Sets the null value identifier string. |
void |
setQuoteChar(char quoteChar)
Sets the quote character. |
void |
setQuoted(boolean quoted)
Set to true to enable quoting. |
void |
setSeparator(char separator)
Sets the separator characters. |
void |
setSuppressedChars(java.lang.String suppressedChars)
Sets characters to be suppressed in CSV output. |
void |
setWriteHeaders(boolean writeHeaders)
Set to true to write headers. |
CsvWriter |
write()
Writes current row, including headers if we are on the first row. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CsvWriter(java.io.Writer writer)
public CsvWriter(java.io.BufferedWriter writer)
| Method Detail |
|---|
public void setSeparator(char separator)
public char getSeparator()
public boolean isQuoted()
public void setQuoted(boolean quoted)
public NullPolicy getNullPolicy()
public void setNullPolicy(NullPolicy nullPolicy)
public java.lang.String getNullValue()
public void setNullValue(java.lang.String nullValue)
public boolean isNullAutofill()
public void setNullAutofill(boolean nullAutofill)
public char getQuoteChar()
public void setQuoteChar(char quoteChar)
public void setEscapeChar(char quoteEscapeChar)
setQuoteChar(char)public char getEscapeChar()
public java.lang.String getEscapedChars()
public void setEscapedChars(java.lang.String escapedChars)
public java.lang.String getSuppressedChars()
public void setSuppressedChars(java.lang.String suppressedChars)
public int getRowCount()
public java.io.Writer getWriter()
public boolean isWriteHeaders()
public void setWriteHeaders(boolean writeHeaders)
public void addColumnName(java.lang.String name)
throws CsvException
name - Column name
CsvException - Thrown
public void addRowIdName(java.lang.String name)
throws CsvException
name - Row ID name
CsvException - Thrown if the row ID has already been set.public java.util.List<java.lang.String> getNames()
public int getWidth()
public CsvWriter write()
throws CsvException,
java.io.IOException
CsvException - Thrown if there is an inconsistency like too many
columns
java.io.IOException - Thrown due to a write error
public CsvWriter flush()
throws java.io.IOException,
CsvException
CsvException - Thrown on an I/O failure
java.io.IOException
public CsvWriter put(int index,
java.lang.String value)
throws CsvException
index - Column index where indexes are numbered 1,2,3,...,N with N
being the width of the row in columnsvalue - String value to write, already escaped if necessary
CsvException - Thrown if client attempts to write same column value
twice or the row is not wide enough
public CsvWriter put(java.lang.String key,
java.lang.String value)
throws CsvException
CsvException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||