java.util
Constructor and Description |
---|
Scanner(File source)
Constructs a new Scanner with the given File as source.
|
Scanner(File source,
String charsetName)
Constructs a new Scanner with the given File as source.
|
Scanner(InputStream source)
Constructs a new Scanner with the given inputStream.
|
Scanner(InputStream source,
String charsetName)
Constructs a new Scanner with the InputSream and a charsetName.
|
Scanner(Readable source)
Constructs a new Scanner with a Readable input as source.
|
Scanner(ReadableByteChannel source)
Constructs a new Scanner with a ReadableByteChannel as
source.
|
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.
|
Scanner(String source)
Constructs a new Scanner using the given String as input only.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this Scanner.
|
Pattern |
delimiter()
Returns the current delimiter.
|
String |
findInLine(Pattern pattern)
Tries to find the pattern in the current line.
|
String |
findInLine(String pattern)
Compiles the given pattern into a
Pattern and calls
findInLine(Pattern) with the compiled pattern and
returns whatever it returns. |
String |
findWithinHorizon(Pattern pattern,
int horizon)
Trys to match the pattern within the given horizon.
|
String |
findWithinHorizon(String pattern,
int horizon)
Compile the pattern and call
findWithinHorizon(Pattern,
int) . |
boolean |
hasNext()
Checks if there is any next String using the current
delimiter.
|
boolean |
hasNext(Pattern pattern)
Searches the pattern in the next subString before the next
current delimiter.
|
boolean |
hasNext(String pattern)
Compiles the pattern to a
Pattern and calls hasNext(Pattern) . |
boolean |
hasNextBigDecimal()
Checks if the string to the next delimiter can be interpreted as
a BigDecimal number.
|
boolean |
hasNextBigInteger()
Checks if the string to the next delimiter can be interpreted as
a BigInteger number.
|
boolean |
hasNextBigInteger(int radix)
Checks if the string to the next delimiter can be interpreted as
a BigInteger number.
|
boolean |
hasNextBoolean()
Checks if the next string could be a boolean.
|
boolean |
hasNextByte()
Checks if the string to the next delimiter can be interpreted as
a byte number.
|
boolean |
hasNextByte(int radix)
Checks if the string to the next delimiter can be interpreted as
a byte number with the given radix.
|
boolean |
hasNextDouble()
Checks if the string to the next delimiter can be interpreted as
a double number.
|
boolean |
hasNextFloat()
Checks if the string to the next delimiter can be interpreted as
a double number.
|
boolean |
hasNextInt()
Checks if the string to the next delimiter can be interpreted as
an int number.
|
boolean |
hasNextInt(int radix)
Checks if the string to the next delimiter can be interpreted as
an int number with the given radix.
|
boolean |
hasNextLine()
Checks if there is a current line, which ends at the next line
break or the end of the input.
|
boolean |
hasNextLong()
Checks if the string to the next delimiter can be interpreted as
a long number.
|
boolean |
hasNextLong(int radix)
Checks if the string to the next delimiter can be interpreted as
a long number with the given radix.
|
boolean |
hasNextShort()
Checks if the string to the next delimiter can be interpreted as
a short number with the given radix.
|
boolean |
hasNextShort(int radix)
Checks if the string to the next delimiter can be interpreted as
a short number.
|
IOException |
ioException()
Returns the last
IOException occured. |
boolean |
isUseLocale()
Returns the current value of
useLocale . |
Locale |
locale()
Returns the current Locale.
|
MatchResult |
match()
Returns the last MatchResult found.
|
String |
next()
Uses the current delimiter to find the next string in the
buffer.
|
String |
next(Pattern pattern)
Tries to match the buffer with the given pattern.
|
String |
next(String pattern)
Tries to match the buffer with the given pattern.
|
BigDecimal |
nextBigDecimal()
Tries to interpret the next string as a BigDecimal value.
|
BigInteger |
nextBigInteger()
Tries to interpret the next string as a BigInteger value.
|
BigInteger |
nextBigInteger(int radix)
Tries to interpret the next string as a BigInteger value with the
given radix.
|
boolean |
nextBoolean()
Tries to interpret the next string to the delimiter as a boolean
value, ignoring case.
|
byte |
nextByte()
Tries to interpret the next string as a byte value.
|
byte |
nextByte(int radix)
Tries to interpret the next string as a byte value with the given
radix.
|
double |
nextDouble()
Tries to interpret the next string as a double value.
|
float |
nextFloat()
Tries to interpret the next string as a double value, and then
casts down to float.
|
int |
nextInt()
Tries to interpret the next string as an int value.
|
int |
nextInt(int radix)
Tries to interpret the next string as an int value with the given
radix.
|
String |
nextLine()
Tries to match the system line seperator, and returns the current
line.
|
long |
nextLong()
Tries to interpret the next string as a long value.
|
long |
nextLong(int radix)
Tries to interpret the next string as a long value with the given
radix.
|
short |
nextShort()
Tries to interpret the next string as a short value.
|
short |
nextShort(int radix)
Tries to interpret the next string as a short value with the
given radix.
|
int |
radix() |
void |
remove()
The remove operation is not supported by this implementation of
Iterator.
|
void |
setUseLocale(boolean useLocale) |
Scanner |
skip(Pattern pattern)
Skips the given pattern.
|
Scanner |
skip(String pattern)
Skips a given pattern.
|
String |
toString()
Returns the string representation of this Scanner.
|
Scanner |
useDelimiter(Pattern pattern)
Sets the current pattern to the given parameter, and updates the
Matcher with the new pattern. |
Scanner |
useDelimiter(String pattern)
Sets the current pattern to the given parameter.
|
Scanner |
useLocale(Locale locale)
Sets the current Locale to the given parameter.
|
Scanner |
useRadix(int radix)
Sets the current radix to the current value if the given radix is
>= 2 and <= 36 otherwise an
IllegalArgumentException is
thrown. |
public Scanner(File source) throws FileNotFoundException
Scanner(InputStream, String)
is called with null
as charsetName.source
- The File to use as source.FileNotFoundException
- If the file is not found an Exception is thrown.public Scanner(File source, String charsetName) throws FileNotFoundException
Scanner(InputStream, String)
is called with the given charsetName.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.FileNotFoundException
- If the file is not found an Exception is thrown.public Scanner(InputStream source)
Scanner(InputStream, String)
is called with null
as charsetName.source
- The InputStream to use as source.public Scanner(InputStream source, String charsetName)
source
- The InputStream to use as source.charsetName
- The charsetName to apply on the source's data.public Scanner(Readable source)
source
- The Readable to use as source.public Scanner(ReadableByteChannel source)
Scanner(ReadableByteChannel,
String)
is called with null
as charsetName.source
- The ReadableByteChannel to use as source.public Scanner(ReadableByteChannel source, String charsetName)
source
- The ReadableByteChannel to use as source.charsetName
- The charsetName to be applied on the source.public void close()
IOException
occurs it is
catched and is available under ioException()
.IllegalStateException
.public String findInLine(Pattern pattern) throws NoSuchElementException
pattern
- The pattern which should be searched in the
current line of the input.NoSuchElementException
is thrown.NoSuchElementException
- If the pattern was not found.public String findInLine(String pattern)
Pattern
and calls
findInLine(Pattern)
with the compiled pattern and
returns whatever it returns.pattern
- The pattern which should be matched in the input.NoSuchElementException
- If the pattern was not found.public String findWithinHorizon(Pattern pattern, int horizon) throws IllegalArgumentException, IllegalStateException
pattern
- Pattern to search.horizon
- IllegalArgumentException
- if the horizon is negative.IllegalStateException
- if the Scanner is closed.public String findWithinHorizon(String pattern, int horizon) throws IllegalArgumentException, IllegalStateException
findWithinHorizon(Pattern,
int)
.pattern
- Pattern to search.horizon
- IllegalArgumentException
- if the horizon is negative.IllegalStateException
- if the Scanner is closed.public boolean hasNext() throws IllegalStateException
null
and the length must be greater then 0. If a NoSuchElementException
is thrown by the search method, it is
catched and false is returned.hasNext
in interface Iterator<String>
true
if there is any result using the current delimiter. This wouldn't
lead to a NoSuchElementException
.IllegalStateException
- if the Scanner is closed.public boolean hasNext(Pattern pattern) throws IllegalStateException
pattern
- The pattern to search for. true
if the pattern is found before the current delimiter.IllegalStateException
- if the Scanner is closed.public boolean hasNext(String pattern) throws IllegalStateException
Pattern
and calls hasNext(Pattern)
.pattern
- The pattern as string to search for. true
if the pattern is found before the current delimiter.IllegalStateException
- if the Scanner is closed.hasNext(Pattern)
public boolean hasNextBigDecimal() throws IllegalStateException
true
if the next string is a BigDecimal number.IllegalStateException
- if the Scanner is closed.nextBigDecimal()
public boolean hasNextBigInteger() throws IllegalStateException
hasNextBigInteger(int)
with the current radix. true
if the next string is a BigInteger number.IllegalStateException
- if the Scanner is closed.nextBigInteger()
public boolean hasNextBigInteger(int radix) throws IllegalStateException
radix
- The radix to use for this check. The global radix of the Scanner will not be
changed. true
if the next string is a BigInteger number.IllegalStateException
- if the Scanner is closed.public boolean hasNextBoolean() throws IllegalStateException
true
. true
if the next string is a boolean.IllegalStateException
- if the Scanner is closed.nextBoolean()
public boolean hasNextByte() throws IllegalStateException
hasNextByte(int)
with the
current radix. true
if the next string is a byte number.IllegalStateException
- if the Scanner is closed.nextByte()
public boolean hasNextByte(int radix) throws IllegalStateException
myNextByte(int, boolean)
is called, and if no
error occurs the next string could be a byte.radix
- The radix to use for this check. The global radix of
the Scanner will not be changed. true
if the next string is a byte number.IllegalStateException
- if the Scanner is closed.nextByte(int)
public boolean hasNextDouble() throws IllegalStateException
myNextDouble(boolean)
is called, and if no error occurs the
next string could be a double. true
if the next string is a double number.IllegalStateException
- if the Scanner is closed.nextDouble()
public boolean hasNextFloat() throws IllegalStateException
myNextDouble(boolean)
is called, and if no error occurs the
next string could be a double. true
if the next string is a double number.IllegalStateException
- if the Scanner is closed.nextFloat()
public boolean hasNextInt() throws IllegalStateException
myNextInt(int, boolean)
is called, and if no error occurs the
next string could be an int. true
if the next string is an int number.IllegalStateException
- if the Scanner is closed.nextInt(int)
public boolean hasNextInt(int radix) throws IllegalStateException
myNextInt(int, boolean)
is called, and if no
error occurs the next string could be an int.radix
- The radix to use for this check. The global radix of the Scanner will not be
changed. true
if the next string is an int number.IllegalStateException
- if the Scanner is closed.nextInt(int)
public boolean hasNextLine() throws IllegalStateException
true
if there is a current line.IllegalStateException
- if the Scanner is closed.public boolean hasNextLong() throws IllegalStateException
myNextLong(int, boolean)
is called, and if no error occurs the
next string could be a long. true
if the next string is a long number.IllegalStateException
- if the Scanner is closed.nextLong()
public boolean hasNextLong(int radix) throws IllegalStateException
myNextLong(int, boolean)
is called, and if no
error occurs the next string could be a long.radix
- The radix to use for this check. The global radix of the Scanner will not be
changed. true
if the next string is a long number.IllegalStateException
- if the Scanner is closed.nextLong(int)
public boolean hasNextShort() throws IllegalStateException
myNextShort(int, boolean)
is called, and if no
error occurs the next string could be a short. true
if the next string is a short number.IllegalStateException
- if the Scanner is closed.nextShort(int)
public boolean hasNextShort(int radix) throws IllegalStateException
myNextShort(int, boolean)
is called, and if no error occurs the
next string could be a short.radix
- The radix to use for this check. The global radix of the Scanner will not be
changed. true
if the next string is a short number.IllegalStateException
- if the Scanner is closed.nextShort(int)
public IOException ioException()
IOException
occured.IOException
.public boolean isUseLocale()
useLocale
. This is used to
tell the Scanner if it should use the Locale format or just
handle numbers of the default format.setUseLocale(boolean)
public Locale locale()
Locale.getDefault()
.useLocale(Locale)
public MatchResult match()
MatchResult
found.public String next() throws NoSuchElementException, IllegalStateException
NoSuchElementException
is
thrown. A successful match sets the matchResult.next
in interface Iterator<String>
NoSuchElementException
- If no element was found an exception is thrown.IllegalStateException
- If the Scanner is closed.match()
public String next(Pattern pattern) throws NoSuchElementException, IllegalStateException
pattern
- The pattern to match.NoSuchElementException
- If no element was found an exception is thrown.IllegalStateException
- If the Scanner is closed.public String next(String pattern) throws NoSuchElementException, IllegalStateException
next(Pattern)
with the compiled pattern.pattern
- The pattern to match.NoSuchElementException
- If no element was found an exception is thrown.IllegalStateException
- If the Scanner is closed.next(Pattern)
public BigDecimal nextBigDecimal() throws NoSuchElementException, IllegalStateException
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
nextBigInteger(int)
with the current radix as parameter,
and return the value.NoSuchElementException
- If no string is found or the string is not a BigInteger.IllegalStateException
- If the Scanner is closed.nextBigInteger(int)
public BigInteger nextBigInteger(int radix) throws NoSuchElementException, IllegalStateException
radix
- The radix to be used for this BigInteger. The current radix of the Scanner is not
changed.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
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
nextByte(int)
with the current radix as parameter, and return
the value.NoSuchElementException
- If no string is found or the string is not a byteIllegalStateException
- If the Scanner is closed.nextByte(int)
public byte nextByte(int radix) throws NoSuchElementException, IllegalStateException
radix
- The radix to be used for this byte. The current radix of the Scanner is not
changed.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
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
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
nextInt(int)
with the current radix as parameter, and return
the value.NoSuchElementException
- If no string is found or the string is not an int.IllegalStateException
- If the Scanner is closed.nextInt(int)
public int nextInt(int radix) throws NoSuchElementException, IllegalStateException
radix
- The radix to be used for this int. The current radix of the Scanner is not changedNoSuchElementException
- If no string is found or the string is not an int.IllegalStateException
- If the Scanner is closed.public String nextLine() throws NoSuchElementException, IllegalStateException
NoSuchElementException
- If the current delimiter is not found.IllegalStateException
- If the Scanner is closed.public long nextLong() throws NoSuchElementException, IllegalStateException
nextLong(int)
with the current radix as parameter, and return
the value.NoSuchElementException
- If no string is found or the string is not a long.IllegalStateException
- If the Scanner is closed.nextLong(int)
public long nextLong(int radix) throws NoSuchElementException, IllegalStateException
radix
- The radix to be used for this long. The current radix of the Scanner is not
changedNoSuchElementException
- If no string is found or the string is not a long.IllegalStateException
- If the Scanner is closed.public short nextShort() throws NoSuchElementException
nextShort(int)
with the current radix as parameter, and return
the value.NoSuchElementException
- If no string is found or the string is not a short.nextShort(int)
public short nextShort(int radix) throws NoSuchElementException
radix
- The radix to be used for this short. The current radix of the Scanner is not
changed.NoSuchElementException
- If no string is found or the string is not a short.public int radix()
public void remove()
public void setUseLocale(boolean useLocale)
useLocale
- the useLocale to set.public Scanner skip(Pattern pattern) throws NoSuchElementException
true
.pattern
- Pattern which should be skipped.this
with the skipped buffer.NoSuchElementException
- If the Pattern is not found.public Scanner skip(String pattern)
skip(Pattern)
with the
compiled pattern.pattern
- Pattern which should be skipped.this
with the skipped buffer.skip(Pattern)
public String toString()
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public Scanner useDelimiter(Pattern pattern)
Matcher
with the new pattern.pattern
- The new pattern to use.this
) with the new pattern.public Scanner useDelimiter(String pattern)
useDelimiter(Pattern)
pattern
- The new pattern to use.this
) with the new pattern.useDelimiter(Pattern)
public Scanner useLocale(Locale locale)
locale
- The new Locale to use. If it is null
nothing happens.this
) with the new Locale.public Scanner useRadix(int radix) throws IllegalArgumentException
IllegalArgumentException
is
thrown.radix
- the new radix to use as default. this
with the new radix value.IllegalArgumentException
- When the given radix is out of bounds.