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 queued by the exception handler.
|
Iterator<T> |
iterator()
The iterator returned by this method takes one line of input at a time
and returns one bean at a time.
|
List<T> |
parse()
Parses the input based on parameters already set through other methods.
|
void |
setCsvReader(CSVReader csvReader)
Sets the reader to be used to read in the information from the CSV input.
|
void |
setErrorLocale(Locale errorLocale)
Sets the locale for error messages.
|
void |
setExceptionHandler(CsvExceptionHandler handler)
Sets the handler for recoverable exceptions raised during processing of
records.
|
void |
setFilter(CsvToBeanFilter filter)
Sets a filter to selectively remove some lines of input before they
become beans.
|
void |
setIgnoreEmptyLines(boolean ignoreEmptyLines)
Ignores any blank lines in the data that are not part of a field.
|
void |
setMappingStrategy(MappingStrategy<? extends T> mappingStrategy)
Sets the mapping strategy to be used by this bean.
|
void |
setOrderedResults(boolean orderedResults)
Sets whether or not results must be returned in the same order in which
they appear in the input.
|
void |
setThrowExceptions(boolean throwExceptions)
Determines whether errors during import should be thrown or kept in a
list for later retrieval via
getCapturedExceptions() . |
void |
setVerifiers(List<BeanVerifier<T>> verifiers)
Sets the list of verifiers to be run on all beans after creation.
|
Stream<T> |
stream()
Parses the input based on parameters already set through other methods.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public List<T> parse() throws IllegalStateException
IllegalStateException
- If either MappingStrategy or CSVReader is
not specifiedstream()
,
iterator()
public Stream<T> stream() throws IllegalStateException
parse()
because it avoids the intermediate storage of the
results in a List
. If you plan on further processing
the results as a Stream
, use this method.IllegalStateException
- If either MappingStrategy or CSVReader is
not specifiedparse()
,
iterator()
public List<CsvException> getCapturedExceptions()
The results returned by this method are not consistent until parsing is concluded.
setExceptionHandler(CsvExceptionHandler)
,
setThrowExceptions(boolean)
public void setMappingStrategy(MappingStrategy<? extends 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()
.
This is a convenience function and is maintained for backwards
compatibility. Passing in true
is equivalent to
setExceptionHandler(new ExceptionHandlerThrow())
and false
is equivalent to
setExceptionHandler(new ExceptionHandlerQueue())
Please note that if both this method and
setExceptionHandler(CsvExceptionHandler)
are called,
the last call wins.
throwExceptions
- Whether or not to throw exceptions during
processingsetExceptionHandler(CsvExceptionHandler)
public void setExceptionHandler(CsvExceptionHandler handler)
If neither this method nor setThrowExceptions(boolean)
is
called, the default exception handler is
ExceptionHandlerThrow
.
Please note that if both this method and
setThrowExceptions(boolean)
are called, the last call wins.
handler
- The exception handler to be used. If null
,
this method does nothing.public 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 beans returned are in the same
order they appeared in the inputpublic void setErrorLocale(Locale errorLocale)
errorLocale
- Locale for error messages. If null, the default locale
is used.public void setVerifiers(List<BeanVerifier<T>> verifiers)
verifiers
- A list of verifiers. May be null
, in which
case, no verifiers are run.public Iterator<T> iterator()
The advantage to this method is saving memory. The cost is the loss of parallel processing, reducing throughput.
The iterator respects all aspects of CsvToBean
, including
filters and capturing exceptions.
public void setIgnoreEmptyLines(boolean ignoreEmptyLines)
ignoreEmptyLines
- true
to ignore empty lines, false
otherwiseCopyright © 2005–2023. All rights reserved.