java.lang.Object
org.csveed.api.CsvClientImpl<T>
-
Constructor Summary
ConstructorDescriptionCsvClientImpl
(Reader reader) Instantiates a new csv client impl.CsvClientImpl
(Reader reader, Class<T> beanClass) Instantiates a new csv client impl.CsvClientImpl
(Reader reader, BeanInstructions beanInstructions) Instantiates a new csv client impl.CsvClientImpl
(Writer writer) Instantiates a new csv client impl.CsvClientImpl
(Writer writer, Class<T> beanClass) Instantiates a new csv client impl.CsvClientImpl
(Writer writer, BeanInstructions beanInstructions) Instantiates a new csv client impl. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the line from which the row was read.Gets the row writer.ignoreProperty
(String propertyName) Sets a field to be ignored for purposes of mapping.boolean
States whether the Reader is done with the file.mapColumnIndexToProperty
(int columnIndex, String propertyName) Maps a column in the CSV to a specific property.mapColumnNameToProperty
(String columnName, String propertyName) Maps a column name (which is found in the header) to a specific property.readBean()
Reads a single row and returns this as a bean.Reads all rows from the file and return these as beans.Returns the header of the CSV file.readRow()
Reads a single row from the file and returns this.readRows()
Reads all rows from the file and returns them as a List.setComment
(char symbol) Sets the character that will be interpreted as a comment field on the first position of a row.setConverter
(String propertyName, Converter converter) Sets a customPropertyEditor
for the property.Determines what dateformat to apply to the cell value before storing it as a date.setEndOfLine
(char[] symbols) Sets the characters (plural) that will be interpreted as end-of-line markers (unless within a quoted field).setEscape
(char symbol) Sets the character that will be interpreted as an escape symbol while within a quoted field.setHeaderNameToProperty
(String propertyName) Determines what property will receive the header name in the currently active dynamic column.setHeaderValueToProperty
(String propertyName) Determines what property will receive the cell value in the currently active dynamic column.setLocalizedNumber
(String propertyName, Locale locale) Determines what Locale to apply to the cell value before converting it to a number.setMapper
(Class<? extends AbstractMapper> mapper) Determines which mapping strategy is to be employed for mapping cells to bean properties.setQuote
(char symbol) Sets the character that will be interpreted as a quote symbol, signifying either the start or the end of a quoted field.setRequired
(String propertyName, boolean required) Determines if the field is required.setSeparator
(char symbol) Sets the character that will be interpreted as a separator between cells.setStartIndexDynamicColumns
(int startIndex) A file can have a special layout with a dynamic number of columns.setStartRow
(int startRow) Sets the start row of the CSV file.setUseHeader
(boolean useHeader) Makes sure that the first readable line is interpreted as the header line.skipCommentLines
(boolean skip) Determines whether comment lines must be skipped.skipEmptyLines
(boolean skip) Determines whether empty lines must be skipped or treated as single-column rows.void
Writes a single Bean to the table.void
writeBeans
(Collection<T> beans) Writes a collection of Beans to the table.void
Writes a header based on the bean properties to the table.writeHeader
(String[] header) Writes the header to the table.void
writeHeader
(Header header) Writes the header to the table.Writes a single row (consisting of String cells) to the table.void
Writes a single row to the table.void
Writes a two-dimensional array of cells (rows with cells) to the table.void
writeRows
(Collection<Row> rows) Writes a collection of rows to the table.
-
Constructor Details
-
CsvClientImpl
Instantiates a new csv client impl.- Parameters:
writer
- the writer
-
CsvClientImpl
-
CsvClientImpl
Instantiates a new csv client impl.- Parameters:
writer
- the writerbeanInstructions
- the bean instructions
-
CsvClientImpl
Instantiates a new csv client impl.- Parameters:
reader
- the reader
-
CsvClientImpl
-
CsvClientImpl
Instantiates a new csv client impl.- Parameters:
reader
- the readerbeanInstructions
- the bean instructions
-
-
Method Details
-
writeBeans
Description copied from interface:CsvClient
Writes a collection of Beans to the table.- Specified by:
writeBeans
in interfaceCsvClient<T>
- Parameters:
beans
- beans to write to the table
-
writeBean
-
writeRow
-
writeRow
-
writeRows
-
writeRows
-
writeHeader
-
writeHeader
Description copied from interface:CsvClient
Writes the header to the table.- Specified by:
writeHeader
in interfaceCsvClient<T>
- Parameters:
header
- the header row
-
writeHeader
public void writeHeader()Description copied from interface:CsvClient
Writes a header based on the bean properties to the table.- Specified by:
writeHeader
in interfaceCsvClient<T>
-
readBeans
-
readBean
-
readRows
-
readRow
-
readHeader
Description copied from interface:CsvClient
Returns the header of the CSV file. Only possibly returns a value when useHeader==true- Specified by:
readHeader
in interfaceCsvClient<T>
- Returns:
- header or null if the useHeader==false
-
getCurrentLine
public int getCurrentLine()Description copied from interface:CsvClient
Returns the line from which the row was read. Note that a line is seen as a legitimate CSV row, not necessarily a printable line (unless multi-lines are used, these values are the same).- Specified by:
getCurrentLine
in interfaceCsvClient<T>
- Returns:
- current line number
-
isFinished
public boolean isFinished()Description copied from interface:CsvClient
States whether the Reader is done with the file.- Specified by:
isFinished
in interfaceCsvClient<T>
- Returns:
- true if file is finished
-
setUseHeader
Description copied from interface:CsvClient
Makes sure that the first readable line is interpreted as the header line. That line will not be read as content. This method is called wheneverCsvFile.useHeader()
is used. The default value for this setting is true. This call is a facade forRowInstructions.setUseHeader(boolean)
.- Specified by:
setUseHeader
in interfaceCsvClient<T>
- Parameters:
useHeader
- true if the header is interpreted and used- Returns:
- convenience for chaining
-
setStartRow
Description copied from interface:CsvClient
Sets the start row of the CSV file. IfCsvClient.setUseHeader(boolean)
== true, this will be the header row and the next ones are all content rows. This method is called wheneverCsvFile.startRow()
is used. The default value for this setting is 1. This call is a facade forRowInstructions.setStartRow(int)
.- Specified by:
setStartRow
in interfaceCsvClient<T>
- Parameters:
startRow
- the first row to start reading, including the header row- Returns:
- convenience for chaining
-
setEscape
Description copied from interface:CsvClient
Sets the character that will be interpreted as an escape symbol while within a quoted field. This method is called wheneverCsvFile.escape()
is used. The default value for this setting is a double quote (") symbol. This call is a facade forRowInstructions.setEscape(char)
. -
setQuote
Description copied from interface:CsvClient
Sets the character that will be interpreted as a quote symbol, signifying either the start or the end of a quoted field. This method is called wheneverCsvFile.quote()
is used. The default value for this setting is a double quote (") symbol. This call is a facade forRowInstructions.setQuote(char)
. -
setSeparator
Description copied from interface:CsvClient
Sets the character that will be interpreted as a separator between cells. This method is called wheneverCsvFile.separator()
is used. The default value for this setting is a semi-colon (;). This call is a facade forRowInstructions.setSeparator(char)
.- Specified by:
setSeparator
in interfaceCsvClient<T>
- Parameters:
symbol
- the symbol to use as a separator between cells- Returns:
- convenience for chaining
-
setComment
Description copied from interface:CsvClient
Sets the character that will be interpreted as a comment field on the first position of a row. This method is called wheneverCsvFile.comment()
is used. The default value for this setting is a hashtag (#).- Specified by:
setComment
in interfaceCsvClient<T>
- Parameters:
symbol
- the symbol to use as the 0-position comment marker- Returns:
- convenience for chaining
-
setEndOfLine
Description copied from interface:CsvClient
Sets the characters (plural) that will be interpreted as end-of-line markers (unless within a quoted field). This method is called wheneverCsvFile.endOfLine()
is used. The default values for this setting are \r and \n. This call is a facade forRowInstructions.setEndOfLine(char[])
.- Specified by:
setEndOfLine
in interfaceCsvClient<T>
- Parameters:
symbols
- the symbol to interpret as end-of-line markers (unless within a quoted field)- Returns:
- convenience for chaining
-
skipEmptyLines
Description copied from interface:CsvClient
Determines whether empty lines must be skipped or treated as single-column rows. This method is called wheneverCsvFile.skipEmptyLines()
is used. The default value for this setting is to skip the empty lines.- Specified by:
skipEmptyLines
in interfaceCsvClient<T>
- Parameters:
skip
- true to skip empty lines, false to treat as single-column rows- Returns:
- convenience for chaining
-
skipCommentLines
Description copied from interface:CsvClient
Determines whether comment lines must be skipped. This method is called wheneverCsvFile.skipCommentLines()
is used. The default value for this setting is to skip comment lines. This method exists to guarantee that lines are not accidentally treated as comment lines.- Specified by:
skipCommentLines
in interfaceCsvClient<T>
- Parameters:
skip
- true to skip comment lines, identified as starting with a comment marker- Returns:
- convenience for chaining
-
setMapper
Description copied from interface:CsvClient
Determines which mapping strategy is to be employed for mapping cells to bean properties. This method is called wheneverCsvFile.mappingStrategy()
is used. The default mapping strategy isColumnIndexMapper
, which looks at either the position of a property within the class or the custom index ifCsvCell.columnIndex()
orCsvClient.mapColumnIndexToProperty(int, String)
has been set. -
setDate
-
setLocalizedNumber
Description copied from interface:CsvClient
Determines what Locale to apply to the cell value before converting it to a number. This method is called wheneverCsvLocalizedNumber
is used. The default for Locale is the Locale of the server.- Specified by:
setLocalizedNumber
in interfaceCsvClient<T>
- Parameters:
propertyName
- the name of the property to write the data tolocale
- the Locale to apply for converting the number- Returns:
- convenience for chaining
-
setRequired
Description copied from interface:CsvClient
Determines if the field is required. If so, the cell may not be empty and aCsvException
will be thrown if this occurs. This method is called wheneverCsvCell.required()
is used. The default for a property is false.- Specified by:
setRequired
in interfaceCsvClient<T>
- Parameters:
propertyName
- property for which the requirement appliesrequired
- whether the cell must be not-null- Returns:
- convenience for chaining
-
setConverter
Description copied from interface:CsvClient
Sets a customPropertyEditor
for the property. This PropertyEditor is called to convert the text to the type of the property and set it on the bean. This method is called wheneverCsvConverter.converter()
is used. The default for a property is based on the wonderful set of PropertyEditors that Spring offers, which is all basics and some extras as well.- Specified by:
setConverter
in interfaceCsvClient<T>
- Parameters:
propertyName
- property to which the converter must be appliedconverter
- PropertyEditor to apply to the property- Returns:
- convenience for chaining
-
ignoreProperty
Description copied from interface:CsvClient
Sets a field to be ignored for purposes of mapping. This method is called wheneverCsvIgnore
is used. By default none of the fields are ignored unless, custom instructions are used. In this case, all fields are ignored by default.- Specified by:
ignoreProperty
in interfaceCsvClient<T>
- Parameters:
propertyName
- property which must be ignored for mapping- Returns:
- convenience for chaining
-
mapColumnIndexToProperty
Description copied from interface:CsvClient
Maps a column in the CSV to a specific property. This method is called wheneverCsvCell.columnIndex()
is used. By default there is NO mapping when custom instructions are used, so you should roll your own. Note that column indexes are 1-based, not 0-based.- Specified by:
mapColumnIndexToProperty
in interfaceCsvClient<T>
- Parameters:
columnIndex
- index of the column for which the property mapping must be appliedpropertyName
- property to which the index-based mapping must be applied- Returns:
- convenience for chaining
-
mapColumnNameToProperty
Description copied from interface:CsvClient
Maps a column name (which is found in the header) to a specific property. Note that to use this, headers must be enabled. This method is called wheneverCsvCell.columnName()
is used. By default there is NO mapping when custom instructions are used, so you should roll your own. Also, don't forget toCsvClient.setMapper(Class)
toColumnNameMapper
for this to work.- Specified by:
mapColumnNameToProperty
in interfaceCsvClient<T>
- Parameters:
columnName
- name of the column for which the property mapping must be appliedpropertyName
- property to which the name-based mapping must be applied- Returns:
- convenience for chaining
-
setStartIndexDynamicColumns
Description copied from interface:CsvClient
A file can have a special layout with a dynamic number of columns. If the intention is to duplicate rows for every separate column, this is the method you require. It will remember the start position of the dynamic columns and treat every column after that as dynamic. For every dynamic column a row will be created. If a bean has fields annotated with @CsvHeaderName or @CsvHeaderValue, it will store the values of the header or the cell for that index column in the fields.- Specified by:
setStartIndexDynamicColumns
in interfaceCsvClient<T>
- Parameters:
startIndex
- the index where the dynamic columns start- Returns:
- convenience for chaining
-
setHeaderNameToProperty
Description copied from interface:CsvClient
Determines what property will receive the header name in the currently active dynamic column.- Specified by:
setHeaderNameToProperty
in interfaceCsvClient<T>
- Parameters:
propertyName
- property in which the active dynamic header name must be stored- Returns:
- convenience for chaining
-
setHeaderValueToProperty
Description copied from interface:CsvClient
Determines what property will receive the cell value in the currently active dynamic column.- Specified by:
setHeaderValueToProperty
in interfaceCsvClient<T>
- Parameters:
propertyName
- property in which the active dynamic column value must be stored- Returns:
- convenience for chaining
-
getRowWriter
-