|
The Meta-Environment API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.csvreader.CsvWriter
public class CsvWriter
A stream based writer for writing delimited text data to a file or a stream.
Nested Class Summary | |
---|---|
private class |
CsvWriter.Letters
|
private class |
CsvWriter.UserSettings
|
Field Summary | |
---|---|
private java.nio.charset.Charset |
charset
|
private boolean |
closed
|
static int |
ESCAPE_MODE_BACKSLASH
Use a backslash character before the text qualifier to represent an occurance of the text qualifier. |
static int |
ESCAPE_MODE_DOUBLED
Double up the text qualifier to represent an occurance of the text qualifier. |
private java.lang.String |
fileName
|
private boolean |
firstColumn
|
private boolean |
initialized
|
private java.io.PrintWriter |
outputStream
|
private boolean |
useCustomRecordDelimiter
|
private CsvWriter.UserSettings |
userSettings
|
Constructor Summary | |
---|---|
CsvWriter(java.io.OutputStream outputStream,
char delimiter,
java.nio.charset.Charset charset)
Creates a CsvWriter object using an
OutputStream to write data to. |
|
CsvWriter(java.lang.String fileName)
Creates a CsvWriter object using a file
as the data destination. Uses a comma as the column delimiter and
ISO-8859-1 as the Charset . |
|
CsvWriter(java.lang.String fileName,
char delimiter,
java.nio.charset.Charset charset)
Creates a CsvWriter object using a file
as the data destination. |
|
CsvWriter(java.io.Writer outputStream,
char delimiter)
Creates a CsvWriter object using a Writer
to write data to. |
Method Summary | |
---|---|
private void |
checkClosed()
|
private void |
checkInit()
|
void |
close()
Closes and releases all related resources. |
private void |
close(boolean closing)
|
void |
endRecord()
Ends the current record by sending the record delimiter. |
protected void |
finalize()
|
void |
flush()
Clears all buffers for the current writer and causes any buffered data to be written to the underlying device. |
char |
getComment()
|
char |
getDelimiter()
Gets the character being used as the column delimiter. |
int |
getEscapeMode()
|
boolean |
getForceQualifier()
Whether fields will be surrounded by the text qualifier even if the qualifier is not necessarily needed to escape this field. |
char |
getRecordDelimiter()
|
char |
getTextQualifier()
Gets the character to use as a text qualifier in the data. |
boolean |
getUseTextQualifier()
Whether text qualifiers will be used while writing data or not. |
static java.lang.String |
replace(java.lang.String original,
java.lang.String pattern,
java.lang.String replace)
|
void |
setComment(char comment)
|
void |
setDelimiter(char delimiter)
Sets the character to use as the column delimiter. |
void |
setEscapeMode(int escapeMode)
|
void |
setForceQualifier(boolean forceQualifier)
Use this to force all fields to be surrounded by the text qualifier even if the qualifier is not necessarily needed to escape this field. |
void |
setRecordDelimiter(char recordDelimiter)
Sets the character to use as the record delimiter. |
void |
setTextQualifier(char textQualifier)
Sets the character to use as a text qualifier in the data. |
void |
setUseTextQualifier(boolean useTextQualifier)
Sets whether text qualifiers will be used while writing data or not. |
void |
write(java.lang.String content)
Writes another column of data to this record. Does not preserve leading and trailing whitespace in this column of data. |
void |
write(java.lang.String content,
boolean preserveSpaces)
Writes another column of data to this record. |
void |
writeComment(java.lang.String commentText)
|
void |
writeRecord(java.lang.String[] values)
Writes a new record using the passed in array of values. |
void |
writeRecord(java.lang.String[] values,
boolean preserveSpaces)
Writes a new record using the passed in array of values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.io.PrintWriter outputStream
private java.lang.String fileName
private boolean firstColumn
private boolean useCustomRecordDelimiter
private java.nio.charset.Charset charset
private CsvWriter.UserSettings userSettings
private boolean initialized
private boolean closed
public static final int ESCAPE_MODE_DOUBLED
public static final int ESCAPE_MODE_BACKSLASH
Constructor Detail |
---|
public CsvWriter(java.lang.String fileName, char delimiter, java.nio.charset.Charset charset)
CsvWriter
object using a file
as the data destination.
fileName
- The path to the file to output the data.delimiter
- The character to use as the column delimiter.charset
- The Charset
to use while
writing the data.public CsvWriter(java.lang.String fileName)
CsvWriter
object using a file
as the data destination. Uses a comma as the column delimiter and
ISO-8859-1 as the Charset
.
fileName
- The path to the file to output the data.public CsvWriter(java.io.Writer outputStream, char delimiter)
CsvWriter
object using a Writer
to write data to.
outputStream
- The stream to write the column delimited data to.delimiter
- The character to use as the column delimiter.public CsvWriter(java.io.OutputStream outputStream, char delimiter, java.nio.charset.Charset charset)
CsvWriter
object using an
OutputStream to write data to.
outputStream
- The stream to write the column delimited data to.delimiter
- The character to use as the column delimiter.charset
- The Charset
to use while
writing the data.Method Detail |
---|
public char getDelimiter()
public void setDelimiter(char delimiter)
delimiter
- The character to use as the column delimiter.public char getRecordDelimiter()
public void setRecordDelimiter(char recordDelimiter)
recordDelimiter
- The character to use as the record delimiter. Default is
combination of standard end of line characters for Windows,
Unix, or Mac.public char getTextQualifier()
public void setTextQualifier(char textQualifier)
textQualifier
- The character to use as a text qualifier in the data.public boolean getUseTextQualifier()
public void setUseTextQualifier(boolean useTextQualifier)
useTextQualifier
- Whether to use a text qualifier while writing data or not.public int getEscapeMode()
public void setEscapeMode(int escapeMode)
public void setComment(char comment)
public char getComment()
public boolean getForceQualifier()
public void setForceQualifier(boolean forceQualifier)
forceQualifier
- Whether to force the fields to be qualified or not.public void write(java.lang.String content, boolean preserveSpaces) throws java.io.IOException
content
- The data for the new column.preserveSpaces
- Whether to preserve leading and trailing whitespace in this
column of data.
java.io.IOException
- Thrown if an error occurs while writing data to the
destination stream.public void write(java.lang.String content) throws java.io.IOException
content
- The data for the new column.
java.io.IOException
- Thrown if an error occurs while writing data to the
destination stream.public void writeComment(java.lang.String commentText) throws java.io.IOException
java.io.IOException
public void writeRecord(java.lang.String[] values, boolean preserveSpaces) throws java.io.IOException
values
- Values to be written.preserveSpaces
- Whether to preserver leading and trailing spaces in columns
while writing out to the record or not.
java.io.IOException
- Thrown if an error occurs while writing data to the
destination stream.public void writeRecord(java.lang.String[] values) throws java.io.IOException
values
- Values to be written.
java.io.IOException
- Thrown if an error occurs while writing data to the
destination stream.public void endRecord() throws java.io.IOException
java.io.IOException
- Thrown if an error occurs while writing data to the
destination stream.private void checkInit() throws java.io.IOException
java.io.IOException
public void flush()
public void close()
private void close(boolean closing)
private void checkClosed() throws java.io.IOException
java.io.IOException
protected void finalize()
finalize
in class java.lang.Object
public static java.lang.String replace(java.lang.String original, java.lang.String pattern, java.lang.String replace)
|
The Meta-Environment API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |