net.sf.jsefa.common.lowlevel.io
Class LineSegmentReader

java.lang.Object
  extended by net.sf.jsefa.common.lowlevel.io.LineSegmentReader

public class LineSegmentReader
extends Object

A reader for reading LineSegments from a stream.

Author:
Norman Lahme-Huetig

Constructor Summary
LineSegmentReader(Reader reader)
          Constructs a new LineSegmentReader.
LineSegmentReader(Reader reader, int bufferSize, int minBufferFilling, int bufferEnlargement)
          Constructs a new LineSegmentReader.
 
Method Summary
 void close()
          Closes the stream.
 InputPosition getInputPosition()
          Returns information about the current position within the input stream.
 void mark()
          Marks the current position in the stream so that calling reset(boolean) will return to this position.
 LineSegment read()
          Reads a LineSegment from the stream.
 LineSegment read(int limit)
          Reads a LineSegment from the stream with an upper bound for the length of its content.
 LineSegment read(int specialTerminator, int limit)
          Reads a LineSegment from the stream.
 void removeMarker()
          Removes the marker.
 void reset(boolean removeMarker)
          Moves back to the position marked with mark() before.
 void skipLine()
          Skips the current line, i. e. moves to the character after the next line break.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineSegmentReader

public LineSegmentReader(Reader reader)
Constructs a new LineSegmentReader.

Parameters:
reader - the reader to access the stream with

LineSegmentReader

public LineSegmentReader(Reader reader,
                         int bufferSize,
                         int minBufferFilling,
                         int bufferEnlargement)
Constructs a new LineSegmentReader.

Parameters:
reader - the reader to access the stream with
bufferSize - the initial size of the character buffer
minBufferFilling - the minimum number of characters to fill the buffer with. Only relevant when a mark is set.
bufferEnlargement - the number of characters to enlarge the buffer if it gets too small. Only relevant when a mark is set.
Method Detail

read

public LineSegment read()
                 throws IOException
Reads a LineSegment from the stream.

The segment is terminated either with a line break or end of stream.

Returns:
a LineSegment or null if there are no characters left on the stream
Throws:
IOException - if an I/O error occurs

read

public LineSegment read(int limit)
                 throws IOException
Reads a LineSegment from the stream with an upper bound for the length of its content.

The segment is either terminated (with a line break or end of stream) or not (if the limit is reached).

Parameters:
limit - the upper bound for the size of the LineSegment (length of its content).
Returns:
a LineSegment or null if there are no characters left on the stream
Throws:
IOException - if an I/O error occurs

read

public LineSegment read(int specialTerminator,
                        int limit)
                 throws IOException
Reads a LineSegment from the stream.

Parameters:
specialTerminator - the character to use as a special terminator for the LineSegement or -1, if only the standard terminators shall be used.
limit - the upper bound for the size of the LineSegment (length of its content).
Returns:
a LineSegment or null if there are no characters left on the stream
Throws:
IOException - if an I/O error occurs

skipLine

public void skipLine()
              throws IOException
Skips the current line, i. e. moves to the character after the next line break.

Throws:
IOException - if an I/O error occurs

getInputPosition

public InputPosition getInputPosition()
Returns information about the current position within the input stream.

Returns:
the input position

mark

public void mark()
Marks the current position in the stream so that calling reset(boolean) will return to this position.

Note: You should remove the marker with removeMarker() if you do not need it any more.


reset

public void reset(boolean removeMarker)
Moves back to the position marked with mark() before.

Parameters:
removeMarker - true, if the marker should be removed afterwards

removeMarker

public void removeMarker()
Removes the marker.


close

public void close()
           throws IOException
Closes the stream.

Throws:
IOException - if an I/O error occurs


Copyright © 2014. All rights reserved.