Class 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 like ApacheCommonCsvRecordMapper, OpenCsvRecordMapper or UnivocityCsvRecordMapper.
    Author:
    Mahmoud Ben Hassine ([email protected])
    • 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 new DelimitedRecordMapper. 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 new DelimitedRecordMapper. Expected record size will be calculated from the header record.
        Parameters:
        recordClass - the target domain object class
        fieldNames - 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 new DelimitedRecordMapper.
        Parameters:
        recordClass - the target domain object class
        fieldNames - 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 new DelimitedRecordMapper. Expected record size will be calculated from the header record.
        Parameters:
        recordClass - the target domain object class
        fieldsPositions - 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 new DelimitedRecordMapper. Expected record size will be calculated from the header record.
        Parameters:
        recordClass - the target domain object class
        fieldsPositions - array of indexes of fields to retain
        fieldNames - 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 new DelimitedRecordMapper.
        Parameters:
        recordClass - the target domain object class
        fieldsPositions - array of indexes of fields to retain
        fieldNames - 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:
        processRecord in interface org.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.