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
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.
|
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, wait
flushQuietly, writeAll, writeAll, writeAll, writeAll, writeAll, writeNext
protected final Writer writer
protected String lineEnd
protected ResultSetHelper resultService
protected volatile IOException exception
public void writeAll(Iterable<String[]> allLines, boolean applyQuotesToAll)
ICSVWriter
writeAll
in interface ICSVWriter
allLines
- 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
ICSVWriter
writeAll
in interface ICSVWriter
rs
- 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)
ICSVWriter
writeNext
in interface ICSVWriter
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.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 Flushable
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public boolean checkError()
ICSVWriter
checkError
in interface ICSVWriter
public IOException getException()
ICSVWriter
NOTE: 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 ICSVWriter
public void resetError()
ICSVWriter
ICSVWriter.checkError()
.resetError
in interface ICSVWriter
public void setResultService(ResultSetHelper resultService)
ICSVWriter
setResultService
in interface ICSVWriter
resultService
- The ResultSetHelperprotected ResultSetHelper resultService()
Copyright © 2005–2023. All rights reserved.