Package com.storedobject.common
Class CSV
java.lang.Object
com.storedobject.common.CSV
-
Field Summary
Fields inherited from interface com.storedobject.common.ContentGenerator
ext
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
Override this method for adding content to the CSV.final void
generateContent
(Writer output) Generate the content and write to a writer.final String
Mime type of the content.Get the value converter that maps the column values to string.final String
File extension normally used for this type of content.protected Writer
Get the writer that takes the output.void
setConverter
(Function<Object, String> converter) Set the value converter to map the column values to string.final void
Set a value at a specific column in the current row.final void
Set values starting from the first column in the current row.final void
setValuesFrom
(int startingColumn, Object... values) Set values starting from a specific column in the current row.void
writeRow()
Write out the current row.
-
Constructor Details
-
CSV
public CSV(int columnCount) Constructor.- Parameters:
columnCount
- Number of columns.
-
-
Method Details
-
generateContent
Override this method for adding content to the CSV. Typically, you callsetValue(int, Object)
(or its variants -setValues(Object...)
orsetValuesFrom(int, Object...)
) for each column value and callwriteRow()
to write out each row.- Throws:
Exception
-
generateContent
Description copied from interface:TextContentGenerator
Generate the content and write to a writer.- Specified by:
generateContent
in interfaceTextContentGenerator
- Parameters:
output
- Writer to collect the generated content.- Throws:
Exception
- if content can not be generated.
-
setValue
Set a value at a specific column in the current row.- Parameters:
column
- Column,value
- Value to set.
-
setValuesFrom
Set values starting from a specific column in the current row.- Parameters:
startingColumn
- Column,values
- Values to set.
-
setValues
Set values starting from the first column in the current row.- Parameters:
values
- Values to set.
-
writeRow
-
setConverter
Set the value converter to map the column values to string.- Parameters:
converter
- Converter. If no converter is set,StringUtility.toString(Object)
is used as the default converter.
-
getConverter
-
getWriter
Get the writer that takes the output. (You should not write anything directly to it).- Returns:
- The writer.
-
getContentType
Description copied from interface:TextContentGenerator
Mime type of the content.- Specified by:
getContentType
in interfaceContentGenerator
- Specified by:
getContentType
in interfaceTextContentGenerator
- Returns:
- Default implementation returns "text/plain".
-
getFileExtension
Description copied from interface:TextContentGenerator
File extension normally used for this type of content.- Specified by:
getFileExtension
in interfaceContentGenerator
- Specified by:
getFileExtension
in interfaceTextContentGenerator
- Returns:
- Default implementation returns "txt".
-