Package repast.simphony.util
Class RandomAccessScanner
- java.lang.Object
-
- repast.simphony.util.Scanner
-
- repast.simphony.util.RandomAccessScanner
-
public class RandomAccessScanner extends Scanner
This class adds random access capabilities to therepast.simphony.integration.Scanner
class. This contains a mark stack, meaning you can have multiple marks set at once, and jump back up them.- Version:
- $Revision$ $Date$
- Author:
- Jerry Vos
-
-
Field Summary
Fields Modifier and Type Field Description protected FileChannel
fileChannel
protected Stack<Long>
markStack
-
Constructor Summary
Constructors Constructor Description RandomAccessScanner(String source)
RandomAccessScanner(FileChannel channel)
RandomAccessScanner(FileChannel channel, String charset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
getBufferLength()
long
getPosition()
Returns the current position of the channel.void
mark()
Adds a mark to the mark stack.Long
popMark()
Removes a mark from the mark stack.void
position(long position)
Positions the stream to the specified location.void
reset()
Positions the stream to the position last marked.protected void
syncToSource()
-
Methods inherited from class repast.simphony.util.Scanner
buffer, bufferMore, delimiter, getNextDelimited, getNextLength, getNextPattern, handleIOException, hasNext, ioException, next, remove, useDelimiter, useDelimiter
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Field Detail
-
fileChannel
protected FileChannel fileChannel
-
-
Constructor Detail
-
RandomAccessScanner
public RandomAccessScanner(FileChannel channel, String charset)
-
RandomAccessScanner
public RandomAccessScanner(FileChannel channel)
-
RandomAccessScanner
public RandomAccessScanner(String source)
-
-
Method Detail
-
getPosition
public long getPosition() throws IOException
Returns the current position of the channel. This accounts for any buffered data, therefore it returns the true position the scanner is at, not just the position the channel is at.- Returns:
- the position the scanner is at in the channel's data.
- Throws:
IOException
-
getBufferLength
protected int getBufferLength()
-
syncToSource
protected void syncToSource()
-
mark
public void mark() throws IOException
Adds a mark to the mark stack.- Throws:
IOException
-
popMark
public Long popMark()
Removes a mark from the mark stack. This does not position the stream to the location of the pop'd mark.- Returns:
- the value of the mark
-
reset
public void reset() throws IOException
Positions the stream to the position last marked. This does not pop the mark off the mark stack.- Throws:
IOException
-
position
public void position(long position) throws IOException
Positions the stream to the specified location. This results in a clearing of the internal buffer and a refilling of it starting at the specified location.- Parameters:
position
- the position to put the stream at- Throws:
IOException
-
-