public class CSVWriter extends AbstractCSVWriter
Modifier and Type | Field and Description |
---|---|
protected char |
escapechar |
protected char |
quotechar |
protected char |
separator |
exception, lineEnd, resultService, writer
DEFAULT_ESCAPE_CHARACTER, DEFAULT_LINE_END, DEFAULT_QUOTE_CHARACTER, DEFAULT_SEPARATOR, INITIAL_STRING_SIZE, NO_ESCAPE_CHARACTER, NO_QUOTE_CHARACTER, RFC4180_LINE_END
Constructor and Description |
---|
CSVWriter(Writer writer)
Constructs CSVWriter using a comma for the separator.
|
CSVWriter(Writer writer,
char separator,
char quotechar,
char escapechar,
String lineEnd)
Constructs CSVWriter with supplied separator, quote char, escape char and line ending.
|
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.
|
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 boolean |
stringContainsSpecialCharacters(String line)
Checks to see if the line contains special characters.
|
protected void |
writeNext(String[] nextLine,
boolean applyQuotesToAll,
Appendable appendable)
Writes the next line to the file.
|
checkError, close, flush, getException, resetError, resultService, setResultService, writeAll, writeAll, writeColumnNames, writeNext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
flushQuietly, writeAll, writeAll, writeAll, writeAll, writeAll, writeNext
protected final char separator
protected final char quotechar
protected final char escapechar
public CSVWriter(Writer writer)
writer
- The writer to an underlying CSV source.public 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 useprotected void writeNext(String[] nextLine, boolean applyQuotesToAll, Appendable appendable) throws IOException
AbstractCSVWriter
writeNext
in class AbstractCSVWriter
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.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 writtenCopyright © 2005–2023. All rights reserved.