Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.util.Scanner
Constructor Summary | |
| |
| |
| |
|
Method Summary | |
@Override |
|
void |
|
Pattern |
|
String |
|
String |
|
String |
|
String |
|
boolean |
|
boolean |
|
boolean | |
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
IOException |
|
boolean |
|
Locale |
|
MatchResult |
|
String |
|
String | |
String | |
BigDecimal |
|
BigInteger |
|
BigInteger |
|
boolean |
|
byte |
|
byte |
|
double |
|
float |
|
int |
|
int |
|
String |
|
long |
|
long |
|
short |
|
short |
|
int |
|
void |
|
void |
|
Scanner | |
Scanner | |
Scanner |
|
Scanner |
|
Scanner | |
Scanner |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public Scanner(File source) throws FileNotFoundException
Constructs a new Scanner with the given File as source.Scanner(InputStream,String)
is called withnull
as charsetName.
- Parameters:
source
- The File to use as source.
- Throws:
FileNotFoundException
- If the file is not found an Exception is thrown.
public Scanner(File source, String charsetName) throws FileNotFoundException
Constructs a new Scanner with the given File as source.
Scanner(InputStream,String)
is called with the given charsetName.
- Parameters:
source
- The File to use as source.charsetName
- Current charset name of the file. If charsetName is null it behaves if it was not set.
- Throws:
FileNotFoundException
- If the file is not found an Exception is thrown.
public Scanner(InputStream source)
Constructs a new Scanner with the given inputStream.
Scanner(InputStream,String)
is called withnull
as charsetName.
- Parameters:
source
- The InputStream to use as source.
public Scanner(InputStream source, String charsetName)
Constructs a new Scanner with the InputSream and a charsetName. Afterwards the Buffer is filled.
- Parameters:
source
- The InputStream to use as source.charsetName
- The charsetName to apply on the source's data.
public Scanner(Readable source)
Constructs a new Scanner with a Readable input as source.
- Parameters:
source
- The Readable to use as source.
public Scanner(String source)
Constructs a new Scanner using the given String as input only.
- Parameters:
source
- The whole String to be used as source.
public Scanner(ReadableByteChannel source)
Constructs a new Scanner with a ReadableByteChannel as source. Therfore theScanner(ReadableByteChannel,String)
is called withnull
as charsetName.
- Parameters:
source
- The ReadableByteChannel to use as source.
public Scanner(ReadableByteChannel source, String charsetName)
Constructs a new Scanner with a ReadableByteChannel as source and a given charsetName, which is to be applied on it.
It also initiates the main Buffer.
- Parameters:
source
- The ReadableByteChannel to use as source.charsetName
- The charsetName to be applied on the source.
public @Override String toString()
Returns the string representation of this Scanner.
public void close()
Closes this Scanner. If anIOException
occurs it is catched and is available underioException()
.
After the Scanner is closed, all searches will lead to aIllegalStateException
.
public String findInLine(String pattern)
Compiles the given pattern into aPattern
and callsfindInLine(Pattern)
with the compiled pattern and returns whatever it returns.
- Parameters:
pattern
- The pattern which should be matched in the input.
- Returns:
- The match in the current line.
- Throws:
NoSuchElementException
- If the pattern was not found.
public String findInLine(Pattern pattern) throws NoSuchElementException
Tries to find the pattern in the current line.
- Parameters:
pattern
- The pattern which should be searched in the current line of the input.
- Returns:
- If the search was successful, the result or otherwise a
NoSuchElementException
is thrown.
- Throws:
NoSuchElementException
- If the pattern was not found.
public String findWithinHorizon(String pattern, int horizon) throws IllegalArgumentException, IllegalStateException
Compile the pattern and callfindWithinHorizon(Pattern,int)
.
- Parameters:
pattern
- Pattern to search.horizon
-
- Returns:
- The result of the match.
- Throws:
IllegalArgumentException
- if the horizon is negative.IllegalStateException
- if the Scanner is closed.
public String findWithinHorizon(Pattern pattern, int horizon) throws IllegalArgumentException, IllegalStateException
Trys to match the pattern within the given horizon.
- Parameters:
pattern
- Pattern to search.horizon
-
- Returns:
- The result of the match.
- Throws:
IllegalArgumentException
- if the horizon is negative.IllegalStateException
- if the Scanner is closed.
public boolean hasNext() throws IllegalStateException
Checks if there is any next String using the current delimiter. Therefore the string must not benull
and the length must be greater then 0. If aNoSuchElementException
is thrown by the search method, it is catched and false is returned.
- Specified by:
- hasNext in interface Iterator<E>
- Returns:
true
if there is any result using the current delimiter. This wouldn't lead to aNoSuchElementException
.
- Throws:
IllegalStateException
- if the Scanner is closed.
public boolean hasNext(String pattern) throws IllegalStateException
Compiles the pattern to aPattern
and callshasNext(Pattern)
.
- Parameters:
pattern
- The pattern as string to search for.
- Returns:
true
if the pattern is found before the current delimiter.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
hasNext(Pattern)
public boolean hasNext(Pattern pattern) throws IllegalStateException
Searches the pattern in the next subString before the next current delimiter.
- Parameters:
pattern
- The pattern to search for.
- Returns:
true
if the pattern is found before the current delimiter.
- Throws:
IllegalStateException
- if the Scanner is closed.
public boolean hasNextBigDecimal() throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a BigDecimal number.
BigDecimal numbers are always tryed with radix 10.
- Returns:
true
if the next string is a BigDecimal number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextBigDecimal()
public boolean hasNextBigInteger() throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a BigInteger number.
CallhasNextBigInteger(int)
with the current radix.
- Returns:
true
if the next string is a BigInteger number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextBigInteger()
public boolean hasNextBigInteger(int radix) throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a BigInteger number.
- Parameters:
radix
- The radix to use for this check. The global radix of the Scanner will not be changed.
- Returns:
true
if the next string is a BigInteger number.
- Throws:
IllegalStateException
- if the Scanner is closed.
public boolean hasNextBoolean() throws IllegalStateException
Checks if the next string could be a boolean. The method handles the input not case sensitiv, so "true" and "TRUE" and even "tRuE" aretrue
.
- Returns:
- Return
true
if the next string is a boolean.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextBoolean()
public boolean hasNextByte() throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a byte number.
CallshasNextByte(int)
with the current radix.
- Returns:
true
if the next string is a byte number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextByte()
public boolean hasNextByte(int radix) throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a byte number with the given radix.
To check, the private methodmyNextByte(int, boolean)
is called, and if no error occurs the next string could be a byte.
- Parameters:
radix
- The radix to use for this check. The global radix of the Scanner will not be changed.
- Returns:
true
if the next string is a byte number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextByte(int)
public boolean hasNextDouble() throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a double number.
To check, the private methodmyNextDouble(boolean)
is called, and if no error occurs the next string could be a double.
- Returns:
true
if the next string is a double number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextDouble()
public boolean hasNextFloat() throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a double number. Because every float is a double this is checked.
To check, the private methodmyNextDouble(boolean)
is called, and if no error occurs the next string could be a double.
- Returns:
true
if the next string is a double number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextFloat()
public boolean hasNextInt() throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as an int number.
To check, the private methodmyNextInt(int, boolean)
is called, and if no error occurs the next string could be an int.
- Returns:
true
if the next string is an int number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextInt(int)
public boolean hasNextInt(int radix) throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as an int number with the given radix.
To check, the private methodmyNextInt(int, boolean)
is called, and if no error occurs the next string could be an int.
- Parameters:
radix
- The radix to use for this check. The global radix of the Scanner will not be changed.
- Returns:
true
if the next string is an int number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextInt(int)
public boolean hasNextLine() throws IllegalStateException
Checks if there is a current line, which ends at the next line break or the end of the input.
- Returns:
true
if there is a current line.
- Throws:
IllegalStateException
- if the Scanner is closed.
public boolean hasNextLong() throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a long number.
To check, the private methodmyNextLong(int, boolean)
is called, and if no error occurs the next string could be a long.
- Returns:
true
if the next string is a long number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextLong()
public boolean hasNextLong(int radix) throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a long number with the given radix.
To check, the private methodmyNextLong(int, boolean)
is called, and if no error occurs the next string could be a long.
- Parameters:
radix
- The radix to use for this check. The global radix of the Scanner will not be changed.
- Returns:
true
if the next string is a long number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextLong(int)
public boolean hasNextShort() throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a short number with the given radix.
To check, the private methodmyNextShort(int, boolean)
is called, and if no error occurs the next string could be a short.
- Returns:
true
if the next string is a short number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextShort(int)
public boolean hasNextShort(int radix) throws IllegalStateException
Checks if the string to the next delimiter can be interpreted as a short number.
To check, the private methodmyNextShort(int, boolean)
is called, and if no error occurs the next string could be a short.
- Parameters:
radix
- The radix to use for this check. The global radix of the Scanner will not be changed.
- Returns:
true
if the next string is a short number.
- Throws:
IllegalStateException
- if the Scanner is closed.
- See Also:
nextShort(int)
public IOException ioException()
Returns the lastIOException
occured.
- Returns:
- Returns the last
IOException
.
public boolean isUseLocale()
Returns the current value ofuseLocale
. This is used to tell the Scanner if it should use the Locale format or just handle numbers of the default format.
- Returns:
- the useLoclae.
- See Also:
setUseLocale(boolean)
public Locale locale()
Returns the current Locale. It is initialized withLocale.getDefault()
.
- Returns:
- Returns the current Locale.
- See Also:
useLocale(Locale)
public MatchResult match()
Returns the last MatchResult found. This is updated after every successfully search.
- Returns:
- Returns the last
MatchResult
found.
public String next() throws NoSuchElementException, IllegalStateException
Uses the current delimiter to find the next string in the buffer. If a string is found the current position is set after the delimiter, otherwise aNoSuchElementException
is thrown. A successful match sets the matchResult.
- Specified by:
- next in interface Iterator<E>
- Returns:
- Returns the next string of the buffer.
- Throws:
NoSuchElementException
- If no element was found an exception is thrown.IllegalStateException
- If the Scanner is closed.
- See Also:
match()
public String next(String pattern) throws NoSuchElementException, IllegalStateException
Tries to match the buffer with the given pattern. The current delimiter will not be changed. Calls thenext(Pattern)
with the compiled pattern.
- Parameters:
pattern
- The pattern to match.
- Returns:
- Returns the next string matching the pattern.
- Throws:
NoSuchElementException
- If no element was found an exception is thrown.IllegalStateException
- If the Scanner is closed.
- See Also:
next(Pattern)
public String next(Pattern pattern) throws NoSuchElementException, IllegalStateException
Tries to match the buffer with the given pattern. The current delimiter will not be changed.
- Parameters:
pattern
- The pattern to match.
- Returns:
- Returns the next string matching the pattern.
- Throws:
NoSuchElementException
- If no element was found an exception is thrown.IllegalStateException
- If the Scanner is closed.
public BigDecimal nextBigDecimal() throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as a BigDecimal value.
- Returns:
- Returns the BigDecimal value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a BigDecimal.IllegalStateException
- If the Scanner is closed.
public BigInteger nextBigInteger() throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as a BigInteger value. CallnextBigInteger(int)
with the current radix as parameter, and return the value.
- Returns:
- Returns the BigInteger value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a BigInteger.IllegalStateException
- If the Scanner is closed.
- See Also:
nextBigInteger(int)
public BigInteger nextBigInteger(int radix) throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as a BigInteger value with the given radix.
- Parameters:
radix
- The radix to be used for this BigInteger. The current radix of the Scanner is not changed.
- Returns:
- Returns the BigInteger value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a BigInteger.IllegalStateException
- If the Scanner is closed.
public boolean nextBoolean() throws NoSuchElementException, IllegalStateException
Tries to interpret the next string to the delimiter as a boolean value, ignoring case.
- Returns:
- Returns the boolean value of the next matching string or throws an exception.
- Throws:
NoSuchElementException
- If no string is found or the string is not a boolean.IllegalStateException
- If the Scanner is closed.
public byte nextByte() throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as a byte value. CallnextByte(int)
with the current radix as parameter, and return the value.
- Returns:
- Returns the byte value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a byteIllegalStateException
- If the Scanner is closed.
- See Also:
nextByte(int)
public byte nextByte(int radix) throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as a byte value with the given radix.
- Parameters:
radix
- The radix to be used for this byte. The current radix of the Scanner is not changed.
- Returns:
- Returns the byte value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a byte.IllegalStateException
- If the Scanner is closed.
public double nextDouble() throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as a double value.
- Returns:
- Returns the int value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a double.IllegalStateException
- If the Scanner is closed.
public float nextFloat() throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as a double value, and then casts down to float.
- Returns:
- Returns the int value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a double.IllegalStateException
- If the Scanner is closed.
public int nextInt() throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as an int value. CallsnextInt(int)
with the current radix as parameter, and return the value.
- Returns:
- Returns the int value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not an int.IllegalStateException
- If the Scanner is closed.
- See Also:
nextInt(int)
public int nextInt(int radix) throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as an int value with the given radix.
- Parameters:
radix
- The radix to be used for this int. The current radix of the Scanner is not changed
- Returns:
- Returns the int value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not an int.IllegalStateException
- If the Scanner is closed.
public String nextLine() throws NoSuchElementException, IllegalStateException
Tries to match the system line seperator, and returns the current line.
- Returns:
- Returns the current line.
- Throws:
NoSuchElementException
- If the current delimiter is not found.IllegalStateException
- If the Scanner is closed.
public long nextLong() throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as a long value. CallsnextLong(int)
with the current radix as parameter, and return the value.
- Returns:
- Returns the long value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a long.IllegalStateException
- If the Scanner is closed.
- See Also:
nextLong(int)
public long nextLong(int radix) throws NoSuchElementException, IllegalStateException
Tries to interpret the next string as a long value with the given radix.
- Parameters:
radix
- The radix to be used for this long. The current radix of the Scanner is not changed
- Returns:
- Returns the long value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a long.IllegalStateException
- If the Scanner is closed.
public short nextShort() throws NoSuchElementException
Tries to interpret the next string as a short value. CallsnextShort(int)
with the current radix as parameter, and return the value.
- Returns:
- Returns the short value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a short.
- See Also:
nextShort(int)
public short nextShort(int radix) throws NoSuchElementException
Tries to interpret the next string as a short value with the given radix.
- Parameters:
radix
- The radix to be used for this short. The current radix of the Scanner is not changed.
- Returns:
- Returns the short value of the next string.
- Throws:
NoSuchElementException
- If no string is found or the string is not a short.
public void remove()
The remove operation is not supported by this implementation of Iterator.
- Specified by:
- remove in interface Iterator<E>
public Scanner skip(String pattern)
Skips a given pattern. Callsskip(Pattern)
with the compiled pattern.
- Parameters:
pattern
- Pattern which should be skipped.
- Returns:
this
with the skipped buffer.
- See Also:
skip(Pattern)
public Scanner skip(Pattern pattern) throws NoSuchElementException
Skips the given pattern. Sets skippedtrue
.
- Parameters:
pattern
- Pattern which should be skipped.
- Returns:
this
with the skipped buffer.
- Throws:
NoSuchElementException
- If the Pattern is not found.
public Scanner useDelimiter(String pattern)
Sets the current pattern to the given parameter. Compiles the pattern and callsuseDelimiter(Pattern)
- Parameters:
pattern
- The new pattern to use.
- Returns:
- Returns the Scanner (
this
) with the new pattern.
- See Also:
useDelimiter(Pattern)
public Scanner useDelimiter(Pattern pattern)
Sets the current pattern to the given parameter, and updates theMatcher
with the new pattern.
- Parameters:
pattern
- The new pattern to use.
- Returns:
- Returns the Scanner (
this
) with the new pattern.
public Scanner useLocale(Locale locale)
Sets the current Locale to the given parameter. Formats and Symbols are also set using the new Locale.
- Parameters:
locale
- The new Locale to use. If it isnull
nothing happens.
- Returns:
- Returns the Scanner (
this
) with the new Locale.
public Scanner useRadix(int radix) throws IllegalArgumentException
Sets the current radix to the current value if the given radix is >= 2 and <= 36 otherwise anIllegalArgumentException
is thrown.
- Parameters:
radix
- the new radix to use as default.
- Returns:
this
with the new radix value.
- Throws:
IllegalArgumentException
- When the given radix is out of bounds.