T
- The type of the beans being writtenpublic class StatefulBeanToCsvBuilder<T> extends Object
Constructor and Description |
---|
StatefulBeanToCsvBuilder(ICSVWriter icsvWriter)
Being stateful the writer is required by the builder at the start and not added in later.
|
StatefulBeanToCsvBuilder(Writer writer)
Default constructor - Being stateful the writer is required by the builder at the start and not added in later.
|
Modifier and Type | Method and Description |
---|---|
StatefulBeanToCsv<T> |
build()
Builds a StatefulBeanToCsv from the information provided, filling in
default values where none have been specified.
|
StatefulBeanToCsvBuilder<T> |
withApplyQuotesToAll(boolean applyQuotesToAll)
Sets whether all outputs should be put in quotes.
|
StatefulBeanToCsvBuilder<T> |
withErrorLocale(Locale errorLocale)
Sets the locale to be used for all error messages.
|
StatefulBeanToCsvBuilder<T> |
withEscapechar(char escapechar) |
StatefulBeanToCsvBuilder<T> |
withExceptionHandler(CsvExceptionHandler exceptionHandler)
Sets the handler for recoverable exceptions raised during processing of
records.
|
StatefulBeanToCsvBuilder<T> |
withIgnoreField(Class<?> type,
Field field)
Adds a
Field to the list of fields opencsv should ignore
completely. |
StatefulBeanToCsvBuilder<T> |
withLineEnd(String lineEnd) |
StatefulBeanToCsvBuilder<T> |
withMappingStrategy(MappingStrategy<T> mappingStrategy)
Sets the mapping strategy for writing beans to a CSV destination.
|
StatefulBeanToCsvBuilder<T> |
withOrderedResults(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.
|
StatefulBeanToCsvBuilder<T> |
withProfile(String profile)
Selects a profile for deciding which configurations to use for the bean
fields.
|
StatefulBeanToCsvBuilder<T> |
withQuotechar(char quotechar) |
StatefulBeanToCsvBuilder<T> |
withSeparator(char separator) |
StatefulBeanToCsvBuilder<T> |
withThrowExceptions(boolean throwExceptions)
Sets the handler for recoverable exceptions that arise during the
processing of records.
|
public StatefulBeanToCsvBuilder(Writer writer)
writer
- - the writer that will be used to output the csv version of the bean.public StatefulBeanToCsvBuilder(ICSVWriter icsvWriter)
icsvWriter
- - the ICSVWriter that will be used to output the csv version of the bean.public StatefulBeanToCsvBuilder<T> withMappingStrategy(MappingStrategy<T> mappingStrategy)
If the mapping strategy is set this way, it will always be used instead of automatic determination of an appropriate mapping strategy.
It is perfectly legitimate to read a CSV source, take the mapping strategy from the read operation, and pass it in to this method for a write operation. This conserves some processing time, but, more importantly, preserves header ordering.
mappingStrategy
- The mapping strategy to be used for write operationspublic StatefulBeanToCsvBuilder<T> withSeparator(char separator)
separator
- The field separator to be used when writing a CSV fileCSVWriter.separator
public StatefulBeanToCsvBuilder<T> withQuotechar(char quotechar)
quotechar
- The quote character to be used when writing a CSV fileCSVWriter.quotechar
public StatefulBeanToCsvBuilder<T> withEscapechar(char escapechar)
escapechar
- The escape character to be used when writing a CSV fileCSVWriter.escapechar
public StatefulBeanToCsvBuilder<T> withLineEnd(String lineEnd)
lineEnd
- The line ending to be used when writing a CSV fileAbstractCSVWriter.lineEnd
public StatefulBeanToCsvBuilder<T> withThrowExceptions(boolean throwExceptions)
This is a convenience function and is maintained for backwards
compatibility. Passing in true
is equivalent to
withExceptionHandler(new ExceptionHandlerThrow())
and false
is equivalent to
withExceptionHandler(new ExceptionHandlerQueue())
Please note that if both this method and
withExceptionHandler(CsvExceptionHandler)
are called,
the last call wins.
throwExceptions
- Whether or not exceptions should be thrown while
writing a CSV file. If not, they may be retrieved later by calling
StatefulBeanToCsv.getCapturedExceptions()
.withExceptionHandler(CsvExceptionHandler)
public StatefulBeanToCsvBuilder<T> withExceptionHandler(CsvExceptionHandler exceptionHandler)
If neither this method nor withThrowExceptions(boolean)
is
called, the default exception handler is
ExceptionHandlerThrow
.
Please note that if both this method and
withThrowExceptions(boolean)
are called, the last call wins.
exceptionHandler
- The exception handler to be used. If null
,
this method does nothing.this
public StatefulBeanToCsvBuilder<T> withOrderedResults(boolean orderedResults)
orderedResults
- Whether or not the lines written are in the same
order they appeared in the inputStatefulBeanToCsv.setOrderedResults(boolean)
public StatefulBeanToCsvBuilder<T> withErrorLocale(Locale errorLocale)
errorLocale
- Locale for error messages. If null, the default locale
is used.StatefulBeanToCsv.setErrorLocale(java.util.Locale)
public StatefulBeanToCsvBuilder<T> withApplyQuotesToAll(boolean applyQuotesToAll)
true
.applyQuotesToAll
- Whether all outputs should be quotedAbstractCSVWriter.writeNext(String[], boolean)
public StatefulBeanToCsvBuilder<T> withIgnoreField(Class<?> type, Field field) throws IllegalArgumentException
Field
to the list of fields opencsv should ignore
completely.
May be called as many times as necessary.
type
- The class opencsv will encounter the field in during
processing. In the case of inheritance, this may not be the
declaring class.field
- The field opencsv is to ignorethis
IllegalArgumentException
- If one of the parameters is
null
or field
cannot be found in type
.MappingStrategy.ignoreFields(MultiValuedMap)
public StatefulBeanToCsvBuilder<T> withProfile(String profile)
profile
- The name of the profile to be usedthis
public StatefulBeanToCsv<T> build()
StatefulBeanToCsv
Copyright © 2005–2023. All rights reserved.