public class Csv extends Object implements SimpleRowSource
Modifier | Constructor and Description |
---|---|
protected |
Csv() |
Modifier and Type | Method and Description |
---|---|
void |
close()
INTERNAL
|
char |
getEscapeCharacter()
Get the current escape character.
|
char |
getFieldDelimiter()
Get the current field delimiter.
|
char |
getFieldSeparatorRead()
Get the current field separator for reading.
|
String |
getFieldSeparatorWrite()
Get the current field separator for writing.
|
static Csv |
getInstance()
Get a new object of this class.
|
char |
getLineCommentCharacter()
Get the line comment character.
|
String |
getLineSeparator()
Get the current line separator.
|
String |
getNullString()
Get the current null string.
|
boolean |
getPreserveWhitespace()
Whether whitespace in unquoted text is preserved.
|
String |
getRowSeparatorWrite()
Get the current row separator for writing.
|
ResultSet |
read(Reader reader,
String[] colNames)
Reads CSV data from a reader and returns a result set.
|
ResultSet |
read(String inputFileName,
String[] colNames,
String charset)
Reads from the CSV file and returns a result set.
|
Object[] |
readRow()
INTERNAL
|
void |
reset()
INTERNAL
|
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(String fieldSeparatorWrite)
Override the field separator for writing.
|
void |
setLineCommentCharacter(char lineCommentCharacter)
Set the line comment character.
|
void |
setLineSeparator(String lineSeparator)
Set the line separator.
|
void |
setNullString(String nullString)
Set the value that represents NULL.
|
String |
setOptions(String options)
INTERNAL.
|
void |
setPreserveWhitespace(boolean value)
Enable or disable preserving whitespace in unquoted text.
|
void |
setRowSeparatorWrite(String rowSeparatorWrite)
Override the end-of-row marker for writing.
|
int |
write(Connection conn,
String outputFileName,
String sql,
String charset)
Writes the result set of a query to a file in the CSV format.
|
int |
write(String outputFileName,
ResultSet rs,
String charset)
Writes the result set to a file in the CSV format.
|
int |
write(Writer writer,
ResultSet rs)
Writes the result set to a file in the CSV format.
|
public static Csv getInstance()
public int write(Writer writer, ResultSet rs) throws SQLException
writer
- the writerrs
- the result setSQLException
public int write(String outputFileName, ResultSet rs, String charset) throws 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 charset
(see system property file.encoding)SQLException
public int write(Connection conn, String outputFileName, String sql, String charset) throws SQLException
conn
- the connectionoutputFileName
- the file namesql
- the querycharset
- the charset or null to use the system default charset
(see system property file.encoding)SQLException
public ResultSet read(String inputFileName, String[] colNames, String charset) throws 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 charset
(see system property file.encoding)SQLException
public ResultSet read(Reader reader, String[] colNames) throws IOException
reader
- the readercolNames
- or null if the column names should be read from the CSV fileIOException
public Object[] readRow() throws SQLException
readRow
in interface SimpleRowSource
SQLException
public void close()
close
in interface SimpleRowSource
public void reset() throws SQLException
reset
in interface SimpleRowSource
SQLException
- if this operation is not supportedpublic void setFieldSeparatorWrite(String fieldSeparatorWrite)
fieldSeparatorWrite
- the field separatorpublic String getFieldSeparatorWrite()
public void setFieldSeparatorRead(char fieldSeparatorRead)
fieldSeparatorRead
- the field separatorpublic char getFieldSeparatorRead()
public String getRowSeparatorWrite()
public void setRowSeparatorWrite(String rowSeparatorWrite)
rowSeparatorWrite
- the row separatorpublic 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(String lineSeparator)
lineSeparator
- the line separatorpublic String getLineSeparator()
public void setNullString(String nullString)
nullString
- the nullpublic String getNullString()
public void setPreserveWhitespace(boolean value)
value
- the new value for the settingpublic boolean getPreserveWhitespace()
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.