T
- Class type read from the filepublic class BeanIOFlatFileItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements ResourceAwareItemReaderItemStream<T>, InitializingBean
This implementation requires Spring 2.5 or greater, and Spring Batch 2.1.x.
Constructor and Description |
---|
BeanIOFlatFileItemReader()
Constructs a new BeanIOFlatFileItemReader.
|
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected void |
doClose() |
protected void |
doOpen() |
protected T |
doRead() |
protected BeanReader |
getBeanReader()
Returns the underlying
BeanReader . |
int |
getLineNumber()
Returns the starting line number of the first record for the most recent bean
object read from this reader, or -1 when the end of the stream is reached.
|
RecordContext |
getRecordContext(int index)
Returns record information for the most recent bean object read from this reader.
|
int |
getRecordCount()
Returns the number of records read from the underlying input stream for the
most recent bean object read from this reader.
|
String |
getRecordName()
Returns the record or group name of the most recent bean object
read from this reader, or null if the end of the stream was reached.
|
protected void |
initializeStreamFactory()
Creates a
StreamFactory if one was not set, loads the stream
mapping resource if set, and validates the StreamFactory has a
mapping for the configured stream name. |
protected void |
jumpToItem(int itemIndex) |
void |
setEncoding(String encoding)
Sets the input stream encoding.
|
void |
setErrorHandler(BeanReaderErrorHandler errorHandler)
Sets the BeanIO error handler for handling BeanIO specific exceptions.
|
void |
setLocale(String locale)
Sets the locale for resolving error messages from a stream mapping's
configured resource bundle.
|
void |
setResource(Resource resource) |
void |
setStreamFactory(StreamFactory streamFactory)
Sets the
StreamFactory for loading stream mapping configurations. |
void |
setStreamMapping(Resource streamMapping)
Sets the mapping file resource.
|
void |
setStreamName(String streamName)
Sets the mapping configuration's stream name for reading this input
stream.
|
void |
setStrict(boolean strict)
In strict mode this reader will throw an exception if the input resource does
not exist when opened.
|
void |
setUseSpringExceptions(boolean useSpringExceptions)
Set to true to force
AbstractItemCountingItemStreamItemReader.read() to wrap BeanIO exceptions
to their closest Spring-batch counterpart. |
close, getCurrentItemCount, getExecutionContextUserSupport, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setName, setSaveState, update
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, open, update
read
public BeanIOFlatFileItemReader()
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
protected T doRead() throws Exception
doRead
in class AbstractItemCountingItemStreamItemReader<T>
Exception
protected void doOpen() throws Exception
doOpen
in class AbstractItemCountingItemStreamItemReader<T>
Exception
protected void doClose() throws Exception
doClose
in class AbstractItemCountingItemStreamItemReader<T>
Exception
protected void jumpToItem(int itemIndex) throws Exception
jumpToItem
in class AbstractItemCountingItemStreamItemReader<T>
Exception
protected void initializeStreamFactory() throws Exception
StreamFactory
if one was not set, loads the stream
mapping resource if set, and validates the StreamFactory has a
mapping for the configured stream name.IllegalStateException
- if the configured stream name is not found
in the StreamFactory after loading the stream mappingException
public String getRecordName()
public int getLineNumber()
public int getRecordCount()
public RecordContext getRecordContext(int index) throws IndexOutOfBoundsException
getRecordCount()
can be used
to determine how many records were read from the stream.index
- the index of the record, starting at 0RecordContext
, or null if the stream is closedIndexOutOfBoundsException
- if there is no record for the given indexgetRecordCount()
protected BeanReader getBeanReader()
BeanReader
.BeanReader
, or null if the stream is closedpublic void setResource(Resource resource)
setResource
in interface ResourceAwareItemReaderItemStream<T>
public void setStrict(boolean strict)
strict
- set to false to disable resource validationpublic void setStreamFactory(StreamFactory streamFactory)
StreamFactory
for loading stream mapping configurations. If not set,
a new default StreamFactory is created.streamFactory
- the StreamFactory to use for loading stream
mapping configurationspublic void setStreamMapping(Resource streamMapping)
streamMapping
- the stream mapping resourcepublic void setStreamName(String streamName)
streamName
- the stream namepublic void setEncoding(String encoding)
encoding
- input stream encodingpublic void setUseSpringExceptions(boolean useSpringExceptions)
AbstractItemCountingItemStreamItemReader.read()
to wrap BeanIO exceptions
to their closest Spring-batch counterpart. Defaults to false.
useSpringExceptions
- set to true to map BeanIO exceptions
to their Spring-batch counterpartpublic void setErrorHandler(BeanReaderErrorHandler errorHandler)
AbstractItemCountingItemStreamItemReader.read()
method will throw the exception
directly.errorHandler
- the BeanReaderErrorHandler
for handling exceptionspublic void setLocale(String locale)
locale
- the locale for resolving error messages