public class Csv extends java.lang.Object implements SimpleRowSource
Constructor and Description |
---|
Csv() |
Modifier and Type | Method and Description |
---|---|
void |
close()
INTERNAL
|
boolean |
getCaseSensitiveColumnNames()
Get the current case sensitive column names setting.
|
char |
getEscapeCharacter()
Get the current escape character.
|
char |
getFieldDelimiter()
Get the current field delimiter.
|
char |
getFieldSeparatorRead()
Get the current field separator for reading.
|
java.lang.String |
getFieldSeparatorWrite()
Get the current field separator for writing.
|
char |
getLineCommentCharacter()
Get the line comment character.
|
java.lang.String |
getLineSeparator()
Get the line separator used for writing.
|
java.lang.String |
getNullString()
Get the current null string.
|
boolean |
getPreserveWhitespace()
Whether whitespace in unquoted text is preserved.
|
boolean |
getWriteColumnHeader()
Whether the column header is written.
|
boolean |
isQuotedNulls()
Returns true if the
null values are quoted. |
java.sql.ResultSet |
read(java.io.Reader reader,
java.lang.String[] colNames)
Reads CSV data from a reader and returns a result set.
|
java.sql.ResultSet |
read(java.lang.String inputFileName,
java.lang.String[] colNames,
java.lang.String charset)
Reads from the CSV file and returns a result set.
|
java.lang.Object[] |
readRow()
INTERNAL
|
void |
reset()
INTERNAL
|
void |
setCaseSensitiveColumnNames(boolean caseSensitiveColumnNames)
Override the case sensitive column names setting.
|
void |
setEscapeCharacter(char escapeCharacter)
Set the escape character.
|
void |
setFieldDelimiter(char fieldDelimiter)
Set the field delimiter.
|
void |
setFieldSeparatorRead(char fieldSeparatorRead)
Override the field separator for reading.
|
void |
setFieldSeparatorWrite(java.lang.String fieldSeparatorWrite)
Override the field separator for writing.
|
void |
setLineCommentCharacter(char lineCommentCharacter)
Set the line comment character.
|
void |
setLineSeparator(java.lang.String lineSeparator)
Set the line separator used for writing.
|
void |
setNullString(java.lang.String nullString)
Set the value that represents NULL.
|
java.lang.String |
setOptions(java.lang.String options)
INTERNAL.
|
void |
setPreserveWhitespace(boolean value)
Enable or disable preserving whitespace in unquoted text.
|
void |
setQuotedNulls(boolean quotedNulls)
Defines if the
null values must
be quoted. |
void |
setWriteColumnHeader(boolean value)
Enable or disable writing the column header.
|
int |
write(java.sql.Connection conn,
java.lang.String outputFileName,
java.lang.String sql,
java.lang.String charset)
Writes the result set of a query to a file in the CSV format.
|
int |
write(java.lang.String outputFileName,
java.sql.ResultSet rs,
java.lang.String charset)
Writes the result set to a file in the CSV format.
|
int |
write(java.io.Writer writer,
java.sql.ResultSet rs)
Writes the result set to a file in the CSV format.
|
public int write(java.io.Writer writer, java.sql.ResultSet rs) throws java.sql.SQLException
writer
- the writerrs
- the result setjava.sql.SQLException
- on failurepublic int write(java.lang.String outputFileName, java.sql.ResultSet rs, java.lang.String charset) throws java.sql.SQLException
while (rs.next()) { writeRow(row); }
outputFileName
- the name of the csv filers
- the result set - the result set must be positioned before the
first row.charset
- the charset or null to use the system default charsetjava.sql.SQLException
- on failurepublic int write(java.sql.Connection conn, java.lang.String outputFileName, java.lang.String sql, java.lang.String charset) throws java.sql.SQLException
conn
- the connectionoutputFileName
- the file namesql
- the querycharset
- the charset or null to use the system default charset
(see system property file.encoding)java.sql.SQLException
- on failurepublic java.sql.ResultSet read(java.lang.String inputFileName, java.lang.String[] colNames, java.lang.String charset) throws java.sql.SQLException
inputFileName
- the file namecolNames
- or null if the column names should be read from the CSV
filecharset
- the charset or null to use the system default charsetjava.sql.SQLException
- on failurepublic java.sql.ResultSet read(java.io.Reader reader, java.lang.String[] colNames) throws java.io.IOException
reader
- the readercolNames
- or null if the column names should be read from the CSV
filejava.io.IOException
- on failurepublic java.lang.Object[] readRow() throws java.sql.SQLException
readRow
in interface SimpleRowSource
java.sql.SQLException
- on failurepublic void close()
close
in interface SimpleRowSource
public void reset() throws java.sql.SQLException
reset
in interface SimpleRowSource
java.sql.SQLException
- if this operation is not supportedpublic void setFieldSeparatorWrite(java.lang.String fieldSeparatorWrite)
fieldSeparatorWrite
- the field separatorpublic java.lang.String getFieldSeparatorWrite()
public void setCaseSensitiveColumnNames(boolean caseSensitiveColumnNames)
caseSensitiveColumnNames
- whether column names are case sensitivepublic boolean getCaseSensitiveColumnNames()
public void setFieldSeparatorRead(char fieldSeparatorRead)
fieldSeparatorRead
- the field separatorpublic char getFieldSeparatorRead()
public void setLineCommentCharacter(char lineCommentCharacter)
lineCommentCharacter
- the line comment characterpublic char getLineCommentCharacter()
public void setFieldDelimiter(char fieldDelimiter)
fieldDelimiter
- the field delimiterpublic char getFieldDelimiter()
public void setEscapeCharacter(char escapeCharacter)
Data: He said "Hello". Escape character: " Field delimiter: " CSV file: "He said ""Hello""."If the field delimiter is a double quote and the escape character is a backslash, then escaping is done similar to Java (however, only the field delimiter is escaped). Example:
Data: He said "Hello". Escape character: \ Field delimiter: " CSV file: "He said \"Hello\"."The value 0 means no escape character is used.
escapeCharacter
- the escape characterpublic char getEscapeCharacter()
public void setLineSeparator(java.lang.String lineSeparator)
lineSeparator
- the line separatorpublic java.lang.String getLineSeparator()
public void setQuotedNulls(boolean quotedNulls)
null values
must
be quoted.quotedNulls
- True if the null values must be quoted.public boolean isQuotedNulls()
null values
are quoted.public void setNullString(java.lang.String nullString)
nullString
- the nullpublic java.lang.String getNullString()
public void setPreserveWhitespace(boolean value)
value
- the new value for the settingpublic boolean getPreserveWhitespace()
public void setWriteColumnHeader(boolean value)
value
- the new value for the settingpublic boolean getWriteColumnHeader()
public java.lang.String setOptions(java.lang.String options)
options
- the options