Interface ICSVWriter
- All Superinterfaces:
AutoCloseable, Closeable, Flushable
- All Known Implementing Classes:
AbstractCSVWriter, CSVParserWriter, CSVWriter
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThe character used for escaping quotes.static final StringDefault line terminator.static final charThe default quote character to use if none is supplied to the constructor.static final charThe default separator to use if none is supplied to the constructor.static final intDefault buffer sizesstatic final charThe escape constant to use when you wish to suppress all escaping.static final charThe quote constant to use when you wish to suppress all quoting.static final StringRFC 4180 compliant line terminator. -
Method Summary
Modifier and TypeMethodDescriptionbooleanFlushes the buffer and checks to see if the there has been an error in the printstream.default voidFlushes the writer without throwing any exceptions.Get latest exception.voidSet the error back to null to be able to check for the next error usingcheckError().voidsetResultService(ResultSetHelper resultService) Sets the result service.default voidWrites iterable to a CSV file.voidWrites iterable to a CSV file.default intWrites the entire ResultSet to a CSV file.default intWrites the entire ResultSet to a CSV file.intWrites the entire ResultSet to a CSV file.default voidWrites the entire list to a CSV file.default voidWrites the entire list to a CSV file.default voidWrites the next line to the file.voidWrites the next line to the file.
-
Field Details
-
DEFAULT_LINE_END
-
RFC4180_LINE_END
-
INITIAL_STRING_SIZE
static final int INITIAL_STRING_SIZEDefault buffer sizes- See Also:
-
DEFAULT_ESCAPE_CHARACTER
static final char DEFAULT_ESCAPE_CHARACTERThe character used for escaping quotes.- See Also:
-
DEFAULT_SEPARATOR
static final char DEFAULT_SEPARATORThe default separator to use if none is supplied to the constructor.- See Also:
-
DEFAULT_QUOTE_CHARACTER
static final char DEFAULT_QUOTE_CHARACTERThe default quote character to use if none is supplied to the constructor.- See Also:
-
NO_QUOTE_CHARACTER
static final char NO_QUOTE_CHARACTERThe quote constant to use when you wish to suppress all quoting.- See Also:
-
NO_ESCAPE_CHARACTER
static final char NO_ESCAPE_CHARACTERThe escape constant to use when you wish to suppress all escaping.- See Also:
-
-
Method Details
-
writeAll
Writes iterable to a CSV file. The list is assumed to be a String[]- Parameters:
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.
-
writeAll
Writes the entire list to a CSV file. The list is assumed to be a String[].- Parameters:
allLines- A List 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.
-
writeAll
-
writeAll
-
writeAll
Writes the entire ResultSet to a CSV file.The caller is responsible for closing the ResultSet. Values are not trimmed. Quotes are applied to all values in the output.
- Parameters:
rs- The result set to writeincludeColumnNames- True if you want column names in the output, false otherwise- Returns:
- Number of lines written.
- Throws:
IOException- Thrown by ResultSetHelper.getColumnValues()SQLException- Thrown by ResultSetHelper.getColumnValues()
-
writeAll
default int writeAll(ResultSet rs, boolean includeColumnNames, boolean trim) throws SQLException, IOException Writes the entire ResultSet to a CSV file.The caller is responsible for closing the ResultSet. Quotes are applied to all values in the output.
- Parameters:
rs- The Result set to write.includeColumnNames- Include the column names in the output.trim- Remove spaces from the data before writing.- Returns:
- Number of lines written - including header.
- Throws:
IOException- Thrown by ResultSetHelper.getColumnValues()SQLException- Thrown by ResultSetHelper.getColumnValues()
-
writeAll
int writeAll(ResultSet rs, boolean includeColumnNames, boolean trim, boolean applyQuotesToAll) throws SQLException, IOException Writes the entire ResultSet to a CSV file. The caller is responsible for closing the ResultSet.- Parameters:
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.- Returns:
- Number of lines written - including header.
- Throws:
IOException- Thrown by ResultSetHelper.getColumnValues()SQLException- Thrown by ResultSetHelper.getColumnValues()
-
writeNext
Writes the next line to the file.- Parameters:
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.
-
writeNext
Writes the next line to the file.- Parameters:
nextLine- A string array with each comma-separated element as a separate entry.
-
checkError
boolean checkError()Flushes the buffer and checks to see if the there has been an error in the printstream.- Returns:
- True if the print stream has encountered an error either on the underlying output stream or during a format conversion.
-
getException
IOException getException()Get latest exception.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.
- Returns:
- the latest IOException encountered in the print stream either on the underlying output stream or during a format conversion.
-
resetError
void resetError()Set the error back to null to be able to check for the next error usingcheckError(). -
setResultService
Sets the result service.- Parameters:
resultService- The ResultSetHelper
-
flushQuietly
default void flushQuietly()Flushes the writer without throwing any exceptions.
-