- 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>
converters
protected RecordDefinition
definition
protected Map<String,Padder>
padders
protected org.fissore.jrecordbind.PropertyUtils
propertyUtils
-
Constructor Summary
Constructors Constructor Description Unmarshaller(RecordDefinition definition)
Creates a new Unmarshaller, with the specified record definition and using the defaultLineReader
implementationUnmarshaller(RecordDefinition definition, LineReader lineReader)
Creates a new Unmarshaller, with the specified record definition and using the specifiedLineReader
implementationUnmarshaller(RecordDefinition definition, LineReader lineReader, Map<String,Converter> converters, Map<String,Padder> padders)
Creates a new Unmarshaller, with the specified record definition and using the specifiedLineReader
implementation, and with user provided instances of converters and padders.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Converter
getConverter(RecordDefinition.Property property)
Gets the converter for the specified property or an instance ofStringConverter
String
getCurrentJunk()
Returns the current internal buffer content.protected Padder
getPadder(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 defaultLineReader
implementation- Parameters:
definition
- the record definition
-
Unmarshaller
public Unmarshaller(RecordDefinition definition, LineReader lineReader)
Creates a new Unmarshaller, with the specified record definition and using the specifiedLineReader
implementation- 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 specifiedLineReader
implementation, 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 returnedfalse
to 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
-
-