Package org.jeasy.batch.flatfile
Class DelimitedRecordMapper<P>
- java.lang.Object
-
- org.jeasy.batch.core.mapper.AbstractRecordMapper<P>
-
- org.jeasy.batch.flatfile.DelimitedRecordMapper<P>
-
- Type Parameters:
P- type of the record's payload
- All Implemented Interfaces:
org.jeasy.batch.core.mapper.RecordMapper<java.lang.String,P>,org.jeasy.batch.core.processor.RecordProcessor<java.lang.String,P>
public class DelimitedRecordMapper<P> extends org.jeasy.batch.core.mapper.AbstractRecordMapper<P> implements org.jeasy.batch.core.mapper.RecordMapper<java.lang.String,P>DSV to Object mapper implementation. This implementation does not support advanced features like detecting delimiters inside quotes or deep mapping, please consider using another Mapper likeApacheCommonCsvRecordMapper,OpenCsvRecordMapperorUnivocityCsvRecordMapper.- Author:
- Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_DELIMITERstatic java.lang.StringDEFAULT_QUALIFIERstatic booleanDEFAULT_WHITESPACE_TRIMMING
-
Constructor Summary
Constructors Constructor Description DelimitedRecordMapper(java.lang.Class<P> recordClass)Create a newDelimitedRecordMapper.DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.Integer... fieldsPositions)Create a newDelimitedRecordMapper.DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.Integer[] fieldsPositions, java.lang.String[] fieldNames)Create a newDelimitedRecordMapper.DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.Integer[] fieldsPositions, java.lang.String[] fieldNames, int recordExpectedLength)Create a newDelimitedRecordMapper.DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.String... fieldNames)Create a newDelimitedRecordMapper.DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.String[] fieldNames, int recordExpectedLength)Create a newDelimitedRecordMapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.List<org.jeasy.batch.flatfile.Field>parseRecord(org.jeasy.batch.core.record.Record<java.lang.String> record)org.jeasy.batch.core.record.Record<P>processRecord(org.jeasy.batch.core.record.Record<java.lang.String> record)voidsetDelimiter(java.lang.String delimiter)Set the delimiter to use.voidsetQualifier(java.lang.String qualifier)Set the data qualifier to use.voidsetTrimWhitespaces(boolean trimWhitespaces)Trim white spaces when parsing the DSV record.
-
-
-
Field Detail
-
DEFAULT_DELIMITER
public static final java.lang.String DEFAULT_DELIMITER
- See Also:
- Constant Field Values
-
DEFAULT_QUALIFIER
public static final java.lang.String DEFAULT_QUALIFIER
- See Also:
- Constant Field Values
-
DEFAULT_WHITESPACE_TRIMMING
public static final boolean DEFAULT_WHITESPACE_TRIMMING
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DelimitedRecordMapper
public DelimitedRecordMapper(java.lang.Class<P> recordClass)
Create a newDelimitedRecordMapper. Column names and expected record size will be calculated from the header record. and set to fields with the same name of the target object.- Parameters:
recordClass- the target domain object class
-
DelimitedRecordMapper
public DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.String... fieldNames)
Create a newDelimitedRecordMapper. Expected record size will be calculated from the header record.- Parameters:
recordClass- the target domain object classfieldNames- a String array containing target type field names in the same order as in the delimited flat file.
-
DelimitedRecordMapper
public DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.String[] fieldNames, int recordExpectedLength)
Create a newDelimitedRecordMapper.- Parameters:
recordClass- the target domain object classfieldNames- a String array containing target type field names in the same order as in the delimited flat file.recordExpectedLength- record expected length
-
DelimitedRecordMapper
public DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.Integer... fieldsPositions)
Create a newDelimitedRecordMapper. Expected record size will be calculated from the header record.- Parameters:
recordClass- the target domain object classfieldsPositions- array of indexes of fields to retain
-
DelimitedRecordMapper
public DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.Integer[] fieldsPositions, java.lang.String[] fieldNames)
Create a newDelimitedRecordMapper. Expected record size will be calculated from the header record.- Parameters:
recordClass- the target domain object classfieldsPositions- array of indexes of fields to retainfieldNames- a String array representing fields name in the same order in the DSV flat file.
-
DelimitedRecordMapper
public DelimitedRecordMapper(java.lang.Class<P> recordClass, java.lang.Integer[] fieldsPositions, java.lang.String[] fieldNames, int recordExpectedLength)
Create a newDelimitedRecordMapper.- Parameters:
recordClass- the target domain object classfieldsPositions- array of indexes of fields to retainfieldNames- a String array representing fields name in the same order in the DSV flat file.recordExpectedLength- record expected length
-
-
Method Detail
-
processRecord
public org.jeasy.batch.core.record.Record<P> processRecord(org.jeasy.batch.core.record.Record<java.lang.String> record) throws java.lang.Exception
- Specified by:
processRecordin interfaceorg.jeasy.batch.core.processor.RecordProcessor<java.lang.String,P>- Throws:
java.lang.Exception
-
parseRecord
protected java.util.List<org.jeasy.batch.flatfile.Field> parseRecord(org.jeasy.batch.core.record.Record<java.lang.String> record) throws java.lang.Exception- Throws:
java.lang.Exception
-
setDelimiter
public void setDelimiter(java.lang.String delimiter)
Set the delimiter to use.- Parameters:
delimiter- the delimiter to use
-
setTrimWhitespaces
public void setTrimWhitespaces(boolean trimWhitespaces)
Trim white spaces when parsing the DSV record.- Parameters:
trimWhitespaces- true if whitespaces should be trimmed
-
setQualifier
public void setQualifier(java.lang.String qualifier)
Set the data qualifier to use.- Parameters:
qualifier- the data qualifier to use.
-
-