Scanner.java revision 893
869N/A * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. 869N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 869N/A * This code is free software; you can redistribute it and/or modify it 869N/A * under the terms of the GNU General Public License version 2 only, as 869N/A * published by the Free Software Foundation. Sun designates this 869N/A * particular file as subject to the "Classpath" exception as provided 869N/A * by Sun in the LICENSE file that accompanied this code. 869N/A * This code is distributed in the hope that it will be useful, but WITHOUT 869N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 869N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 869N/A * version 2 for more details (a copy is included in the LICENSE file that 869N/A * accompanied this code). 869N/A * You should have received a copy of the GNU General Public License version 873N/A * 2 along with this work; if not, write to the Free Software Foundation, 869N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 869N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 869N/A * CA 95054 USA or visit www.sun.com if you need additional information or 869N/A * A simple text scanner which can parse primitive types and strings using 0N/A * regular expressions. 48N/A * <p>A <code>Scanner</code> breaks its input into tokens using a 869N/A * delimiter pattern, which by default matches whitespace. The resulting 0N/A * tokens may then be converted into values of different types using the 869N/A * various <tt>next</tt> methods. 869N/A * <p>For example, this code allows a user to read a number from 0N/A * <tt>System.in</tt>: 869N/A * Scanner sc = new Scanner(System.in); 868N/A * int i = sc.nextInt(); 1007N/A * <p>As another example, this code allows <code>long</code> types to be 869N/A * assigned from entries in a file <code>myNumbers</code>: 1004N/A * Scanner sc = new Scanner(new File("myNumbers")); 0N/A * while (sc.hasNextLong()) { 0N/A * long aLong = sc.nextLong(); 0N/A * <p>The scanner can also use delimiters other than whitespace. This 0N/A * example reads several items in from a string: 869N/A * String input = "1 fish 2 fish red fish blue fish"; 868N/A * Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*"); 65N/A * System.out.println(s.nextInt()); 869N/A * System.out.println(s.nextInt()); 65N/A * System.out.println(s.next()); 65N/A * System.out.println(s.next()); 65N/A * s.close(); </pre></blockquote> 65N/A * prints the following output: 65N/A * <blockquote><pre> 65N/A * blue </pre></blockquote> 65N/A * <p>The same output can be generated with this code, which uses a regular 65N/A * expression to parse all four tokens at once: 65N/A * String input = "1 fish 2 fish red fish blue fish"; 0N/A * Scanner s = new Scanner(input); 869N/A * s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"); 868N/A * MatchResult result = s.match(); 0N/A * for (int i=1; i<=result.groupCount(); i++) 0N/A * System.out.println(result.group(i)); 0N/A * s.close(); </pre></blockquote> 0N/A * <p>The <a name="default-delimiter">default whitespace delimiter</a> used 0N/A * by a scanner is as recognized by {@link java.lang.Character}.{@link 0N/A * java.lang.Character#isWhitespace(char) isWhitespace}. The {@link #reset} 869N/A * method will reset the value of the scanner's delimiter to the default 0N/A * whitespace delimiter regardless of whether it was previously changed. 869N/A * <p>A scanning operation may block waiting for input. 0N/A * <p>The {@link #next} and {@link #hasNext} methods and their 0N/A * primitive-type companion methods (such as {@link #nextInt} and 869N/A * {@link #hasNextInt}) first skip any input that matches the delimiter 0N/A * pattern, and then attempt to return the next token. Both <tt>hasNext</tt> 0N/A * and <tt>next</tt> methods may block waiting for further input. Whether a 869N/A * <tt>hasNext</tt> method blocks has no connection to whether or not its 868N/A * associated <tt>next</tt> method will block. 869N/A * <p> The {@link #findInLine}, {@link #findWithinHorizon}, and {@link #skip} 868N/A * methods operate independently of the delimiter pattern. These methods will 868N/A * attempt to match the specified pattern with no regard to delimiters in the 869N/A * input and thus can be used in special circumstances where delimiters are 869N/A * not relevant. These methods may block waiting for more input. 0N/A * <p>When a scanner throws an {@link InputMismatchException}, the scanner 48N/A * will not pass the token that caused the exception, so that it may be 869N/A * retrieved or skipped via some other method. 869N/A * <p>Depending upon the type of delimiting pattern, empty tokens may be 868N/A * returned. For example, the pattern <tt>"\\s+"</tt> will return no empty 869N/A * tokens since it matches multiple instances of the delimiter. The delimiting 868N/A * pattern <tt>"\\s"</tt> could return empty tokens since it only passes one 0N/A * <p> A scanner can read text from any object which implements the {@link 869N/A * java.lang.Readable} interface. If an invocation of the underlying 868N/A * readable's {@link java.lang.Readable#read} method throws an {@link 0N/A * java.io.IOException} then the scanner assumes that the end of the input 0N/A * has been reached. The most recent <tt>IOException</tt> thrown by the 848N/A * underlying readable can be retrieved via the {@link #ioException} method. 848N/A * <p>When a <code>Scanner</code> is closed, it will close its input source 869N/A * if the source implements the {@link java.io.Closeable} interface. 848N/A * <p>A <code>Scanner</code> is not safe for multithreaded use without 0N/A * external synchronization. 0N/A * <p>Unless otherwise mentioned, passing a <code>null</code> parameter into 869N/A * any method of a <code>Scanner</code> will cause a 0N/A * <code>NullPointerException</code> to be thrown. 0N/A * <p>A scanner will default to interpreting numbers as decimal unless a 868N/A * different radix has been set by using the {@link #useRadix} method. The 868N/A * {@link #reset} method will reset the value of the scanner's radix to 868N/A * <code>10</code> regardless of whether it was previously changed. 869N/A * <a name="localized-numbers"> 868N/A * <h4> Localized numbers </h4> 868N/A * <p> An instance of this class is capable of scanning numbers in the standard 868N/A * formats as well as in the formats of the scanner's locale. A scanner's 868N/A * <a name="initial-locale">initial locale </a>is the value returned by the {@link 868N/A * java.util.Locale#getDefault} method; it may be changed via the {@link 868N/A * #useLocale} method. The {@link #reset} method will reset the value of the 869N/A * scanner's locale to the initial locale regardless of whether it was 868N/A * <p>The localized formats are defined in terms of the following parameters, 868N/A * which for a particular locale are taken from that locale's {@link 868N/A * java.text.DecimalFormat DecimalFormat} object, <tt>df</tt>, and its and 868N/A * {@link java.text.DecimalFormatSymbols DecimalFormatSymbols} object, 868N/A * <tr><td valign="top"><i>LocalGroupSeparator </i></td> 868N/A * <td valign="top">The character used to separate thousands groups, 868N/A * <i>i.e.,</i> <tt>dfs.</tt>{@link 868N/A * java.text.DecimalFormatSymbols#getGroupingSeparator 869N/A * getGroupingSeparator()}</td></tr> 868N/A * <tr><td valign="top"><i>LocalDecimalSeparator </i></td> 868N/A * <td valign="top">The character used for the decimal point, 868N/A * <i>i.e.,</i> <tt>dfs.</tt>{@link 868N/A * java.text.DecimalFormatSymbols#getDecimalSeparator 868N/A * getDecimalSeparator()}</td></tr> 869N/A * <tr><td valign="top"><i>LocalPositivePrefix </i></td> 868N/A * <td valign="top">The string that appears before a positive number (may 868N/A * be empty), <i>i.e.,</i> <tt>df.</tt>{@link 868N/A * java.text.DecimalFormat#getPositivePrefix 868N/A * getPositivePrefix()}</td></tr> 868N/A * <tr><td valign="top"><i>LocalPositiveSuffix </i></td> 868N/A * <td valign="top">The string that appears after a positive number (may be 868N/A * empty), <i>i.e.,</i> <tt>df.</tt>{@link 869N/A * java.text.DecimalFormat#getPositiveSuffix 868N/A * getPositiveSuffix()}</td></tr> 868N/A * <tr><td valign="top"><i>LocalNegativePrefix </i></td> 868N/A * <td valign="top">The string that appears before a negative number (may 868N/A * be empty), <i>i.e.,</i> <tt>df.</tt>{@link 868N/A * java.text.DecimalFormat#getNegativePrefix 868N/A * getNegativePrefix()}</td></tr> 868N/A * <tr><td valign="top"><i>LocalNegativeSuffix </i></td> 869N/A * <td valign="top">The string that appears after a negative number (may be 868N/A * empty), <i>i.e.,</i> <tt>df.</tt>{@link 0N/A * java.text.DecimalFormat#getNegativeSuffix 869N/A * getNegativeSuffix()}</td></tr> 0N/A * <tr><td valign="top"><i>LocalNaN </i></td> 868N/A * <td valign="top">The string that represents not-a-number for 869N/A * floating-point values, 868N/A * <i>i.e.,</i> <tt>dfs.</tt>{@link 0N/A * java.text.DecimalFormatSymbols#getNaN 0N/A * <tr><td valign="top"><i>LocalInfinity </i></td> 868N/A * <td valign="top">The string that represents infinity for floating-point 869N/A * values, <i>i.e.,</i> <tt>dfs.</tt>{@link 868N/A * java.text.DecimalFormatSymbols#getInfinity 868N/A * getInfinity()}</td></tr> 869N/A * </table></blockquote> 869N/A * <a name="number-syntax"> 869N/A * <h4> Number syntax </h4> 868N/A * <p> The strings that can be parsed as numbers by an instance of this class 868N/A * are specified in terms of the following regular-expression grammar, where 868N/A * Rmax is the highest digit in the radix being used (for example, Rmax is 9 869N/A * <table cellspacing=0 cellpadding=0 align=center> 869N/A * <tr><td valign=top align=right><i>NonASCIIDigit</i> ::</td> 869N/A * <td valign=top>= A non-ASCII character c for which 869N/A * {@link java.lang.Character#isDigit Character.isDigit}<tt>(c)</tt> 869N/A * returns true</td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <tr><td align=right><i>Non0Digit</i> ::</td> 869N/A * <td><tt>= [1-</tt><i>Rmax</i><tt>] | </tt><i>NonASCIIDigit</i></td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <tr><td align=right><i>Digit</i> ::</td> 869N/A * <td><tt>= [0-</tt><i>Rmax</i><tt>] | </tt><i>NonASCIIDigit</i></td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <tr><td valign=top align=right><i>GroupedNumeral</i> ::</td> 869N/A * <table cellpadding=0 cellspacing=0> 869N/A * <tr><td><tt>= ( </tt></td> 869N/A * <td><i>Non0Digit</i><tt> 869N/A * </tt><i>Digit</i><tt>? 869N/A * </tt><i>Digit</i><tt>?</tt></td></tr> 869N/A * <td><tt>( </tt><i>LocalGroupSeparator</i><tt> 869N/A * </tt><i>Digit</i><tt> 869N/A * </tt><i>Digit</i><tt> 869N/A * </tt><i>Digit</i><tt> )+ )</tt></td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <tr><td align=right><i>Numeral</i> ::</td> 869N/A * <td><tt>= ( ( </tt><i>Digit</i><tt>+ ) 869N/A * | </tt><i>GroupedNumeral</i><tt> )</tt></td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <tr><td valign=top align=right> 869N/A * <a name="Integer-regex"><i>Integer</i> ::</td> 869N/A * <td valign=top><tt>= ( [-+]? ( </tt><i>Numeral</i><tt> 869N/A * <td><tt>| </tt><i>LocalPositivePrefix</i><tt> </tt><i>Numeral</i><tt> 869N/A * </tt><i>LocalPositiveSuffix</i></td></tr> 869N/A * <td><tt>| </tt><i>LocalNegativePrefix</i><tt> </tt><i>Numeral</i><tt> 869N/A * </tt><i>LocalNegativeSuffix</i></td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <tr><td align=right><i>DecimalNumeral</i> ::</td> 869N/A * <td><tt>= </tt><i>Numeral</i></td></tr> 869N/A * <td><tt>| </tt><i>Numeral</i><tt> 869N/A * </tt><i>LocalDecimalSeparator</i><tt> 869N/A * </tt><i>Digit</i><tt>*</tt></td></tr> 824N/A * <td><tt>| </tt><i>LocalDecimalSeparator</i><tt> 869N/A * </tt><i>Digit</i><tt>+</tt></td></tr> 824N/A * <tr><td> </td></tr> 824N/A * <tr><td align=right><i>Exponent</i> ::</td> 824N/A * <td><tt>= ( [eE] [+-]? </tt><i>Digit</i><tt>+ )</tt></td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <a name="Decimal-regex"><i>Decimal</i> ::</td> 869N/A * <td><tt>= ( [-+]? </tt><i>DecimalNumeral</i><tt> 869N/A * </tt><i>Exponent</i><tt>? )</tt></td></tr> 869N/A * <td><tt>| </tt><i>LocalPositivePrefix</i><tt> 869N/A * </tt><i>DecimalNumeral</i><tt> 869N/A * </tt><i>LocalPositiveSuffix</i> 869N/A * </tt><i>Exponent</i><tt>?</td></tr> 869N/A * <td><tt>| </tt><i>LocalNegativePrefix</i><tt> 869N/A * </tt><i>DecimalNumeral</i><tt> 869N/A * </tt><i>LocalNegativeSuffix</i> 869N/A * </tt><i>Exponent</i><tt>?</td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <tr><td align=right><i>HexFloat</i> ::</td> 869N/A * <td><tt>= [-+]? 0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+ 869N/A * ([pP][-+]?[0-9]+)?</tt></td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <tr><td align=right><i>NonNumber</i> ::</td> 869N/A * <td valign=top><tt>= NaN 869N/A * | </tt><i>LocalNan</i><tt> 869N/A * | </tt><i>LocalInfinity</i></td></tr> 869N/A * <tr><td> </td></tr> 0N/A * <tr><td align=right><i>SignedNonNumber</i> ::</td> 869N/A * <td><tt>= ( [-+]? </tt><i>NonNumber</i><tt> )</tt></td></tr> 0N/A * <td><tt>| </tt><i>LocalPositivePrefix</i><tt> 0N/A * </tt><i>NonNumber</i><tt> 0N/A * </tt><i>LocalPositiveSuffix</i></td></tr> 0N/A * <td><tt>| </tt><i>LocalNegativePrefix</i><tt> 0N/A * </tt><i>NonNumber</i><tt> 869N/A * </tt><i>LocalNegativeSuffix</i></td></tr> 869N/A * <tr><td> </td></tr> 869N/A * <tr><td valign=top align=right> 869N/A * <a name="Float-regex"><i>Float</i> ::</td> 869N/A * <td valign=top><tt>= </tt><i>Decimal</i><tt></td></tr> 0N/A * <td><tt>| </tt><i>HexFloat</i><tt></td></tr> 0N/A * <td><tt>| </tt><i>SignedNonNumber</i><tt></td></tr> 869N/A * <p> Whitespace is not significant in the above regular expressions. 824N/A // Internal buffer used to hold input 869N/A // Size of internal character buffer 869N/A // The index into the buffer currently held by the Scanner 869N/A // Internal matcher used for finding delimiters 824N/A // Pattern used to delimit tokens 869N/A // Pattern found in last hasNext operation 869N/A // Position after last hasNext operation 869N/A // Result after last hasNext operation 869N/A // Boolean is true if source is done 869N/A // Boolean indicating more input is required 0N/A // Boolean indicating if a delim has been skipped this operation 0N/A // A store of a position that the scanner may fall back to 0N/A // A cache of the last primitive type scanned 0N/A // Boolean indicating if a match result is available 0N/A // Boolean indicating if this scanner has been closed 0N/A // The current radix used by this scanner 0N/A // The default radix for this scanner 0N/A // The locale used by this scanner 46N/A // A cache of the last few recently used Patterns 0N/A // A holder of the last IOException encountered 0N/A // A pattern for java whitespace 869N/A "\\p{javaWhitespace}+");
0N/A // A pattern for any token 869N/A // A pattern for non-ASCII digits 756N/A "[\\p{javaDigit}&&[^0-9]]");
988N/A // Fields and methods to support scanning primitive types 988N/A * Locale dependent values used to scan numbers 869N/A * Fields and an accessor method to match booleans 824N/A * Fields and methods to match bytes, shorts, ints, and longs 824N/A // \\p{javaDigit} is not guaranteed to be appropriate 869N/A // here but what can we do? The final authority will be 824N/A // whatever parse method is invoked, so ultimately the 869N/A // Scanner will do the right thing 869N/A // digit++ is the possessive form which is necessary for reducing 869N/A // backtracking that would otherwise cause unacceptable performance 824N/A * Fields and an accessor method to match line separators 868N/A "\r\n|[\n\r\u2028\u2029\u0085]";
869N/A * Fields and methods to match floats and doubles 869N/A // \\p{javaDigit} may not be perfect, see above 869N/A // Once again digit++ is used for performance, as above 0N/A "[-+]?0[xX][0-9a-fA-F]*\\.[0-9a-fA-F]+([pP][-+]?[0-9]+)?";
0N/A * Constructs a <code>Scanner</code> that returns values scanned 869N/A * from the specified source delimited by the specified pattern. 868N/A * @param source A character source implementing the Readable interface 869N/A * @param pattern A delimiting pattern 868N/A * @return A scanner with the specified source and pattern 0N/A * Constructs a new <code>Scanner</code> that produces values scanned 0N/A * from the specified source. 0N/A * @param source A character source implementing the {@link Readable} 869N/A * Constructs a new <code>Scanner</code> that produces values scanned 869N/A * from the specified input stream. Bytes from the stream are converted 0N/A * into characters using the underlying platform's 868N/A * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. 868N/A * @param source An input stream to be scanned 0N/A * Constructs a new <code>Scanner</code> that produces values scanned 0N/A * from the specified input stream. Bytes from the stream are converted 0N/A * into characters using the specified charset. 0N/A * @param source An input stream to be scanned 0N/A * @param charsetName The encoding type used to convert bytes from the 869N/A * stream into characters to be scanned 869N/A * @throws IllegalArgumentException if the specified character set 869N/A * Constructs a new <code>Scanner</code> that produces values scanned 869N/A * from the specified file. Bytes from the file are converted into 869N/A * characters using the underlying platform's 869N/A * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. 869N/A * @param source A file to be scanned 869N/A * @throws FileNotFoundException if source is not found 869N/A * Constructs a new <code>Scanner</code> that produces values scanned 0N/A * from the specified file. Bytes from the file are converted into 868N/A * characters using the specified charset. 0N/A * @param source A file to be scanned 869N/A * @param charsetName The encoding type used to convert bytes from the file 0N/A * into characters to be scanned 0N/A * @throws FileNotFoundException if source is not found 869N/A * @throws IllegalArgumentException if the specified encoding is 0N/A * Constructs a new <code>Scanner</code> that produces values scanned 869N/A * from the specified file. Bytes from the file are converted into 0N/A * characters using the underlying platform's 0N/A * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. 0N/A * A file to be scanned 0N/A * @throws IOException 0N/A * if an I/O error occurs opening source 868N/A * Constructs a new <code>Scanner</code> that produces values scanned 0N/A * from the specified file. Bytes from the file are converted into 869N/A * characters using the specified charset. 0N/A * @param charsetName 0N/A * The encoding type used to convert bytes from the file 869N/A * into characters to be scanned 0N/A * @throws IOException 0N/A * if an I/O error occurs opening source 0N/A * @throws IllegalArgumentException 0N/A * if the specified encoding is not found 0N/A * Constructs a new <code>Scanner</code> that produces values scanned 0N/A * from the specified string. 0N/A * @param source A string to scan 869N/A * Constructs a new <code>Scanner</code> that produces values scanned 0N/A * from the specified channel. Bytes from the source are converted into 0N/A * characters using the underlying platform's 0N/A * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. 0N/A * @param source A channel to scan 869N/A * Constructs a new <code>Scanner</code> that produces values scanned 869N/A * from the specified channel. Bytes from the source are converted into 869N/A * characters using the specified charset. 0N/A * @param source A channel to scan 869N/A * @param charsetName The encoding type used to convert bytes from the 0N/A * channel into characters to be scanned 0N/A * @throws IllegalArgumentException if the specified character set 869N/A // Private primitives used to support scanning 0N/A // Clears both regular cache and type cache 0N/A // Also clears both the regular cache and the type cache 0N/A // Also clears both the regular cache and the type cache 0N/A // Tries to read more input. May block. 869N/A // Prepare to receive data 869N/A // Restore current position and limit for reading 0N/A // After this method is called there will either be an exception 0N/A // or else there will be space in the buffer 0N/A // Gain space by compacting buffer 0N/A // Gain space by growing buffer 0N/A // be modified appropriately 0N/A // If we are at the end of input then NoSuchElement; 869N/A // If there is still input left then InputMismatch 0N/A // Returns true if a complete token or partial token is in the buffer. 0N/A // It is not necessary to find a complete token since a partial token 869N/A // means that there will be another token with or without more input. 0N/A // Skip delims first 0N/A // If we are sitting at the end, no more tokens in buffer 869N/A * Returns a "complete token" that matches the specified pattern 0N/A * A token is complete if surrounded by delims; a partial token 0N/A * is prefixed by delims but not postfixed by them 869N/A * The position is advanced to the end of that complete token 869N/A * Pattern == null means accept any token at all 0N/A * 1. valid string means it was found 0N/A * 2. null with needInput=false means we won't ever find it 869N/A * 3. null with needInput=true means try again after readInput 0N/A // Skip delims first 869N/A if (!
skipped) {
// Enforcing only one skip of leading delims 0N/A // If more input could extend the delimiters then we must wait 0N/A // The delims were whole and the matcher should skip them 0N/A // If we are sitting at the end, no more tokens in buffer 869N/A // Must look for next delims. Simply attempting to match the 869N/A // pattern at this point may find a match but it might not be 869N/A // the first longest match because of missing input, or it might 869N/A // match a partial token instead of the whole thing. 869N/A // Then look for next delims 868N/A // Zero length delimiter match; we should find the next one 868N/A // using the automatic advance past a zero length match; 868N/A // Otherwise we have just found the same one we just skipped 869N/A // In the rare case that more input could cause the match 0N/A // to be lost and there is more input coming we must wait 0N/A // for more input. Note that hitting the end is okay as long 869N/A // as the match cannot go away. It is the beginning of the 0N/A // next delims we want to be sure about, we don't care if 869N/A // they potentially extend further. 869N/A // There is a complete token. 869N/A // Must continue with match to provide valid MatchResult 869N/A // Attempt to match against the desired pattern 869N/A }
else {
// Complete token but it does not match 869N/A // If we can't find the next delims but no more input is coming, 245N/A // then we can treat the remainder as a whole token 869N/A // Must continue with match to provide valid MatchResult 245N/A // Last token; Match the pattern here or throw 0N/A // Last piece does not match 869N/A // There is a partial token in the buffer; must read more 0N/A // Finds the specified pattern in the buffer up to horizon. 869N/A // Returns a match for the specified input pattern. 0N/A // The match may be longer if didn't hit horizon or real end 0N/A // Hit an artificial end; try to extend the match 869N/A // The match could go away depending on what is next 0N/A // Rare case: we hit the end of input and it happens 0N/A // that it is at the horizon and the end of input is 0N/A // required for the match. 0N/A // Did not hit end, or hit real end, or hit horizon 0N/A // If there is no specified horizon, or if we have not searched 0N/A // to the specified horizon yet, get more input 0N/A // Returns a match for the specified input pattern anchored at 0N/A // the current position 868N/A // Get more input and try again 869N/A // Read more to find pattern 1026N/A // Throws if the scanner is closed 1017N/A * <p> If this scanner has not yet been closed then if its underlying 1017N/A * {@linkplain java.lang.Readable readable} also implements the {@link 1017N/A * java.io.Closeable} interface then the readable's <tt>close</tt> method 1017N/A * will be invoked. If this scanner is already closed then invoking this 1017N/A * method will have no effect. 1026N/A * <p>Attempting to perform search operations after a scanner has 1026N/A * been closed will result in an {@link IllegalStateException}. 0N/A * Returns the <code>IOException</code> last thrown by this 0N/A * <code>Scanner</code>'s underlying <code>Readable</code>. This method 0N/A * returns <code>null</code> if no such exception exists. 0N/A * @return the last exception thrown by this scanner's readable 0N/A * Returns the <code>Pattern</code> this <code>Scanner</code> is currently 0N/A * using to match delimiters. 0N/A * @return this scanner's delimiting pattern. 0N/A * Sets this scanner's delimiting pattern to the specified pattern. 0N/A * @param pattern A delimiting pattern 868N/A * Sets this scanner's delimiting pattern to a pattern constructed from 869N/A * the specified <code>String</code>. 868N/A * <p> An invocation of this method of the form 0N/A * <tt>useDelimiter(pattern)</tt> behaves in exactly the same way as the 0N/A * invocation <tt>useDelimiter(Pattern.compile(pattern))</tt>. 869N/A * <p> Invoking the {@link #reset} method will set the scanner's delimiter 0N/A * to the <a href= "#default-delimiter">default</a>. 869N/A * @param pattern A string specifying a delimiting pattern 776N/A * Returns this scanner's locale. 776N/A * <p>A scanner's locale affects many elements of its default 776N/A * primitive matching regular expressions; see 776N/A * <a href= "#localized-numbers">localized numbers</a> above. 776N/A * @return this scanner's locale 868N/A * Sets this scanner's locale to the specified locale. 869N/A * <p>A scanner's locale affects many elements of its default 0N/A * primitive matching regular expressions; see 0N/A * <a href= "#localized-numbers">localized numbers</a> above. 868N/A * <p>Invoking the {@link #reset} method will set the scanner's locale to 869N/A * the <a href= "#initial-locale">initial locale</a>. 869N/A * @param locale A string specifying the locale to use 48N/A * @return this scanner 869N/A // These must be literalized to avoid collision with regex 868N/A // metacharacters such as dot or parenthesis 869N/A // Quoting the nonzero length locale-specific things 868N/A // to avoid potential conflict with metacharacters 868N/A // Force rebuilding and recompilation of locale dependent 0N/A // primitive patterns 868N/A * Returns this scanner's default radix. 869N/A * <p>A scanner's radix affects elements of its default 869N/A * number matching regular expressions; see 868N/A * <a href= "#localized-numbers">localized numbers</a> above. 869N/A * @return the default radix of this scanner 869N/A * Sets this scanner's default radix to the specified radix. 869N/A * <p>A scanner's radix affects elements of its default 869N/A * number matching regular expressions; see 868N/A * <a href= "#localized-numbers">localized numbers</a> above. 0N/A * <p>If the radix is less than <code>Character.MIN_RADIX</code> 869N/A * or greater than <code>Character.MAX_RADIX</code>, then an 0N/A * <code>IllegalArgumentException</code> is thrown. 869N/A * <p>Invoking the {@link #reset} method will set the scanner's radix to 0N/A * @param radix The radix to use when scanning numbers 0N/A * @return this scanner 0N/A * @throws IllegalArgumentException if radix is out of range 0N/A // Force rebuilding and recompilation of radix dependent patterns 0N/A // The next operation should occur in the specified radix but 0N/A // the default is left untouched. 914N/A // Force rebuilding and recompilation of radix dependent patterns 0N/A * Returns the match result of the last scanning operation performed 0N/A * by this scanner. This method throws <code>IllegalStateException</code> 869N/A * if no match has been performed, or if the last match was 0N/A * <p>The various <code>next</code>methods of <code>Scanner</code> 0N/A * make a match result available if they complete without throwing an 0N/A * exception. For instance, after an invocation of the {@link #nextInt} 0N/A * method that returned an int, this method returns a 869N/A * <code>MatchResult</code> for the search of the 0N/A * <a href="#Integer-regex"><i>Integer</i></a> regular expression 0N/A * defined above. Similarly the {@link #findInLine}, 0N/A * {@link #findWithinHorizon}, and {@link #skip} methods will make a 0N/A * match available if they succeed. 0N/A * @return a match result for the last match operation 869N/A * @throws IllegalStateException If no match result is available 0N/A * <p>Returns the string representation of this <code>Scanner</code>. The 0N/A * string representation of a <code>Scanner</code> contains information 0N/A * that may be useful for debugging. The exact format is unspecified. 0N/A * @return The string representation of this scanner 0N/A * Returns true if this scanner has another token in its input. 0N/A * This method may block while waiting for input to scan. 0N/A * The scanner does not advance past any input. 0N/A * @return true if and only if this scanner has another token 0N/A * @throws IllegalStateException if this scanner is closed 869N/A * @see java.util.Iterator 869N/A * Finds and returns the next complete token from this scanner. 0N/A * A complete token is preceded and followed by input that matches 0N/A * the delimiter pattern. This method may block while waiting for input 869N/A * to scan, even if a previous invocation of {@link #hasNext} returned 0N/A * <code>true</code>. 0N/A * @return the next token 0N/A * @throws NoSuchElementException if no more tokens are available 869N/A * @throws IllegalStateException if this scanner is closed 0N/A * @see java.util.Iterator 0N/A * The remove operation is not supported by this implementation of 0N/A * <code>Iterator</code>. 0N/A * @throws UnsupportedOperationException if this method is invoked. 0N/A * @see java.util.Iterator 0N/A * Returns true if the next token matches the pattern constructed from the 0N/A * specified string. The scanner does not advance past any input. 0N/A * <p> An invocation of this method of the form <tt>hasNext(pattern)</tt> 0N/A * behaves in exactly the same way as the invocation 0N/A * <tt>hasNext(Pattern.compile(pattern))</tt>. 0N/A * @param pattern a string specifying the pattern to scan 0N/A * @return true if and only if this scanner has another token matching 869N/A * the specified pattern 0N/A * @throws IllegalStateException if this scanner is closed 0N/A * Returns the next token if it matches the pattern constructed from the 0N/A * specified string. If the match is successful, the scanner advances 0N/A * past the input that matched the pattern. 0N/A * <p> An invocation of this method of the form <tt>next(pattern)</tt> 0N/A * behaves in exactly the same way as the invocation 869N/A * <tt>next(Pattern.compile(pattern))</tt>. 0N/A * @param pattern a string specifying the pattern to scan 0N/A * @return the next token 0N/A * @throws NoSuchElementException if no such tokens are available 0N/A * @throws IllegalStateException if this scanner is closed 0N/A * Returns true if the next complete token matches the specified pattern. 0N/A * A complete token is prefixed and postfixed by input that matches 869N/A * the delimiter pattern. This method may block while waiting for input. 0N/A * The scanner does not advance past any input. 0N/A * @param pattern the pattern to scan for 0N/A * @return true if and only if this scanner has another token matching 0N/A * the specified pattern 0N/A * @throws IllegalStateException if this scanner is closed 0N/A * Returns the next token if it matches the specified pattern. This 0N/A * method may block while waiting for input to scan, even if a previous 0N/A * invocation of {@link #hasNext(Pattern)} returned <code>true</code>. 0N/A * If the match is successful, the scanner advances past the input that 0N/A * matched the pattern. 869N/A * @param pattern the pattern to scan for 0N/A * @return the next token 0N/A * @throws NoSuchElementException if no more tokens are available 0N/A * @throws IllegalStateException if this scanner is closed 0N/A // Did we already find this pattern? 0N/A // Search for the pattern 0N/A * Returns true if there is another line in the input of this scanner. 0N/A * This method may block while waiting for input. The scanner does not 0N/A * advance past any input. 869N/A * @return true if and only if this scanner has another line of input 0N/A * @throws IllegalStateException if this scanner is closed 0N/A * Advances this scanner past the current line and returns the input 0N/A * This method returns the rest of the current line, excluding any line 869N/A * separator at the end. The position is set to the beginning of the next 0N/A * <p>Since this method continues to search through the input looking 0N/A * for a line separator, it may buffer all of the input searching for 0N/A * the line to skip if no line separators are present. 869N/A * @return the line that was skipped 0N/A * @throws NoSuchElementException if no line was found 0N/A * @throws IllegalStateException if this scanner is closed 0N/A // Public methods that ignore delimiters 0N/A * Attempts to find the next occurrence of a pattern constructed from the 0N/A * specified string, ignoring delimiters. 869N/A * <p>An invocation of this method of the form <tt>findInLine(pattern)</tt> 869N/A * behaves in exactly the same way as the invocation 0N/A * <tt>findInLine(Pattern.compile(pattern))</tt>. 0N/A * @param pattern a string specifying the pattern to search for 0N/A * @return the text that matched the specified pattern 0N/A * @throws IllegalStateException if this scanner is closed 0N/A * Attempts to find the next occurrence of the specified pattern ignoring 0N/A * delimiters. If the pattern is found before the next line separator, the 0N/A * scanner advances past the input that matched and returns the string that 0N/A * If no such pattern is detected in the input up to the next line 0N/A * separator, then <code>null</code> is returned and the scanner's 869N/A * position is unchanged. This method may block waiting for input that 869N/A * <p>Since this method continues to search through the input looking 869N/A * for the specified pattern, it may buffer all of the input searching for 869N/A * the desired token if no line separators are present. 868N/A * @param pattern the pattern to scan for 868N/A * @return the text that matched the specified pattern 868N/A * @throws IllegalStateException if this scanner is closed 0N/A // Expand buffer to include the next newline or end of input 869N/A break;
// up to next newline 868N/A break;
// up to end of input 824N/A // If there is nothing between the current pos and the next 869N/A // newline simply return null, invoking findWithinHorizon 868N/A // with "horizon=0" will scan beyond the line bound. 868N/A // Search for the pattern 824N/A * Attempts to find the next occurrence of a pattern constructed from the 869N/A * specified string, ignoring delimiters. 824N/A * <p>An invocation of this method of the form 869N/A * <tt>findWithinHorizon(pattern)</tt> behaves in exactly the same way as 868N/A * <tt>findWithinHorizon(Pattern.compile(pattern, horizon))</tt>. 849N/A * @param pattern a string specifying the pattern to search for 824N/A * @return the text that matched the specified pattern 0N/A * @throws IllegalStateException if this scanner is closed 869N/A * @throws IllegalArgumentException if horizon is negative 869N/A * Attempts to find the next occurrence of the specified pattern. 0N/A * <p>This method searches through the input up to the specified 869N/A * search horizon, ignoring delimiters. If the pattern is found the 869N/A * scanner advances past the input that matched and returns the string 0N/A * that matched the pattern. If no such pattern is detected then the * null is returned and the scanner's position remains unchanged. This * method may block waiting for input that matches the pattern. * <p>A scanner will never search more than <code>horizon</code> code * points beyond its current position. Note that a match may be clipped * by the horizon; that is, an arbitrary match result may have been * different if the horizon had been larger. The scanner treats the * horizon as a transparent, non-anchoring bound (see {@link * Matcher#useTransparentBounds} and {@link Matcher#useAnchoringBounds}). * <p>If horizon is <code>0</code>, then the horizon is ignored and * this method continues to search through the input looking for the * specified pattern without bound. In this case it may buffer all of * the input searching for the pattern. * <p>If horizon is negative, then an IllegalArgumentException is * @param pattern the pattern to scan for * @return the text that matched the specified pattern * @throws IllegalStateException if this scanner is closed * @throws IllegalArgumentException if horizon is negative // Search for the pattern break;
// up to end of input * Skips input that matches the specified pattern, ignoring delimiters. * This method will skip input if an anchored match of the specified * <p>If a match to the specified pattern is not found at the * current position, then no input is skipped and a * <tt>NoSuchElementException</tt> is thrown. * <p>Since this method seeks to match the specified pattern starting at * the scanner's current position, patterns that can match a lot of * input (".*", for example) may cause the scanner to buffer a large * <p>Note that it is possible to skip something without risking a * <code>NoSuchElementException</code> by using a pattern that can * match nothing, e.g., <code>sc.skip("[ \t]*")</code>. * @param pattern a string specifying the pattern to skip over * @throws NoSuchElementException if the specified pattern is not found * @throws IllegalStateException if this scanner is closed // Search for the pattern * Skips input that matches a pattern constructed from the specified * <p> An invocation of this method of the form <tt>skip(pattern)</tt> * behaves in exactly the same way as the invocation * <tt>skip(Pattern.compile(pattern))</tt>. * @param pattern a string specifying the pattern to skip over * @throws IllegalStateException if this scanner is closed // Convenience methods for scanning primitives * Returns true if the next token in this scanner's input can be * interpreted as a boolean value using a case insensitive pattern * created from the string "true|false". The scanner does not * advance past the input that matched. * @return true if and only if this scanner's next token is a valid * @throws IllegalStateException if this scanner is closed * Scans the next token of the input into a boolean value and returns * that value. This method will throw <code>InputMismatchException</code> * if the next token cannot be translated into a valid boolean value. * If the match is successful, the scanner advances past the input that * @return the boolean scanned from the input * @throws InputMismatchException if the next token is not a valid boolean * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as a byte value in the default radix using the * {@link #nextByte} method. The scanner does not advance past any input. * @return true if and only if this scanner's next token is a valid * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as a byte value in the specified radix using the * {@link #nextByte} method. The scanner does not advance past any input. * @param radix the radix used to interpret the token as a byte value * @return true if and only if this scanner's next token is a valid * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a <tt>byte</tt>. * <p> An invocation of this method of the form * <tt>nextByte()</tt> behaves in exactly the same way as the * invocation <tt>nextByte(radix)</tt>, where <code>radix</code> * is the default radix of this scanner. * @return the <tt>byte</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a <tt>byte</tt>. * This method will throw <code>InputMismatchException</code> * if the next token cannot be translated into a valid byte value as * described below. If the translation is successful, the scanner advances * past the input that matched. * <p> If the next token matches the <a * href="#Integer-regex"><i>Integer</i></a> regular expression defined * above then the token is converted into a <tt>byte</tt> value as if by * removing all locale specific prefixes, group separators, and locale * specific suffixes, then mapping non-ASCII digits into ASCII * digits via {@link Character#digit Character.digit}, prepending a * negative sign (-) if the locale specific negative prefixes and suffixes * were present, and passing the resulting string to * {@link Byte#parseByte(String, int) Byte.parseByte} with the * @param radix the radix used to interpret the token as a byte value * @return the <tt>byte</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as a short value in the default radix using the * {@link #nextShort} method. The scanner does not advance past any input. * @return true if and only if this scanner's next token is a valid * short value in the default radix * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as a short value in the specified radix using the * {@link #nextShort} method. The scanner does not advance past any input. * @param radix the radix used to interpret the token as a short value * @return true if and only if this scanner's next token is a valid * short value in the specified radix * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a <tt>short</tt>. * <p> An invocation of this method of the form * <tt>nextShort()</tt> behaves in exactly the same way as the * invocation <tt>nextShort(radix)</tt>, where <code>radix</code> * is the default radix of this scanner. * @return the <tt>short</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a <tt>short</tt>. * This method will throw <code>InputMismatchException</code> * if the next token cannot be translated into a valid short value as * described below. If the translation is successful, the scanner advances * past the input that matched. * <p> If the next token matches the <a * href="#Integer-regex"><i>Integer</i></a> regular expression defined * above then the token is converted into a <tt>short</tt> value as if by * removing all locale specific prefixes, group separators, and locale * specific suffixes, then mapping non-ASCII digits into ASCII * digits via {@link Character#digit Character.digit}, prepending a * negative sign (-) if the locale specific negative prefixes and suffixes * were present, and passing the resulting string to * {@link Short#parseShort(String, int) Short.parseShort} with the * @param radix the radix used to interpret the token as a short value * @return the <tt>short</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as an int value in the default radix using the * {@link #nextInt} method. The scanner does not advance past any input. * @return true if and only if this scanner's next token is a valid * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as an int value in the specified radix using the * {@link #nextInt} method. The scanner does not advance past any input. * @param radix the radix used to interpret the token as an int value * @return true if and only if this scanner's next token is a valid * @throws IllegalStateException if this scanner is closed * The integer token must be stripped of prefixes, group separators, * and suffixes, non ascii digits must be converted into ascii digits * before parse will accept it. * Scans the next token of the input as an <tt>int</tt>. * <p> An invocation of this method of the form * <tt>nextInt()</tt> behaves in exactly the same way as the * invocation <tt>nextInt(radix)</tt>, where <code>radix</code> * is the default radix of this scanner. * @return the <tt>int</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as an <tt>int</tt>. * This method will throw <code>InputMismatchException</code> * if the next token cannot be translated into a valid int value as * described below. If the translation is successful, the scanner advances * past the input that matched. * <p> If the next token matches the <a * href="#Integer-regex"><i>Integer</i></a> regular expression defined * above then the token is converted into an <tt>int</tt> value as if by * removing all locale specific prefixes, group separators, and locale * specific suffixes, then mapping non-ASCII digits into ASCII * digits via {@link Character#digit Character.digit}, prepending a * negative sign (-) if the locale specific negative prefixes and suffixes * were present, and passing the resulting string to * {@link Integer#parseInt(String, int) Integer.parseInt} with the * @param radix the radix used to interpret the token as an int value * @return the <tt>int</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as a long value in the default radix using the * {@link #nextLong} method. The scanner does not advance past any input. * @return true if and only if this scanner's next token is a valid * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as a long value in the specified radix using the * {@link #nextLong} method. The scanner does not advance past any input. * @param radix the radix used to interpret the token as a long value * @return true if and only if this scanner's next token is a valid * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a <tt>long</tt>. * <p> An invocation of this method of the form * <tt>nextLong()</tt> behaves in exactly the same way as the * invocation <tt>nextLong(radix)</tt>, where <code>radix</code> * is the default radix of this scanner. * @return the <tt>long</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a <tt>long</tt>. * This method will throw <code>InputMismatchException</code> * if the next token cannot be translated into a valid long value as * described below. If the translation is successful, the scanner advances * past the input that matched. * <p> If the next token matches the <a * href="#Integer-regex"><i>Integer</i></a> regular expression defined * above then the token is converted into a <tt>long</tt> value as if by * removing all locale specific prefixes, group separators, and locale * specific suffixes, then mapping non-ASCII digits into ASCII * digits via {@link Character#digit Character.digit}, prepending a * negative sign (-) if the locale specific negative prefixes and suffixes * were present, and passing the resulting string to * {@link Long#parseLong(String, int) Long.parseLong} with the * @param radix the radix used to interpret the token as an int value * @return the <tt>long</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * The float token must be stripped of prefixes, group separators, * and suffixes, non ascii digits must be converted into ascii digits * before parseFloat will accept it. * If there are non-ascii digits in the token these digits must * be processed before the token is passed to parseFloat. // Translate non-ASCII digits * Returns true if the next token in this scanner's input can be * interpreted as a float value using the {@link #nextFloat} * method. The scanner does not advance past any input. * @return true if and only if this scanner's next token is a valid * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a <tt>float</tt>. * This method will throw <code>InputMismatchException</code> * if the next token cannot be translated into a valid float value as * described below. If the translation is successful, the scanner advances * past the input that matched. * <p> If the next token matches the <a * href="#Float-regex"><i>Float</i></a> regular expression defined above * then the token is converted into a <tt>float</tt> value as if by * removing all locale specific prefixes, group separators, and locale * specific suffixes, then mapping non-ASCII digits into ASCII * digits via {@link Character#digit Character.digit}, prepending a * negative sign (-) if the locale specific negative prefixes and suffixes * were present, and passing the resulting string to * {@link Float#parseFloat Float.parseFloat}. If the token matches * the localized NaN or infinity strings, then either "Nan" or "Infinity" * is passed to {@link Float#parseFloat(String) Float.parseFloat} as * @return the <tt>float</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Float</i> * regular expression, or is out of range * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as a double value using the {@link #nextDouble} * method. The scanner does not advance past any input. * @return true if and only if this scanner's next token is a valid * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a <tt>double</tt>. * This method will throw <code>InputMismatchException</code> * if the next token cannot be translated into a valid double value. * If the translation is successful, the scanner advances past the input * <p> If the next token matches the <a * href="#Float-regex"><i>Float</i></a> regular expression defined above * then the token is converted into a <tt>double</tt> value as if by * removing all locale specific prefixes, group separators, and locale * specific suffixes, then mapping non-ASCII digits into ASCII * digits via {@link Character#digit Character.digit}, prepending a * negative sign (-) if the locale specific negative prefixes and suffixes * were present, and passing the resulting string to * {@link Double#parseDouble Double.parseDouble}. If the token matches * the localized NaN or infinity strings, then either "Nan" or "Infinity" * is passed to {@link Double#parseDouble(String) Double.parseDouble} as * @return the <tt>double</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Float</i> * regular expression, or is out of range * @throws NoSuchElementException if the input is exhausted * @throws IllegalStateException if this scanner is closed // Convenience methods for scanning multi precision numbers * Returns true if the next token in this scanner's input can be * interpreted as a <code>BigInteger</code> in the default radix using the * {@link #nextBigInteger} method. The scanner does not advance past any * @return true if and only if this scanner's next token is a valid * <code>BigInteger</code> * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as a <code>BigInteger</code> in the specified radix using * the {@link #nextBigInteger} method. The scanner does not advance past * @param radix the radix used to interpret the token as an integer * @return true if and only if this scanner's next token is a valid * <code>BigInteger</code> * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a {@link java.math.BigInteger * <p> An invocation of this method of the form * <tt>nextBigInteger()</tt> behaves in exactly the same way as the * invocation <tt>nextBigInteger(radix)</tt>, where <code>radix</code> * is the default radix of this scanner. * @return the <tt>BigInteger</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if the input is exhausted * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a {@link java.math.BigInteger * <p> If the next token matches the <a * href="#Integer-regex"><i>Integer</i></a> regular expression defined * above then the token is converted into a <tt>BigInteger</tt> value as if * by removing all group separators, mapping non-ASCII digits into ASCII * digits via the {@link Character#digit Character.digit}, and passing the * resulting string to the {@link * java.math.BigInteger#BigInteger(java.lang.String) * BigInteger(String, int)} constructor with the specified radix. * @param radix the radix used to interpret the token * @return the <tt>BigInteger</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Integer</i> * regular expression, or is out of range * @throws NoSuchElementException if the input is exhausted * @throws IllegalStateException if this scanner is closed * Returns true if the next token in this scanner's input can be * interpreted as a <code>BigDecimal</code> using the * {@link #nextBigDecimal} method. The scanner does not advance past any * @return true if and only if this scanner's next token is a valid * <code>BigDecimal</code> * @throws IllegalStateException if this scanner is closed * Scans the next token of the input as a {@link java.math.BigDecimal * <p> If the next token matches the <a * href="#Decimal-regex"><i>Decimal</i></a> regular expression defined * above then the token is converted into a <tt>BigDecimal</tt> value as if * by removing all group separators, mapping non-ASCII digits into ASCII * digits via the {@link Character#digit Character.digit}, and passing the * resulting string to the {@link * java.math.BigDecimal#BigDecimal(java.lang.String) BigDecimal(String)} * @return the <tt>BigDecimal</tt> scanned from the input * @throws InputMismatchException * if the next token does not match the <i>Decimal</i> * regular expression, or is out of range * @throws NoSuchElementException if the input is exhausted * @throws IllegalStateException if this scanner is closed * <p> Resetting a scanner discards all of its explicit state * information which may have been changed by invocations of {@link * #useDelimiter}, {@link #useLocale}, or {@link #useRadix}. * <p> An invocation of this method of the form * <tt>scanner.reset()</tt> behaves in exactly the same way as the * scanner.useDelimiter("\\p{javaWhitespace}+") * .useLocale(Locale.getDefault())