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.
This class implements multi-threading on writing more than one bean, so there should be no need to use it across threads in an application. As such, it is not thread-safe.
OpencsvUtils.determineMappingStrategy(java.lang.Class, java.util.Locale, java.lang.String)
Constructor and Description |
---|
StatefulBeanToCsv(MappingStrategy<T> mappingStrategy,
CsvExceptionHandler exceptionHandler,
boolean applyQuotesToAll,
ICSVWriter csvWriter,
org.apache.commons.collections4.MultiValuedMap<Class<?>,Field> ignoredFields,
String profile)
Constructor used to allow building of a
StatefulBeanToCsv
with a user-supplied ICSVWriter class. |
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()
Deprecated.
There is simply no need for this method.
|
void |
setErrorLocale(Locale errorLocale)
Sets the locale for all error messages.
|
void |
setOrderedResults(boolean orderedResults)
Sets whether or not results must be written in the same order in which
they appear in the list of beans provided as input.
|
void |
write(Iterator<T> iBeans)
Writes an iterator of beans out to the
Writer provided to the
constructor. |
void |
write(List<T> beans)
Writes a list of beans out to the
Writer provided to the
constructor. |
void |
write(Stream<T> beans)
Writes a stream 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(MappingStrategy<T> mappingStrategy, CsvExceptionHandler exceptionHandler, boolean applyQuotesToAll, ICSVWriter csvWriter, org.apache.commons.collections4.MultiValuedMap<Class<?>,Field> ignoredFields, String profile)
StatefulBeanToCsv
with a user-supplied ICSVWriter
class.mappingStrategy
- The mapping strategy to use when writing a CSV fileexceptionHandler
- Determines the exception handling behaviorapplyQuotesToAll
- Whether all output fields should be quotedcsvWriter
- An user-supplied ICSVWriter
for writing beans to a CSV outputignoredFields
- The fields to ignore during processing. May be null
.profile
- The profile to use when configuring how to interpret bean fieldspublic 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 void write(Iterator<T> iBeans) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException
Writer
provided to the
constructor.iBeans
- An iterator 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 void write(Stream<T> beans) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException
Writer
provided to the
constructor.beans
- A stream 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 void setOrderedResults(boolean orderedResults)
orderedResults
to false
. The lack of ordering then also
applies to any captured exceptions, if you have chosen not to have
exceptions thrown.orderedResults
- Whether or not the lines written are in the same
order they appeared in the input@Deprecated public 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.
public void setErrorLocale(Locale errorLocale)
errorLocale
- Locale for error messages. If null, the default locale
is used.Copyright © 2005–2023. All rights reserved.