org.springframework.batch.item.file
Class FlatFileItemReader<T>

java.lang.Object
  extended by org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
      extended by org.springframework.batch.item.file.FlatFileItemReader<T>
All Implemented Interfaces:
ResourceAwareItemReaderItemStream<T>, ItemReader<T>, ItemStream, ItemStreamReader<T>, InitializingBean

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

Restartable ItemReader that reads lines from input setResource(Resource). Line is defined by the setRecordSeparatorPolicy(RecordSeparatorPolicy) and mapped to item using setLineMapper(LineMapper).

Author:
Robert Kasanicky

Field Summary
static String DEFAULT_CHARSET
           
 
Constructor Summary
FlatFileItemReader()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  void doClose()
          Close the resources opened in AbstractItemCountingItemStreamItemReader.doOpen().
protected  void doOpen()
          Open resources necessary to start reading input.
protected  T doRead()
          Read next item from input.
 void setComments(String[] comments)
          Setter for comment prefixes.
 void setEncoding(String encoding)
          Setter for the encoding for this input source.
 void setLineMapper(LineMapper<T> lineMapper)
          Setter for line mapper.
 void setLinesToSkip(int linesToSkip)
          Public setter for the number of lines to skip at the start of a file.
 void setRecordSeparatorPolicy(RecordSeparatorPolicy recordSeparatorPolicy)
          Public setter for the recordSeparatorPolicy.
 void setResource(Resource resource)
          Public setter for the input resource.
 void setSkippedLinesCallback(LineCallbackHandler skippedLinesCallback)
           
 void setStrict(boolean strict)
          In strict mode the reader will throw an exception on AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext) if the input resource does not exist.
 
Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, jumpToItem, 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
 

Field Detail

DEFAULT_CHARSET

public static final String DEFAULT_CHARSET
Constructor Detail

FlatFileItemReader

public FlatFileItemReader()
Method Detail

setStrict

public void setStrict(boolean strict)
In strict mode the reader will throw an exception on AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext) if the input resource does not exist.

Parameters:
strict - false by default

setSkippedLinesCallback

public void setSkippedLinesCallback(LineCallbackHandler skippedLinesCallback)
Parameters:
skippedLinesCallback - will be called for each one of the initial skipped lines before any items are read.

setLinesToSkip

public void setLinesToSkip(int linesToSkip)
Public setter for the number of lines to skip at the start of a file. Can be used if the file contains a header without useful (column name) information, and without a comment delimiter at the beginning of the lines.

Parameters:
linesToSkip - the number of lines to skip

setLineMapper

public void setLineMapper(LineMapper<T> lineMapper)
Setter for line mapper. This property is required to be set.

Parameters:
lineMapper - maps line to item

setEncoding

public void setEncoding(String encoding)
Setter for the encoding for this input source. Default value is DEFAULT_CHARSET.

Parameters:
encoding - a properties object which possibly contains the encoding for this input file;

setComments

public void setComments(String[] comments)
Setter for comment prefixes. Can be used to ignore header lines as well by using e.g. the first couple of column names as a prefix.

Parameters:
comments - an array of comment line prefixes.

setResource

public void setResource(Resource resource)
Public setter for the input resource.

Specified by:
setResource in interface ResourceAwareItemReaderItemStream<T>

setRecordSeparatorPolicy

public void setRecordSeparatorPolicy(RecordSeparatorPolicy recordSeparatorPolicy)
Public setter for the recordSeparatorPolicy. Used to determine where the line endings are and do things like continue over a line ending if inside a quoted string.

Parameters:
recordSeparatorPolicy - the recordSeparatorPolicy to set

doRead

protected T doRead()
            throws Exception
Description copied from class: AbstractItemCountingItemStreamItemReader
Read next item from input.

Specified by:
doRead in class AbstractItemCountingItemStreamItemReader<T>
Returns:
string corresponding to logical record according to setRecordSeparatorPolicy(RecordSeparatorPolicy) (might span multiple lines in file).
Throws:
Exception

doClose

protected void doClose()
                throws Exception
Description copied from class: AbstractItemCountingItemStreamItemReader
Close the resources opened in AbstractItemCountingItemStreamItemReader.doOpen().

Specified by:
doClose in class AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception

doOpen

protected void doOpen()
               throws Exception
Description copied from class: AbstractItemCountingItemStreamItemReader
Open resources necessary to start reading input.

Specified by:
doOpen in class AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception

afterPropertiesSet

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


Copyright © 2009 SpringSource. All Rights Reserved.