public final class OpencsvUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Pattern |
compilePattern(String regex,
int regexFlags,
Class<?> callingClass,
Locale errorLocale)
Compiles a regular expression into a
Pattern ,
throwing an exception that is proper in the context of opencsv if the
regular expression is not valid. |
static Pattern |
compilePatternAtLeastOneGroup(String regex,
int regexFlags,
Class<?> callingClass,
Locale errorLocale)
Compiles a regular expression into a
Pattern ,
throwing an exception that is proper in the context of opencsv if the
regular expression is not valid, or if it does not have at least one
capturing group. |
static <T> MappingStrategy<T> |
determineMappingStrategy(Class<? extends T> type,
Locale errorLocale,
String profile)
Determines which mapping strategy is appropriate for this bean.
|
static void |
handleException(CsvException e,
long lineNumber,
CsvExceptionHandler exceptionHandler,
BlockingQueue<OrderedObject<CsvException>> queue)
A function to consolidate code common to handling exceptions thrown
during reading or writing of CSV files.
|
static <E> void |
queueRefuseToAcceptDefeat(BlockingQueue<E> queue,
E object)
I find it annoying that when I want to queue something in a blocking
queue, the thread might be interrupted and I have to try again; this
method fixes that.
|
static void |
verifyFormatString(String format,
Class<?> callingClass,
Locale errorLocale)
Verifies that the given format string works with one string parameter.
|
public static <T> MappingStrategy<T> determineMappingStrategy(Class<? extends T> type, Locale errorLocale, String profile)
CsvBindByPosition
,
CsvCustomBindByPosition
, CsvBindAndSplitByPosition
or
CsvBindAndJoinByPosition
are present,
ColumnPositionMappingStrategy
is chosen.HeaderColumnNameMappingStrategy
is chosen. If
annotations are present, they will be used, otherwise the field names
will be used as the column names.T
- The type of the bean for which the mapping strategy is soughttype
- The class of the bean for which the mapping strategy is soughterrorLocale
- The locale to use for all error messages. If null, the
default locale is used.profile
- The profile to use when configuring bean fieldspublic static <E> void queueRefuseToAcceptDefeat(BlockingQueue<E> queue, E object)
E
- The type of the object to be queuedqueue
- The queue the object should be added toobject
- The object to be queuedpublic static void handleException(CsvException e, long lineNumber, CsvExceptionHandler exceptionHandler, BlockingQueue<OrderedObject<CsvException>> queue)
e
- The exception originally thrownlineNumber
- The line or record number that caused the exceptionexceptionHandler
- The exception handlerqueue
- The queue for captured exceptionspublic static Pattern compilePatternAtLeastOneGroup(String regex, int regexFlags, Class<?> callingClass, Locale errorLocale) throws CsvBadConverterException
Pattern
,
throwing an exception that is proper in the context of opencsv if the
regular expression is not valid, or if it does not have at least one
capturing group.regex
- The regular expression to be compiled. May be null
or an empty string, in which case null
is returned.
Must have at least one capturing group if not null
or empty.regexFlags
- Flags for compiling the regular expression, as in
Pattern.compile(String, int)
.callingClass
- The class from which this method is being called.
Used for generating helpful exceptions.errorLocale
- The locale to be used for error messages. If
null
, the default locale is used.null
if the input was null or
emptyCsvBadConverterException
- If the regular expression is not empty
but invalid or valid but does not have at least one capturing grouppublic static Pattern compilePattern(String regex, int regexFlags, Class<?> callingClass, Locale errorLocale) throws CsvBadConverterException
Pattern
,
throwing an exception that is proper in the context of opencsv if the
regular expression is not valid.
This method may be used by custom converters if they are required to
compile regular expressions that are unknown at compile time.regex
- The regular expression to be compiled. May be null
or an empty string, in which case null
is returned.regexFlags
- Flags for compiling the regular expression, as in
Pattern.compile(String, int)
.callingClass
- The class from which this method is being called.
Used for generating helpful exceptions.errorLocale
- The locale to be used for error messages. If
null
, the default locale is used.null
if the input was null or
emptyCsvBadConverterException
- If the regular expression is not empty
but invalidpublic static void verifyFormatString(String format, Class<?> callingClass, Locale errorLocale)
format
- A format string for String.format(String, Object...)
callingClass
- The class from which this method is being called.
Used for generating helpful exceptions.errorLocale
- The locale to be used for error messages. If
null
, the default locale is used.Copyright © 2005–2023. All rights reserved.