- java.lang.Object
-
- org.fissore.jrecordbind.Unmarshaller<E>
-
public class Unmarshaller<E> extends Object
Transforms an input reader into beans. You can consume the transformed beans by callingunmarshallToIterator(Reader)which returns an Iterator, or by callingunmarshallToStream(Reader), which returns a Stream.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,Converter>convertersprotected RecordDefinitiondefinitionprotected Map<String,Padder>paddersprotected org.fissore.jrecordbind.PropertyUtilspropertyUtils
-
Constructor Summary
Constructors Constructor Description Unmarshaller(RecordDefinition definition)Creates a new Unmarshaller, with the specified record definition and using the defaultLineReaderimplementationUnmarshaller(RecordDefinition definition, LineReader lineReader)Creates a new Unmarshaller, with the specified record definition and using the specifiedLineReaderimplementationUnmarshaller(RecordDefinition definition, LineReader lineReader, Map<String,Converter> converters, Map<String,Padder> padders)Creates a new Unmarshaller, with the specified record definition and using the specifiedLineReaderimplementation, and with user provided instances of converters and padders.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ConvertergetConverter(RecordDefinition.Property property)Gets the converter for the specified property or an instance ofStringConverterStringgetCurrentJunk()Returns the current internal buffer content.protected PaddergetPadder(RecordDefinition currentDefinition, RecordDefinition.Property property)Gets the padder for the specified property or the default one specified by the record definitionIterator<E>unmarshallToIterator(Reader input)Unmarshalls the input fixed-length file, a bean at a timeStream<E>unmarshallToStream(Reader input)LikeunmarshallToIterator(Reader), but returns a Stream instead of an Iterator
-
-
-
Constructor Detail
-
Unmarshaller
public Unmarshaller(RecordDefinition definition)
Creates a new Unmarshaller, with the specified record definition and using the defaultLineReaderimplementation- Parameters:
definition- the record definition
-
Unmarshaller
public Unmarshaller(RecordDefinition definition, LineReader lineReader)
Creates a new Unmarshaller, with the specified record definition and using the specifiedLineReaderimplementation- Parameters:
definition- the record definitionlineReader- a custom implementation of the LineReader
-
Unmarshaller
public Unmarshaller(RecordDefinition definition, LineReader lineReader, Map<String,Converter> converters, Map<String,Padder> padders)
Creates a new Unmarshaller, with the specified record definition and using the specifiedLineReaderimplementation, and with user provided instances of converters and padders.- Parameters:
definition- the record definitionlineReader- a custom implementation of the LineReaderconverters- user provided instances of converterspadders- user provided instances of padders
-
-
Method Detail
-
getCurrentJunk
public String getCurrentJunk()
Returns the current internal buffer content. If called right after aIterator.next()call, it will return what JRecordBind wasn't able to unmarshall. Usually called after theIterator.hasNext()has returnedfalseto report the user about the "junk" found in the text file- Returns:
- the current "junk" stored in the internal buffer
-
unmarshallToIterator
public Iterator<E> unmarshallToIterator(Reader input)
Unmarshalls the input fixed-length file, a bean at a time- Parameters:
input- the input fixed-length file- Returns:
- an Iterator: each next() call will give back the next bean
-
unmarshallToStream
public Stream<E> unmarshallToStream(Reader input)
LikeunmarshallToIterator(Reader), but returns a Stream instead of an Iterator- Parameters:
input- the input fixed-length file- Returns:
- a stream of beans
-
getPadder
protected Padder getPadder(RecordDefinition currentDefinition, RecordDefinition.Property property)
Gets the padder for the specified property or the default one specified by the record definition- Parameters:
currentDefinition- the record definitionproperty- the property- Returns:
- a padder instance
-
getConverter
protected Converter getConverter(RecordDefinition.Property property)
Gets the converter for the specified property or an instance ofStringConverter- Parameters:
property- the property- Returns:
- a converter instance
-
-