T
- Type of the bean to be writtenpublic class StatefulBeanToCsv<T> extends Object
Writer
,
keeping state information and making an intelligent guess at the mapping
strategy to be applied.MappingUtils.determineMappingStrategy(java.lang.Class)
Constructor and Description |
---|
StatefulBeanToCsv(char escapechar,
String lineEnd,
MappingStrategy<T> mappingStrategy,
char quotechar,
char separator,
boolean throwExceptions,
Writer writer)
The only constructor that should be used.
|
Modifier and Type | Method and Description |
---|---|
List<CsvException> |
getCapturedExceptions()
Any exceptions captured during writing of beans to a CSV destination can
be retrieved through this method.
|
boolean |
isThrowExceptions() |
void |
write(List<T> beans)
Writes a list of beans out to the
Writer provided to the
constructor. |
void |
write(T bean)
Writes a bean out to the
Writer provided to the
constructor. |
public StatefulBeanToCsv(char escapechar, String lineEnd, MappingStrategy<T> mappingStrategy, char quotechar, char separator, boolean throwExceptions, Writer writer)
escapechar
- The escape character to use when writing a CSV filelineEnd
- The line ending to use when writing a CSV filemappingStrategy
- The mapping strategy to use when writing a CSV filequotechar
- The quote character to use when writing a CSV fileseparator
- The field separator to use when writing a CSV filethrowExceptions
- Whether or not exceptions should be thrown while
writing the CSV file. If not, they are collected and can be retrieved
via getCapturedExceptions()
.writer
- A Writer
for writing the beans as a CSV topublic void write(T bean) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException
Writer
provided to the
constructor.bean
- A bean to be written to a CSV destinationCsvDataTypeMismatchException
- If a field of the bean is
annotated improperly or an unsupported data type is supposed to be
writtenCsvRequiredFieldEmptyException
- If a field is marked as required,
but the source is nullpublic void write(List<T> beans) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException
Writer
provided to the
constructor.beans
- A list of beans to be written to a CSV destinationCsvDataTypeMismatchException
- If a field of the beans is
annotated improperly or an unsupported data type is supposed to be
writtenCsvRequiredFieldEmptyException
- If a field is marked as required,
but the source is nullpublic boolean isThrowExceptions()
getCapturedExceptions()
.public List<CsvException> getCapturedExceptions()
Reads from the list are destructive! Calling this method will
clear the list of captured exceptions. However, calling
write(java.util.List)
or write(java.lang.Object)
multiple times with no intervening call to this method will not clear the
list of captured exceptions, but rather add to it if further exceptions
are thrown.
Copyright © 2017. All rights reserved.