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 voidOverride this method for adding content to the CSV.final voidgenerateContent(Writer output) Generate the content and write to a writer.final StringMime type of the content.Get the value converter that maps the column values to string.final StringFile extension normally used for this type of content.protected WriterGet the writer that takes the output.voidsetColumnCount(int columnCount) Sets the number of columns to be used for the CSV content.voidsetConverter(Function<Object, String> converter) Set the value converter to map the column values to string.final voidSet a value at a specific column in the current row.final voidSet values starting from the first column in the current row.final voidsetValuesFrom(int startingColumn, Object... values) Set values starting from a specific column in the current row.voidwriteRow()Write out the current row.
-
Constructor Details
-
CSV
public CSV()Constructor. -
CSV
public CSV(int columnCount) Constructor.- Parameters:
columnCount- Number of columns.
-
-
Method Details
-
setColumnCount
public void setColumnCount(int columnCount) Sets the number of columns to be used for the CSV content. The column count must be set before the writer is initialized. Additionally, the column count must be a positive integer.- Parameters:
columnCount- The number of columns to be set. Must be 1 or greater.- Throws:
SORuntimeException- If the column count is set after the writer is initialized or if an invalid column count (less than 1) is specified.
-
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:TextContentGeneratorGenerate the content and write to a writer.- Specified by:
generateContentin 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:TextContentGeneratorMime type of the content.- Specified by:
getContentTypein interfaceContentGenerator- Specified by:
getContentTypein interfaceTextContentGenerator- Returns:
- Default implementation returns "text/plain".
-
getFileExtension
Description copied from interface:TextContentGeneratorFile extension normally used for this type of content.- Specified by:
getFileExtensionin interfaceContentGenerator- Specified by:
getFileExtensionin interfaceTextContentGenerator- Returns:
- Default implementation returns "txt".
-