Package org.jeasy.batch.flatfile
Class FixedLengthRecordMarshaller<P>
- java.lang.Object
-
- org.jeasy.batch.flatfile.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 usingString.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 (mahmoud.benhassine@icloud.com)
-
-
Constructor Summary
Constructors Constructor Description FixedLengthRecordMarshaller(java.lang.Class<P> type, java.lang.String format, java.lang.String... fields)Create a newFixedLengthRecordMarshaller.FixedLengthRecordMarshaller(org.jeasy.batch.core.field.FieldExtractor<P> fieldExtractor, java.lang.String format)Create a newFixedLengthRecordMarshaller.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.jeasy.batch.core.record.StringRecordprocessRecord(org.jeasy.batch.core.record.Record<P> record)voidsetLocale(java.util.Locale locale)Set the locale to use to format records.
-
-
-
Constructor Detail
-
FixedLengthRecordMarshaller
public FixedLengthRecordMarshaller(java.lang.Class<P> type, java.lang.String format, java.lang.String... fields)
Create a newFixedLengthRecordMarshaller. This constructor will create a field extractor of typeBeanFieldExtractor.- Parameters:
type- of object to marshalformat- to use (inFormattersyntax)fields- to marshal in the right order
-
FixedLengthRecordMarshaller
public FixedLengthRecordMarshaller(org.jeasy.batch.core.field.FieldExtractor<P> fieldExtractor, java.lang.String format)
Create a newFixedLengthRecordMarshaller.- Parameters:
fieldExtractor- to use to extract fieldsformat- to use (inFormattersyntax)
-
-
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:
processRecordin interfaceorg.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
-
-