Class FixedLengthRecordMarshaller<P>

  • Type Parameters:
    P - type of the record's payload
    All Implemented Interfaces:
    org.jeasy.batch.core.marshaller.RecordMarshaller<P,​java.lang.String>, org.jeasy.batch.core.processor.RecordProcessor<P,​java.lang.String>

    public class FixedLengthRecordMarshaller<P>
    extends java.lang.Object
    implements org.jeasy.batch.core.marshaller.RecordMarshaller<P,​java.lang.String>
    Marshals a POJO to fixed length format using String.format(Locale, String, Object...). This marshaller can be used to left/right pad fields with white spaces to a fixed length. However, it does NOT truncate data if a field value is longer than the specified field length.
    Author:
    Mahmoud Ben Hassine ([email protected])
    • Constructor Detail

      • FixedLengthRecordMarshaller

        public FixedLengthRecordMarshaller​(java.lang.Class<P> type,
                                           java.lang.String format,
                                           java.lang.String... fields)
        Create a new FixedLengthRecordMarshaller. This constructor will create a field extractor of type BeanFieldExtractor.
        Parameters:
        type - of object to marshal
        format - to use (in Formatter syntax)
        fields - to marshal in the right order
      • FixedLengthRecordMarshaller

        public FixedLengthRecordMarshaller​(org.jeasy.batch.core.field.FieldExtractor<P> fieldExtractor,
                                           java.lang.String format)
        Parameters:
        fieldExtractor - to use to extract fields
        format - to use (in Formatter syntax)
    • Method Detail

      • processRecord

        public org.jeasy.batch.core.record.StringRecord processRecord​(org.jeasy.batch.core.record.Record<P> record)
                                                               throws java.lang.Exception
        Specified by:
        processRecord in interface org.jeasy.batch.core.processor.RecordProcessor<P,​java.lang.String>
        Throws:
        java.lang.Exception
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Set the locale to use to format records.
        Parameters:
        locale - to use to format records