public abstract class AbstractCSVWriter extends Object implements ICSVWriter
| Modifier and Type | Field and Description |
|---|---|
protected IOException |
exception |
protected String |
lineEnd |
protected ResultSetHelper |
resultService |
protected Writer |
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 |
|---|
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() |
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 final Writer writer
protected String lineEnd
protected ResultSetHelper resultService
protected volatile IOException exception
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 void setResultService(ResultSetHelper resultService)
ICSVWritersetResultService in interface ICSVWriterresultService - The ResultSetHelperprotected ResultSetHelper resultService()
Copyright © 2019. All rights reserved.