|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.batch.item.support.AbstractBufferedItemReaderItemStream org.springframework.batch.item.file.FlatFileItemReader
public class FlatFileItemReader
This class represents a ItemReader
, that reads lines from text file,
tokenizes them to structured tuples (FieldSet
s) instances and maps
the FieldSet
s to domain objects. The location of the file is defined
by the resource property. To separate the structure of the file,
LineTokenizer
is used to parse data obtained from the file.
A FlatFileItemReader
is not thread safe because it maintains state in
the form of a ResourceLineReader
. Be careful to configure a
FlatFileItemReader
using an appropriate factory or scope so that it
is not shared between threads.
This class supports restart, skipping invalid lines and storing statistics.
It can be configured to setup FieldSet
column names from the file
header, skip given number of lines at the beginning of the file.
Field Summary | |
---|---|
static String |
DEFAULT_CHARSET
|
Constructor Summary | |
---|---|
FlatFileItemReader()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
protected void |
doClose()
Close the resources opened in AbstractBufferedItemReaderItemStream.doOpen() . |
protected void |
doOpen()
Open resources necessary to start reading input. |
protected Object |
doRead()
Reads a line from input, tokenizes is it using the setLineTokenizer(LineTokenizer) and maps to domain object using
setFieldSetMapper(FieldSetMapper) . |
protected LineReader |
getReader()
|
void |
setComments(String[] comments)
Setter for comment prefixes. |
void |
setEncoding(String encoding)
Setter for the encoding for this input source. |
void |
setFieldSetMapper(FieldSetMapper fieldSetMapper)
Set the FieldSetMapper to be used for each line. |
void |
setFirstLineIsHeader(boolean firstLineIsHeader)
Indicates whether first line is a header. |
void |
setLinesToSkip(int linesToSkip)
Public setter for the number of lines to skip at the start of a file. |
void |
setLineTokenizer(LineTokenizer lineTokenizer)
|
void |
setRecordSeparatorPolicy(RecordSeparatorPolicy recordSeparatorPolicy)
Public setter for the recordSeparatorPolicy. |
void |
setResource(Resource resource)
Setter for resource property. |
Methods inherited from class org.springframework.batch.item.support.AbstractBufferedItemReaderItemStream |
---|
close, getCurrentItemCount, jumpToItem, mark, open, read, reset, setCurrentItemCount, 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.ItemReader |
---|
mark, read, reset |
Methods inherited from interface org.springframework.batch.item.ItemStream |
---|
close, open, update |
Field Detail |
---|
public static final String DEFAULT_CHARSET
Constructor Detail |
---|
public FlatFileItemReader()
Method Detail |
---|
protected LineReader getReader()
public void setResource(Resource resource)
setResource
in interface ResourceAwareItemReaderItemStream
resource
- public void setRecordSeparatorPolicy(RecordSeparatorPolicy recordSeparatorPolicy)
recordSeparatorPolicy
- the recordSeparatorPolicy to setpublic void setComments(String[] comments)
comments
- an array of comment line prefixes.public void setFirstLineIsHeader(boolean firstLineIsHeader)
AbstractLineTokenizer
and the column names haven't been set
already then the header will be used to setup column names. Default is
false
.
public void setLineTokenizer(LineTokenizer lineTokenizer)
lineTokenizer
- tokenizes each line from file into FieldSet
.public void setFieldSetMapper(FieldSetMapper fieldSetMapper)
fieldSetMapper
- public void setLinesToSkip(int linesToSkip)
linesToSkip
- the number of lines to skippublic void setEncoding(String encoding)
DEFAULT_CHARSET
.
encoding
- a properties object which possibly contains the encoding
for this input file;public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
protected void doClose() throws Exception
AbstractBufferedItemReaderItemStream
AbstractBufferedItemReaderItemStream.doOpen()
.
doClose
in class AbstractBufferedItemReaderItemStream
Exception
protected void doOpen() throws Exception
AbstractBufferedItemReaderItemStream
doOpen
in class AbstractBufferedItemReaderItemStream
Exception
protected Object doRead() throws Exception
setLineTokenizer(LineTokenizer)
and maps to domain object using
setFieldSetMapper(FieldSetMapper)
.
doRead
in class AbstractBufferedItemReaderItemStream
Exception
ItemReader.read()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |