|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.batch.item.file.separator.ResourceLineReader
public class ResourceLineReader
An input source that reads lines one by one from a resource.
A line can consist of multiple lines in the input resource, according to the RecordSeparatorPolicy
in force.
By default a line is either terminated by a newline (as per BufferedReader.readLine()
), or can be continued
onto the next line if a field surrounded by quotes (\") contains a newline.
Comment lines can be indicated using a line prefix (or collection of prefixes) and they will be ignored. The default
is "#", so lines starting with a pound sign will be ignored.
All the public methods that interact with the underlying resource (open, close, read etc.) are synchronized on this.
Package private because this is not intended to be a public API - used internally by the flat file input sources.
That makes abuses of the fact that it is stateful easier to control.
Constructor Summary | |
---|---|
ResourceLineReader(Resource resource)
|
|
ResourceLineReader(Resource resource,
String encoding)
|
Method Summary | |
---|---|
void |
close()
Close the reader associated with this input source. |
int |
getPosition()
Getter for current line count (not the current number of lines returned). |
void |
mark()
Mark the state for return later with reset. |
void |
open()
Creates internal state object. |
Object |
read()
Read the next line from the input resource, ignoring comments, and according to the RecordSeparatorPolicy . |
void |
reset()
Reset the reader to the last mark. |
void |
setComments(String[] comments)
Setter for comment prefixes. |
void |
setRecordSeparatorPolicy(RecordSeparatorPolicy recordSeparatorPolicy)
Setter for the RecordSeparatorPolicy . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ResourceLineReader(Resource resource) throws IOException
IOException
public ResourceLineReader(Resource resource, String encoding)
Method Detail |
---|
public void setRecordSeparatorPolicy(RecordSeparatorPolicy recordSeparatorPolicy)
RecordSeparatorPolicy
. Default value is a DefaultRecordSeparatorPolicy
. Ideally
should not be changed once a reader is in use, but it would not be fatal if it was.
recordSeparatorPolicy
- the new RecordSeparatorPolicy
public void setComments(String[] comments)
comments
- an array of comment line prefixes.public Object read()
RecordSeparatorPolicy
.
read
in interface ItemReader
ItemReader.read()
public void open()
open
in interface LineReader
public void close()
close
in interface LineReader
public int getPosition()
getPosition
in interface LineReader
public void mark() throws MarkFailedException
BufferedReader
,
which means that there is a limit to how much data can be recovered if the mark needs to be reset.ItemStream
is used in a single-threaded environment. The state backing
the mark is a single counter, keeping track of the current position, so multiple threads cannot be accommodated.
mark
in interface ItemReader
MarkFailedException
- if the mark could not be set.reset()
public void reset() throws ResetFailedException
reset
in interface ItemReader
ResetFailedException
- if the reset is unsuccessful, e.g. if the read-ahead limit was breached.mark()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |