Package repast.simphony.util
Class Scanner
java.lang.Object
repast.simphony.util.Scanner
- Direct Known Subclasses:
RandomAccessScanner
A class that will take in an a Readable object and will perform scanning functions on it. This
provides the ability to grab a String of characters up to a delimiter, following a pattern, or a
certain length.
This is somewhat a replacement for java's built in
This is somewhat a replacement for java's built in
Scanner
class, but isn't
final and provides some extra methods, while excluding the next[data type] type methods.- Author:
- Jerry Vos
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionScanner
(ReadableByteChannel channel) Scanner
(ReadableByteChannel channel, String charset) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
buffer()
protected void
Returns the delimiter pattern used fornext()
andgetNextDelimited()
.Fetches the next String of characters up to the current delimiter.getNextLength
(int length) Retrieves the next n characters from the stream, where n is the specified length.getNextPattern
(String pattern) Retrieves a sequence of characters that matches the specified pattern.protected void
boolean
hasNext()
Returns true if there are some characters left to be returned, otherwise false.Returns the last IOException that occurred.next()
Same asgetNextDelimited()
.void
remove()
Currently unsupported.useDelimiter
(String delimiter) Sets the delimiter pattern used fornext()
andgetNextDelimited()
.useDelimiter
(Pattern delimiterPattern) Sets the delimiter pattern used fornext()
andgetNextDelimited()
.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 Details
-
BUF_SIZE
public static final int BUF_SIZE- See Also:
-
buf
-
eof
protected boolean eof -
source
-
-
Constructor Details
-
Scanner
-
Scanner
-
Scanner
-
Scanner
-
-
Method Details
-
buffer
protected void buffer() -
handleIOException
-
bufferMore
protected void bufferMore() -
hasNext
public boolean hasNext()Returns true if there are some characters left to be returned, otherwise false. -
next
Same asgetNextDelimited()
. -
getNextDelimited
Fetches the next String of characters up to the current delimiter. If the end of the buffer is reached while trying to find the delimiter, the String of characters from the current position to the end of the stream will be returned. If we're at the end of the stream a NoSuchElementException will be thrown.- Returns:
- the next String of characters up to the delimiter or end of the stream, whichever comes first
- See Also:
-
getNextPattern
Retrieves a sequence of characters that matches the specified pattern. This sequence must begin with the next character in the stream. If the pattern isn't matched (or isn't matched including the first character) an InputMismatchException will be thrown.- Parameters:
pattern
- the pattern to fetch based off of- Returns:
- a String that matches the specified pattern
- See Also:
-
getNextLength
Retrieves the next n characters from the stream, where n is the specified length. If there are not enough characters left an exception will be thrown.- Parameters:
length
- how many characters to fetch- Returns:
- a string of the specified number of characters
- See Also:
-
useDelimiter
Sets the delimiter pattern used fornext()
andgetNextDelimited()
. This is a regular expression and will be converted to a Pattern.- Returns:
- the previous delimiter pattern
- See Also:
-
useDelimiter
Sets the delimiter pattern used fornext()
andgetNextDelimited()
.- Returns:
- the previous delimiter pattern
-
delimiter
Returns the delimiter pattern used fornext()
andgetNextDelimited()
.- Returns:
- the current delimiter pattern
- See Also:
-
remove
public void remove()Currently unsupported. Throws anUnsupportedOperationException
. -
ioException
Returns the last IOException that occurred.- Returns:
- the last IOException that occurred
-