public abstract class AbstractCSVWriter extends Object implements ICSVWriter
| Modifier and Type | Field and Description |
|---|---|
protected IOException |
exception |
DEFAULT_ESCAPE_CHARACTER, DEFAULT_LINE_END, DEFAULT_QUOTE_CHARACTER, DEFAULT_SEPARATOR, INITIAL_STRING_SIZE, NO_ESCAPE_CHARACTER, NO_QUOTE_CHARACTER, RFC4180_LINE_END| Modifier | Constructor and Description |
|---|---|
protected |
AbstractCSVWriter(Writer writer,
String lineEnd)
Constructor to initialize the common values.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkError()
Flushes the buffer and checks to see if the there has been an error in the printstream.
|
void |
close() |
void |
flush() |
IOException |
getException()
Get latest exception.
|
protected String |
getLineEnd()
Retrieves the line ending sequence used when writing CSV data.
|
protected Writer |
getWriter()
Provides access to the writer used for outputting CSV data.
|
void |
resetError()
Set the error back to null to be able to check for the next error
using
ICSVWriter.checkError(). |
protected ResultSetHelper |
resultService()
Lazy resultSetHelper creation.
|
void |
setResultService(ResultSetHelper resultService)
Sets the result service.
|
void |
writeAll(Iterable<String[]> allLines,
boolean applyQuotesToAll)
Writes iterable 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,
boolean applyQuotesToAll)
Writes the next line to the file.
|
protected abstract void |
writeNext(String[] nextLine,
boolean applyQuotesToAll,
Appendable appendable)
Writes the next line to the file.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitflushQuietly, writeAll, writeAll, writeAll, writeAll, writeAll, writeNextprotected volatile IOException exception
protected final Writer getWriter()
Writer instance used for writing CSV content.protected final String getLineEnd()
public void writeAll(Iterable<String[]> allLines, boolean applyQuotesToAll)
ICSVWriterwriteAll in interface ICSVWriterallLines - 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.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, boolean trim, boolean applyQuotesToAll) throws SQLException, IOException
ICSVWriterwriteAll in interface ICSVWriterrs - 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.SQLException - Thrown by ResultSetHelper.getColumnValues()IOException - Thrown by ResultSetHelper.getColumnValues()public void writeNext(String[] nextLine, boolean applyQuotesToAll)
ICSVWriterwriteNext in interface ICSVWriternextLine - 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 abstract 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 flush()
throws IOException
flush in interface FlushableIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic boolean checkError()
ICSVWritercheckError in interface ICSVWriterpublic IOException getException()
ICSVWriterNOTE: This does not return exception which are caught by underlying writer (PrintWriter) or stream. If you are using this method then consider using a Writer class that throws exceptions.
getException in interface ICSVWriterpublic void resetError()
ICSVWriterICSVWriter.checkError().resetError in interface ICSVWriterpublic void setResultService(ResultSetHelper resultService)
ICSVWritersetResultService in interface ICSVWriterresultService - The ResultSetHelperprotected ResultSetHelper resultService()
Copyright © 2005–2025. All rights reserved.