Modifier and Type | Field and Description |
---|---|
static char |
DEFAULT_ESCAPE_CHARACTER
The character used for escaping quotes.
|
static String |
DEFAULT_LINE_END
Default line terminator.
|
static char |
DEFAULT_QUOTE_CHARACTER
The default quote character to use if none is supplied to the
constructor.
|
static char |
DEFAULT_SEPARATOR
The default separator to use if none is supplied to the constructor.
|
protected char |
escapechar |
protected IOException |
exception |
static int |
INITIAL_STRING_SIZE |
protected String |
lineEnd |
static char |
NO_ESCAPE_CHARACTER
The escape constant to use when you wish to suppress all escaping.
|
static char |
NO_QUOTE_CHARACTER
The quote constant to use when you wish to suppress all quoting.
|
protected char |
quotechar |
protected ResultSetHelper |
resultService |
static String |
RFC4180_LINE_END
RFC 4180 compliant line terminator.
|
protected char |
separator |
protected Writer |
writer |
Constructor and Description |
---|
CSVWriter(Writer writer)
Constructs CSVWriter using a comma for the separator.
|
CSVWriter(Writer writer,
char separator)
Deprecated.
Please use
CSVWriter(java.io.Writer, char, char, char, java.lang.String) instead. |
CSVWriter(Writer writer,
char separator,
char quotechar)
Deprecated.
Please use
CSVWriter(java.io.Writer, char, char, char, java.lang.String) instead. |
CSVWriter(Writer writer,
char separator,
char quotechar,
char escapechar)
Deprecated.
Please use
CSVWriter(java.io.Writer, char, char, char, java.lang.String) instead. |
CSVWriter(Writer writer,
char separator,
char quotechar,
char escapechar,
String lineEnd)
Constructs CSVWriter with supplied separator, quote char, escape char and line ending.
|
CSVWriter(Writer writer,
char separator,
char quotechar,
String lineEnd)
Deprecated.
Please use
CSVWriter(java.io.Writer, char, char, char, java.lang.String) instead. |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkCharactersToEscape(char nextChar)
Checks whether the next character that is to be written out is a special
character that must be quoted.
|
boolean |
checkError()
Flushes the buffer and checks to see if the there has been an error in the printstream.
|
void |
close()
Close the underlying stream writer flushing any buffered content.
|
void |
flush()
Flush underlying stream to writer.
|
void |
flushQuietly()
Flushes the writer without throwing any exceptions.
|
protected void |
processCharacter(Appendable appendable,
char nextChar)
Appends the character to the StringBuilder adding the escape character if needed.
|
protected void |
processLine(String nextElement,
Appendable appendable)
Processes all the characters in a line.
|
protected ResultSetHelper |
resultService()
Lazy resultSetHelper creation.
|
void |
setResultService(ResultSetHelper resultService)
Sets the result service.
|
protected boolean |
stringContainsSpecialCharacters(String line)
Checks to see if the line contains special characters.
|
void |
writeAll(Iterable<String[]> allLines)
Writes iterable to a CSV file.
|
void |
writeAll(Iterable<String[]> allLines,
boolean applyQuotesToAll)
Writes iterable to a CSV file.
|
void |
writeAll(List<String[]> allLines)
Writes the entire list to a CSV file.
|
void |
writeAll(List<String[]> allLines,
boolean applyQuotesToAll)
Writes the entire list to a CSV file.
|
int |
writeAll(ResultSet rs,
boolean includeColumnNames)
Writes the entire ResultSet to a CSV file.
|
int |
writeAll(ResultSet rs,
boolean includeColumnNames,
boolean trim)
Writes the entire ResultSet to a CSV file.
|
int |
writeAll(ResultSet rs,
boolean includeColumnNames,
boolean trim,
boolean applyQuotesToAll)
Writes the entire ResultSet to a CSV file.
|
protected void |
writeColumnNames(ResultSet rs,
boolean applyQuotesToAll)
Writes the column names.
|
void |
writeNext(String[] nextLine)
Writes the next line to the file.
|
void |
writeNext(String[] nextLine,
boolean applyQuotesToAll)
Writes the next line to the file.
|
protected void |
writeNext(String[] nextLine,
boolean applyQuotesToAll,
Appendable appendable)
Writes the next line to the file.
|
public static final int INITIAL_STRING_SIZE
public static final char DEFAULT_ESCAPE_CHARACTER
public static final char DEFAULT_SEPARATOR
public static final char DEFAULT_QUOTE_CHARACTER
public static final char NO_QUOTE_CHARACTER
public static final char NO_ESCAPE_CHARACTER
public static final String DEFAULT_LINE_END
public static final String RFC4180_LINE_END
protected final Writer writer
protected final char separator
protected final char quotechar
protected final char escapechar
protected String lineEnd
protected ResultSetHelper resultService
protected volatile IOException exception
public CSVWriter(Writer writer)
writer
- The writer to an underlying CSV source.@Deprecated public CSVWriter(Writer writer, char separator)
CSVWriter(java.io.Writer, char, char, char, java.lang.String)
instead.writer
- The writer to an underlying CSV source.separator
- The delimiter to use for separating entries.@Deprecated public CSVWriter(Writer writer, char separator, char quotechar)
CSVWriter(java.io.Writer, char, char, char, java.lang.String)
instead.writer
- The writer to an underlying CSV source.separator
- The delimiter to use for separating entriesquotechar
- The character to use for quoted elements@Deprecated public CSVWriter(Writer writer, char separator, char quotechar, char escapechar)
CSVWriter(java.io.Writer, char, char, char, java.lang.String)
instead.writer
- The writer to an underlying CSV source.separator
- The delimiter to use for separating entriesquotechar
- The character to use for quoted elementsescapechar
- The character to use for escaping quotechars or escapechars@Deprecated public CSVWriter(Writer writer, char separator, char quotechar, String lineEnd)
CSVWriter(java.io.Writer, char, char, char, java.lang.String)
instead.writer
- The writer to an underlying CSV source.separator
- The delimiter to use for separating entriesquotechar
- The character to use for quoted elementslineEnd
- The line feed terminator to usepublic CSVWriter(Writer writer, char separator, char quotechar, char escapechar, String lineEnd)
writer
- The writer to an underlying CSV source.separator
- The delimiter to use for separating entriesquotechar
- The character to use for quoted elementsescapechar
- The character to use for escaping quotechars or escapecharslineEnd
- The line feed terminator to usepublic void writeAll(Iterable<String[]> allLines, boolean applyQuotesToAll)
allLines
- an Iterable of String[], with each String[] representing a line of
the file.applyQuotesToAll
- true if all values are to be quoted. false if quotes only
to be applied to values which contain the separator, escape,
quote or new line characters.public void writeAll(List<String[]> allLines, boolean applyQuotesToAll)
allLines
- A List of String[] with each String[] representing a line of
the file.applyQuotesToAll
- True if all values are to be quoted. False if quotes only
to be applied to values which contain the separator, escape,
quote, or new line characters.public void writeAll(Iterable<String[]> allLines)
allLines
- an Iterable of String[], with each String[] representing a line of
the file.public void writeAll(List<String[]> allLines)
allLines
- A List of String[] with each String[] representing a line of
the file.protected void writeColumnNames(ResultSet rs, boolean applyQuotesToAll) throws SQLException
rs
- ResultSet containing column names.applyQuotesToAll
- Whether all header names should be quoted.SQLException
- Thrown by ResultSetHelper.getColumnNames(java.sql.ResultSet)
public int writeAll(ResultSet rs, boolean includeColumnNames) throws SQLException, IOException
rs
- The result set to writeincludeColumnNames
- True if you want column names in the output, false otherwiseIOException
- Thrown by ResultSetHelper.getColumnValues()SQLException
- Thrown by ResultSetHelper.getColumnValues()public int writeAll(ResultSet rs, boolean includeColumnNames, boolean trim) throws SQLException, IOException
rs
- The Result set to write.includeColumnNames
- Include the column names in the output.trim
- Remove spaces from the data before writing.IOException
- Thrown by ResultSetHelper.getColumnValues()SQLException
- Thrown by ResultSetHelper.getColumnValues()public int writeAll(ResultSet rs, boolean includeColumnNames, boolean trim, boolean applyQuotesToAll) throws SQLException, IOException
rs
- The Result set to write.includeColumnNames
- Include the column names in the output.trim
- Remove spaces from the data before writing.applyQuotesToAll
- Whether all values should be quoted.IOException
- Thrown by ResultSetHelper.getColumnValues()SQLException
- Thrown by ResultSetHelper.getColumnValues()public void writeNext(String[] nextLine, boolean applyQuotesToAll)
nextLine
- A string array with each comma-separated element as a separate
entry.applyQuotesToAll
- True if all values are to be quoted. False applies quotes only
to values which contain the separator, escape, quote, or new line characters.protected void writeNext(String[] nextLine, boolean applyQuotesToAll, Appendable appendable) throws IOException
nextLine
- a string array with each comma-separated element as a separate
entry.applyQuotesToAll
- true if all values are to be quoted. false applies quotes only
to values which contain the separator, escape, quote or new line characters.appendable
- Appendable used as buffer.IOException
- Exceptions thrown by the writer supplied to CSVWriter.public void writeNext(String[] nextLine)
nextLine
- A string array with each comma-separated element as a separate
entry.protected boolean stringContainsSpecialCharacters(String line)
line
- Element of data to check for special characters.protected void processLine(String nextElement, Appendable appendable) throws IOException
nextElement
- Element to process.appendable
- - Appendable holding the processed data.IOException
- - IOException thrown by the writer supplied to the CSVWriterprotected void processCharacter(Appendable appendable, char nextChar) throws IOException
appendable
- - Appendable holding the processed data.nextChar
- Character to processIOException
- - IOException thrown by the writer supplied to the CSVWriter.protected boolean checkCharactersToEscape(char nextChar)
nextChar
- The next character to be writtenpublic void flush() throws IOException
flush
in interface Flushable
IOException
- If bad things happenpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
- If bad things happenpublic boolean checkError()
public void setResultService(ResultSetHelper resultService)
resultService
- The ResultSetHelperprotected ResultSetHelper resultService()
public void flushQuietly()
Copyright © 2017. All rights reserved.