BeanIO 2.0.4

org.beanio.spring
Class BeanIOFlatFileItemReader<T>

java.lang.Object
  extended by org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
      extended by org.beanio.spring.BeanIOFlatFileItemReader<T>
Type Parameters:
T - Class type read from the file
All Implemented Interfaces:
ResourceAwareItemReaderItemStream<T>, ItemReader<T>, ItemStream, ItemStreamReader<T>, InitializingBean

public class BeanIOFlatFileItemReader<T>
extends AbstractItemCountingItemStreamItemReader<T>
implements ResourceAwareItemReaderItemStream<T>, InitializingBean

A Spring Batch item reader that uses a BeanIO stream mapping file to read items from a flat file. Restart capabilities are fully supported.

This implementation requires Spring 2.5 or greater, and Spring Batch 2.1.x.

Since:
1.2
Author:
Kevin Seim

Constructor Summary
BeanIOFlatFileItemReader()
          Constructs a new BeanIOFlatFileItemReader.
 
Method Summary
 void afterPropertiesSet()
           
protected  void doClose()
           
protected  void doOpen()
           
protected  T doRead()
           
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.
 
Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, getExecutionContextUserSupport, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setName, setSaveState, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.batch.item.ItemStream
close, open, update
 
Methods inherited from interface org.springframework.batch.item.ItemReader
read
 

Constructor Detail

BeanIOFlatFileItemReader

public BeanIOFlatFileItemReader()
Constructs a new BeanIOFlatFileItemReader.

Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

doRead

protected T doRead()
            throws Exception
Specified by:
doRead in class AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception

doOpen

protected void doOpen()
               throws Exception
Specified by:
doOpen in class AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception

doClose

protected void doClose()
                throws Exception
Specified by:
doClose in class AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception

jumpToItem

protected void jumpToItem(int itemIndex)
                   throws Exception
Overrides:
jumpToItem in class AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception

initializeStreamFactory

protected void initializeStreamFactory()
                                throws Exception
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.

Throws:
IllegalStateException - if the configured stream name is not found in the StreamFactory after loading the stream mapping
Exception

setResource

public void setResource(Resource resource)
Specified by:
setResource in interface ResourceAwareItemReaderItemStream<T>

setStrict

public void setStrict(boolean strict)
In strict mode this reader will throw an exception if the input resource does not exist when opened. Defaults to true.

Parameters:
strict - set to false to disable resource validation

setStreamFactory

public void setStreamFactory(StreamFactory streamFactory)
Sets the StreamFactory for loading stream mapping configurations. If not set, a new default StreamFactory is created.

Parameters:
streamFactory - the StreamFactory to use for loading stream mapping configurations

setStreamMapping

public void setStreamMapping(Resource streamMapping)
Sets the mapping file resource. A mapping file is required if a stream factory is not set.

Parameters:
streamMapping - the stream mapping resource

setStreamName

public void setStreamName(String streamName)
Sets the mapping configuration's stream name for reading this input stream.

Parameters:
streamName - the stream name

setEncoding

public void setEncoding(String encoding)
Sets the input stream encoding. If not set, the default system charset is used to read the input stream.

Parameters:
encoding - input stream encoding

setUseSpringExceptions

public void setUseSpringExceptions(boolean useSpringExceptions)
Set to true to force AbstractItemCountingItemStreamItemReader.read() to wrap BeanIO exceptions to their closest Spring-batch counterpart. Defaults to false.

Parameters:
useSpringExceptions - set to true to map BeanIO exceptions to their Spring-batch counterpart

setErrorHandler

public void setErrorHandler(BeanReaderErrorHandler errorHandler)
Sets the BeanIO error handler for handling BeanIO specific exceptions. If no error handler is set, the AbstractItemCountingItemStreamItemReader.read() method will throw the exception directly.

Parameters:
errorHandler - the BeanReaderErrorHandler for handling exceptions

setLocale

public void setLocale(String locale)
Sets the locale for resolving error messages from a stream mapping's configured resource bundle. By default, the system default locale is used.

Parameters:
locale - the locale for resolving error messages

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim