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.
|
static int |
INITIAL_STRING_SIZE |
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.
|
static String |
RFC4180_LINE_END
RFC 4180 compliant line terminator.
|
Constructor and Description |
---|
CSVWriter(Writer writer)
Constructs CSVWriter using a comma for the separator.
|
CSVWriter(Writer writer,
char separator)
Constructs CSVWriter with supplied separator.
|
CSVWriter(Writer writer,
char separator,
char quotechar)
Constructs CSVWriter with supplied separator and quote char.
|
CSVWriter(Writer writer,
char separator,
char quotechar,
char escapechar)
Constructs CSVWriter with supplied separator and quote char.
|
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)
Constructs CSVWriter with supplied separator and quote char.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkError()
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 StringBuilder |
processLine(String nextElement)
Processes all the characters in a line.
|
protected boolean |
stringContainsSpecialCharacters(String line)
checks to see if the line contains special characters.
|
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.
|
void |
writeNext(String[] nextLine)
Writes the next line to the file.
|
void |
writeNext(String[] nextLine,
boolean applyQuotesToAll)
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
public CSVWriter(Writer writer)
writer
- the writer to an underlying CSV source.public CSVWriter(Writer writer, char separator)
writer
- the writer to an underlying CSV source.separator
- the delimiter to use for separating entries.public CSVWriter(Writer writer, char separator, char quotechar)
writer
- the writer to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementspublic CSVWriter(Writer writer, char separator, char quotechar, char escapechar)
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 escapecharspublic CSVWriter(Writer writer, char separator, char quotechar, String lineEnd)
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(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(List<String[]> allLines)
allLines
- a List of String[], with each String[] representing a line of
the file.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.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 StringBuilder processLine(String nextElement)
nextElement
- - element to process.public 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()
true
if the print stream has encountered an error,
either on the underlying output stream or during a format
conversion.public void flushQuietly()
Copyright © 2019 Liquibase.org. All rights reserved.