T
- Class to convert the objects to.public class CsvToBean<T> extends AbstractCSVToBean
Constructor and Description |
---|
CsvToBean()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
List<CsvException> |
getCapturedExceptions()
Returns the list of all exceptions that would have been thrown during the
import, but were suppressed by setting
throwExceptions to false . |
protected PropertyEditor |
getPropertyEditor(PropertyDescriptor desc)
Attempt to find custom property editor on descriptor first, else try the
propery editor manager.
|
List<T> |
parse()
Parses the input based on parameters already set through other methods.
|
List<T> |
parse(MappingStrategy<T> mapper,
CSVReader csv)
Parse the values from the CSVReader.
|
List<T> |
parse(MappingStrategy<T> mapper,
CSVReader csv,
boolean throwExceptions)
Parse the values from the CSVReader.
|
List<T> |
parse(MappingStrategy<T> mapper,
CSVReader csv,
CsvToBeanFilter filter)
Parse the values from the CSVReader.
|
List<T> |
parse(MappingStrategy<T> mapper,
CSVReader csv,
CsvToBeanFilter filter,
boolean throwExceptions)
Parse the values from the CSVReader.
|
List<T> |
parse(MappingStrategy<T> mapper,
Reader reader)
Parse the values from a CSVReader constructed from the Reader passed in.
|
List<T> |
parse(MappingStrategy<T> mapper,
Reader reader,
boolean throwExceptions)
Parse the values from a CSVReader constructed from the Reader passed in.
|
List<T> |
parse(MappingStrategy<T> mapper,
Reader reader,
CsvToBeanFilter filter)
Parse the values from a CSVReader constructed from the Reader passed in.
|
List<T> |
parse(MappingStrategy<T> mapper,
Reader reader,
CsvToBeanFilter filter,
boolean throwExceptions)
Parse the values from a CSVReader constructed from the Reader passed in.
|
protected T |
processLine(MappingStrategy<T> mapper,
String[] line)
Creates a single object from a line from the CSV file.
|
void |
setCsvReader(CSVReader csvReader)
Sets the reader to be used to read in the information from the CSV input.
|
void |
setFilter(CsvToBeanFilter filter)
Sets a filter to selectively remove some lines of input before they
become beans.
|
void |
setMappingStrategy(MappingStrategy<T> mappingStrategy)
Sets the mapping strategy to be used by this bean.
|
void |
setThrowExceptions(boolean throwExceptions)
Determines whether errors during import should be thrown or kept in a
list for later retrieval via
getCapturedExceptions() . |
checkForTrim, convertValue, getPropertyEditorValue
public List<T> parse(MappingStrategy<T> mapper, Reader reader)
mapper
- Mapping strategy for the bean.reader
- Reader used to construct a CSVReaderpublic List<T> parse(MappingStrategy<T> mapper, Reader reader, boolean throwExceptions)
mapper
- Mapping strategy for the bean.reader
- Reader used to construct a CSVReaderthrowExceptions
- If false, exceptions internal to opencsv will not
be thrown, but can be accessed after processing is finished through
getCapturedExceptions()
.public List<T> parse(MappingStrategy<T> mapper, Reader reader, CsvToBeanFilter filter)
mapper
- Mapping strategy for the bean.reader
- Reader used to construct a CSVReaderfilter
- CsvToBeanFilter to apply - null if no filter.public List<T> parse(MappingStrategy<T> mapper, Reader reader, CsvToBeanFilter filter, boolean throwExceptions)
mapper
- Mapping strategy for the bean.reader
- Reader used to construct a CSVReaderfilter
- CsvToBeanFilter to apply - null if no filter.throwExceptions
- If false, exceptions internal to opencsv will not
be thrown, but can be accessed after processing is finished through
getCapturedExceptions()
.public List<T> parse(MappingStrategy<T> mapper, CSVReader csv)
mapper
- Mapping strategy for the bean.csv
- CSVReaderpublic List<T> parse(MappingStrategy<T> mapper, CSVReader csv, boolean throwExceptions)
mapper
- Mapping strategy for the bean.csv
- CSVReaderthrowExceptions
- If false, exceptions internal to opencsv will not
be thrown, but can be accessed after processing is finished through
getCapturedExceptions()
.public List<T> parse(MappingStrategy<T> mapper, CSVReader csv, CsvToBeanFilter filter)
mapper
- Mapping strategy for the bean.csv
- CSVReaderfilter
- CsvToBeanFilter to apply - null if no filter.public List<T> parse(MappingStrategy<T> mapper, CSVReader csv, CsvToBeanFilter filter, boolean throwExceptions)
getCapturedExceptions()
.mapper
- Mapping strategy for the bean.csv
- CSVReaderfilter
- CsvToBeanFilter to apply - null if no filter.throwExceptions
- If false, exceptions internal to opencsv will not
be thrown, but can be accessed after processing is finished through
getCapturedExceptions()
.public List<T> parse() throws IllegalStateException
IllegalStateException
- If either MappingStrategy or CSVReader is
not specifiedprotected T processLine(MappingStrategy<T> mapper, String[] line) throws IllegalAccessException, InvocationTargetException, InstantiationException, IntrospectionException, CsvBadConverterException, CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException
mapper
- MappingStrategyline
- Array of Strings from the CSV file.IllegalAccessException
- Thrown on error creating bean.InvocationTargetException
- Thrown on error calling the setters.InstantiationException
- Thrown on error creating bean.IntrospectionException
- Thrown on error getting the PropertyDescriptor.CsvBadConverterException
- If a custom converter cannot be
initialized properlyCsvDataTypeMismatchException
- If the source data cannot be converted
to the type of the destination fieldCsvRequiredFieldEmptyException
- If a mandatory field is empty in
the input fileCsvConstraintViolationException
- When the internal structure of
data would be violated by the data in the CSV fileprotected PropertyEditor getPropertyEditor(PropertyDescriptor desc) throws InstantiationException, IllegalAccessException
AbstractCSVToBean
getPropertyEditor
in class AbstractCSVToBean
desc
- PropertyDescriptor.InstantiationException
- Thrown when getting the PropertyEditor for the class.IllegalAccessException
- Thrown when getting the PropertyEditor for the class.public List<CsvException> getCapturedExceptions()
throwExceptions
to false
.public void setMappingStrategy(MappingStrategy<T> mappingStrategy)
mappingStrategy
- Mapping strategy to convert CSV input to a beanpublic void setCsvReader(CSVReader csvReader)
csvReader
- Reader for inputpublic void setFilter(CsvToBeanFilter filter)
filter
- A class that filters the input linespublic void setThrowExceptions(boolean throwExceptions)
getCapturedExceptions()
.throwExceptions
- Whether or not to throw exceptions during processingCopyright © 2017. All rights reserved.