类 FlatFileItemReader<T>
- java.lang.Object
- org.springframework.batch.item.ItemStreamSupport
- org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
- org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
- org.springframework.batch.item.file.FlatFileItemReader<T>
- 所有已实现的接口:
ResourceAwareItemReaderItemStream<T>
,ItemReader<T>
,ItemStream
,ItemStreamReader<T>
,org.springframework.beans.factory.InitializingBean
public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements ResourceAwareItemReaderItemStream<T>, org.springframework.beans.factory.InitializingBean
RestartableItemReader
that reads lines from inputsetResource(Resource)
. Line is defined by thesetRecordSeparatorPolicy(RecordSeparatorPolicy)
and mapped to item usingsetLineMapper(LineMapper)
. If an exception is thrown during line mapping it is rethrown asFlatFileParseException
adding information about the problematic line and its line number.- 作者:
- Robert Kasanicky, Mahmoud Ben Hassine
字段概要
字段 修饰符和类型 字段 说明 static java.lang.String
DEFAULT_CHARSET
static java.lang.String[]
DEFAULT_COMMENT_PREFIXES
构造器概要
构造器 构造器 说明 FlatFileItemReader()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
protected void
doClose()
Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen()
.protected void
doOpen()
Open resources necessary to start reading input.protected T
doRead()
Read next item from input.protected void
jumpToItem(int itemIndex)
Move to the given item index.void
setBufferedReaderFactory(BufferedReaderFactory bufferedReaderFactory)
Factory for theBufferedReader
that will be used to extract lines from the file.void
setComments(java.lang.String[] comments)
Setter for comment prefixes.void
setEncoding(java.lang.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(org.springframework.core.io.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 onAbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)
if the input resource does not exist.从类继承的方法 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.batch.item.ItemReader
read
从接口继承的方法 org.springframework.batch.item.ItemStream
close, open, update
字段详细资料
DEFAULT_CHARSET
public static final java.lang.String DEFAULT_CHARSET
DEFAULT_COMMENT_PREFIXES
public static final java.lang.String[] DEFAULT_COMMENT_PREFIXES
构造器详细资料
FlatFileItemReader
public FlatFileItemReader()
方法详细资料
setStrict
public void setStrict(boolean strict)
In strict mode the reader will throw an exception onAbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)
if the input resource does not exist.- 参数:
strict
-true
by default
setSkippedLinesCallback
public void setSkippedLinesCallback(LineCallbackHandler skippedLinesCallback)
- 参数:
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.- 参数:
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.- 参数:
lineMapper
- maps line to item
setEncoding
public void setEncoding(java.lang.String encoding)
Setter for the encoding for this input source. Default value isDEFAULT_CHARSET
.- 参数:
encoding
- a properties object which possibly contains the encoding for this input file;
setBufferedReaderFactory
public void setBufferedReaderFactory(BufferedReaderFactory bufferedReaderFactory)
Factory for theBufferedReader
that will be used to extract lines from the file. The default is fine for plain text files, but this is a useful strategy for binary files where the standard BufferedReader from java.io is limiting.- 参数:
bufferedReaderFactory
- the bufferedReaderFactory to set
setComments
public void setComments(java.lang.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. Defaults toDEFAULT_COMMENT_PREFIXES
.- 参数:
comments
- an array of comment line prefixes.
setResource
public void setResource(org.springframework.core.io.Resource resource)
Public setter for the input resource.- 指定者:
setResource
在接口中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.- 参数:
recordSeparatorPolicy
- the recordSeparatorPolicy to set
doRead
protected T doRead() throws java.lang.Exception
Read next item from input.- 指定者:
doRead
在类中AbstractItemCountingItemStreamItemReader<T>
- 返回:
- string corresponding to logical record according to
setRecordSeparatorPolicy(RecordSeparatorPolicy)
(might span multiple lines in file). - 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doClose
protected void doClose() throws java.lang.Exception
Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen()
.- 指定者:
doClose
在类中AbstractItemCountingItemStreamItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doOpen
protected void doOpen() throws java.lang.Exception
Open resources necessary to start reading input.- 指定者:
doOpen
在类中AbstractItemCountingItemStreamItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 抛出:
java.lang.Exception
jumpToItem
protected void jumpToItem(int itemIndex) throws java.lang.Exception
Move to the given item index. Subclasses should override this method if there is a more efficient way of moving to given index than re-reading the input usingAbstractItemCountingItemStreamItemReader.doRead()
.- 覆盖:
jumpToItem
在类中AbstractItemCountingItemStreamItemReader<T>
- 参数:
itemIndex
- index of item (0 based) to jump to.- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework