Package org.kissweb
Class DelimitedFileWriter
java.lang.Object
org.kissweb.DelimitedFileWriter
- All Implemented Interfaces:
AutoCloseable
Class dealing with the creation of standard comma delimited or CSV files.
This class implements the AutoCloseable interface.
-
Constructor Summary
ConstructorDescriptionDelimitedFileWriter
(String name) Create a standard CSV file using the standard delimiter (,) and quote (") characters.DelimitedFileWriter
(String name, boolean append) Create or append to a standard CSV file using the standard delimiter (,) and quote (") characters.DelimitedFileWriter
(String name, boolean append, int itemsPerRow) Create or append to a standard CSV file using the standard delimiter (,) and quote (") characters.DelimitedFileWriter
(String name, boolean append, int itemsPerRow, char delimiter, char quote) Create a new or append to an existing CSV file.DelimitedFileWriter
(String name, char delim) Create a new CSV file us ing the specified delimiter character and the default quote character ("). -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the CSV file being created.void
End the current row.int
Returns the number of columns output already on the current row.void
setDateFormat
(String fmt) Set the format of date output.void
writeDate
(int x) Output a numeric date in the default format.void
writeField
(char x) Output a single character field.void
writeField
(double x) Output a floating point number with a maximum of two decimal places.void
writeField
(int x) Output an integer column.void
writeField
(int charLimit, String x) Write a String field limiting the size of the String.void
writeField
(String x) Write a String field correctly dealing with embedded quotes and delimitersvoid
Write a String field forcing the string to uppercase and a quoted output.void
writeNoZero
(int x) Output an integer field using an empty field if the number is zero.
-
Constructor Details
-
DelimitedFileWriter
Create a new CSV file us ing the specified delimiter character and the default quote character (").- Parameters:
name
-delim
-- Throws:
IOException
-
DelimitedFileWriter
public DelimitedFileWriter(String name, boolean append, int itemsPerRow, char delimiter, char quote) throws IOException Create a new or append to an existing CSV file.- Parameters:
name
-append
-itemsPerRow
- create a standard number of columns-per-row or specify -1 to indicate that you will explicitly output what is neededdelimiter
-quote
-- Throws:
IOException
-
DelimitedFileWriter
Create or append to a standard CSV file using the standard delimiter (,) and quote (") characters.- Parameters:
name
-append
-itemsPerRow
- create a standard number of columns-per-row or specify -1 to indicate that you will explicitly output what is needed- Throws:
IOException
-
DelimitedFileWriter
Create or append to a standard CSV file using the standard delimiter (,) and quote (") characters.- Parameters:
name
-append
-- Throws:
IOException
-
DelimitedFileWriter
Create a standard CSV file using the standard delimiter (,) and quote (") characters.- Parameters:
name
-- Throws:
IOException
-
-
Method Details
-
setDateFormat
Set the format of date output. Default is mm/dd/yyyy- Parameters:
fmt
-- See Also:
-
close
public void close()Close the CSV file being created. Note that this method will be called automatically if the try-with-resource Java facility is utilized.- Specified by:
close
in interfaceAutoCloseable
-
writeField
Write a String field correctly dealing with embedded quotes and delimiters- Parameters:
x
-- Throws:
Exception
-
writeField
Write a String field limiting the size of the String. Deals correctly with embedded quotes and delimiters.- Parameters:
charLimit
- max size of the stringx
- the string- Throws:
Exception
-
writeFieldUpperCase
Write a String field forcing the string to uppercase and a quoted output.- Parameters:
x
-- Throws:
Exception
-
writeField
Output a floating point number with a maximum of two decimal places.- Parameters:
x
-- Throws:
Exception
-
writeField
Output an integer column.- Parameters:
x
-- Throws:
Exception
-
writeNoZero
Output an integer field using an empty field if the number is zero.- Parameters:
x
-- Throws:
Exception
-
writeField
Output a single character field. Quotes and delimiters are correctly handled.- Parameters:
x
-- Throws:
Exception
-
writeDate
Output a numeric date in the default format.- Parameters:
x
- the date as an integer YYYYMMDD- Throws:
Exception
- See Also:
-
dateFmt
-
endRecord
End the current row. Throws an exception if all of the columns weren't specified.- Throws:
IOException
Exception
-
getFieldCount
public int getFieldCount()Returns the number of columns output already on the current row.- Returns:
-