| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_LINE_END
The default line delimiter to be used.
|
static boolean |
DEFAULT_QUOTE_ALL |
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.
|
| Constructor and Description |
|---|
CSVWriter(Writer aWriter)
Constructs
CSVWriter with all default settings. |
| 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.
|
char |
getEscapeChar() |
protected StringBuilder |
getEscapedText(String sNextElement)
Processes all the characters in a line.
|
String |
getLineEnd() |
char |
getQuoteChar() |
char |
getSeparatorChar() |
CSVWriter |
setEscapeChar(char cEscapeChar)
Sets the character to use for escaping a separator or quote.
|
CSVWriter |
setLineEnd(String sLineEnd)
Set the line delimiting string.
|
CSVWriter |
setQuoteChar(char cQuoteChar)
Sets the character to use for quoted elements.
|
CSVWriter |
setSeparatorChar(char cSeparator)
Sets the delimiter to use for separating entries.
|
protected boolean |
stringContainsSpecialCharacters(String sLine)
checks to see if the line contains special characters.
|
void |
writeAll(List<List<String>> aAllLines)
Writes the entire list to a CSV file with quoting enabled.
|
void |
writeAll(List<List<String>> aAllLines,
boolean bApplyQuotesToAll)
Writes the entire list to a CSV file.
|
void |
writeNext(Iterable<String> aNextLine)
Writes the next line to the file.
|
void |
writeNext(Iterable<String> aNextLine,
boolean bApplyQuotesToAll)
Writes the next line to the file.
|
void |
writeNext(Iterator<String> aNextLine,
boolean bApplyQuotesToAll)
Writes the next line to the file.
|
void |
writeNext(String... aNextLine)
Writes the next line to the file.
|
void |
writeNext(String[] aNextLine,
boolean bApplyQuotesToAll)
Writes the next line to the file.
|
void |
writeNext(String[] aNextLine,
int nOfs,
int nLength)
Writes the next line to the file.
|
void |
writeNext(String[] aNextLine,
int nOfs,
int nLength,
boolean bApplyQuotesToAll)
Writes the next line to the file.
|
public static final char NO_QUOTE_CHARACTER
public static final char NO_ESCAPE_CHARACTER
public static final String DEFAULT_LINE_END
public static final boolean DEFAULT_QUOTE_ALL
public char getSeparatorChar()
@Nonnull public CSVWriter setSeparatorChar(char cSeparator)
cSeparator - the delimiter to use for separating entriespublic char getQuoteChar()
@Nonnull public CSVWriter setQuoteChar(char cQuoteChar)
cQuoteChar - the character to use for quoted element.public char getEscapeChar()
@Nonnull public CSVWriter setEscapeChar(char cEscapeChar)
cEscapeChar - the character to use for escaping a separator or quote.@Nonnull @Nonempty public String getLineEnd()
null nor empty.@Nonnull public CSVWriter setLineEnd(@Nonnull@Nonempty String sLineEnd)
sLineEnd - The line end. May neither be null nor empty.public void writeAll(@Nonnull List<List<String>> aAllLines, boolean bApplyQuotesToAll)
aAllLines - a List of List of String, with each List of String representing a
line of the file.bApplyQuotesToAll - 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(@Nonnull List<List<String>> aAllLines)
aAllLines - a List of List of String, with each List of String representing a
line of the file.public void writeNext(@Nullable Iterator<String> aNextLine, boolean bApplyQuotesToAll)
aNextLine - A collection of Strings where each entry represents a single cell.bApplyQuotesToAll - 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(@Nullable Iterable<String> aNextLine, boolean bApplyQuotesToAll)
aNextLine - a string array with each comma-separated element as a separate
entry.bApplyQuotesToAll - 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(@Nullable Iterable<String> aNextLine)
aNextLine - a string array with each comma-separated element as a separate
entry.public void writeNext(@Nullable String[] aNextLine, boolean bApplyQuotesToAll)
aNextLine - a string array with each comma-separated element as a separate
entry.bApplyQuotesToAll - 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(@Nullable String... aNextLine)
aNextLine - a string array with each comma-separated element as a separate
entry.public void writeNext(@Nullable String[] aNextLine, @Nonnegative int nOfs, @Nonnegative int nLength, boolean bApplyQuotesToAll)
aNextLine - a string array with each comma-separated element as a separate
entry.nOfs - Array Offset. Must be ≥ 0.nLength - Array Length. Must be ≥ 0.bApplyQuotesToAll - 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(@Nullable String[] aNextLine, @Nonnegative int nOfs, @Nonnegative int nLength)
aNextLine - a string array with each comma-separated element as a separate
entry.nOfs - Array Offset. Must be ≥ 0.nLength - Array Length. Must be ≥ 0.protected boolean stringContainsSpecialCharacters(@Nonnull String sLine)
sLine - - element of data to check for special characters.@Nonnull protected StringBuilder getEscapedText(@Nonnull String sNextElement)
sNextElement - element to process.public void flush()
throws IOException
flush in interface FlushableIOException - if bad things happenpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - 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 © 2014–2015 Philip Helger. All rights reserved.