< prev index next >

src/java.base/share/classes/java/util/Scanner.java

Print this page

        

*** 40,63 **** /** * A simple text scanner which can parse primitive types and strings using * regular expressions. * ! * <p>A <code>Scanner</code> breaks its input into tokens using a * delimiter pattern, which by default matches whitespace. The resulting * tokens may then be converted into values of different types using the ! * various <tt>next</tt> methods. * * <p>For example, this code allows a user to read a number from ! * <tt>System.in</tt>: * <blockquote><pre>{@code * Scanner sc = new Scanner(System.in); * int i = sc.nextInt(); * }</pre></blockquote> * ! * <p>As another example, this code allows <code>long</code> types to be ! * assigned from entries in a file <code>myNumbers</code>: * <blockquote><pre>{@code * Scanner sc = new Scanner(new File("myNumbers")); * while (sc.hasNextLong()) { * long aLong = sc.nextLong(); * } --- 40,63 ---- /** * A simple text scanner which can parse primitive types and strings using * regular expressions. * ! * <p>A {@code Scanner} breaks its input into tokens using a * delimiter pattern, which by default matches whitespace. The resulting * tokens may then be converted into values of different types using the ! * various {@code next} methods. * * <p>For example, this code allows a user to read a number from ! * {@code System.in}: * <blockquote><pre>{@code * Scanner sc = new Scanner(System.in); * int i = sc.nextInt(); * }</pre></blockquote> * ! * <p>As another example, this code allows {@code long} types to be ! * assigned from entries in a file {@code myNumbers}: * <blockquote><pre>{@code * Scanner sc = new Scanner(new File("myNumbers")); * while (sc.hasNextLong()) { * long aLong = sc.nextLong(); * }
*** 104,117 **** * <p>A scanning operation may block waiting for input. * * <p>The {@link #next} and {@link #hasNext} methods and their * primitive-type companion methods (such as {@link #nextInt} and * {@link #hasNextInt}) first skip any input that matches the delimiter ! * pattern, and then attempt to return the next token. Both <tt>hasNext</tt> ! * and <tt>next</tt> methods may block waiting for further input. Whether a ! * <tt>hasNext</tt> method blocks has no connection to whether or not its ! * associated <tt>next</tt> method will block. * * <p> The {@link #findInLine}, {@link #findWithinHorizon}, and {@link #skip} * methods operate independently of the delimiter pattern. These methods will * attempt to match the specified pattern with no regard to delimiters in the * input and thus can be used in special circumstances where delimiters are --- 104,117 ---- * <p>A scanning operation may block waiting for input. * * <p>The {@link #next} and {@link #hasNext} methods and their * primitive-type companion methods (such as {@link #nextInt} and * {@link #hasNextInt}) first skip any input that matches the delimiter ! * pattern, and then attempt to return the next token. Both {@code hasNext} ! * and {@code next} methods may block waiting for further input. Whether a ! * {@code hasNext} method blocks has no connection to whether or not its ! * associated {@code next} method will block. * * <p> The {@link #findInLine}, {@link #findWithinHorizon}, and {@link #skip} * methods operate independently of the delimiter pattern. These methods will * attempt to match the specified pattern with no regard to delimiters in the * input and thus can be used in special circumstances where delimiters are
*** 120,155 **** * <p>When a scanner throws an {@link InputMismatchException}, the scanner * will not pass the token that caused the exception, so that it may be * retrieved or skipped via some other method. * * <p>Depending upon the type of delimiting pattern, empty tokens may be ! * returned. For example, the pattern <tt>"\\s+"</tt> will return no empty * tokens since it matches multiple instances of the delimiter. The delimiting ! * pattern <tt>"\\s"</tt> could return empty tokens since it only passes one * space at a time. * * <p> A scanner can read text from any object which implements the {@link * java.lang.Readable} interface. If an invocation of the underlying * readable's {@link java.lang.Readable#read} method throws an {@link * java.io.IOException} then the scanner assumes that the end of the input ! * has been reached. The most recent <tt>IOException</tt> thrown by the * underlying readable can be retrieved via the {@link #ioException} method. * ! * <p>When a <code>Scanner</code> is closed, it will close its input source * if the source implements the {@link java.io.Closeable} interface. * ! * <p>A <code>Scanner</code> is not safe for multithreaded use without * external synchronization. * ! * <p>Unless otherwise mentioned, passing a <code>null</code> parameter into ! * any method of a <code>Scanner</code> will cause a ! * <code>NullPointerException</code> to be thrown. * * <p>A scanner will default to interpreting numbers as decimal unless a * different radix has been set by using the {@link #useRadix} method. The * {@link #reset} method will reset the value of the scanner's radix to ! * <code>10</code> regardless of whether it was previously changed. * * <h3> <a name="localized-numbers">Localized numbers</a> </h3> * * <p> An instance of this class is capable of scanning numbers in the standard * formats as well as in the formats of the scanner's locale. A scanner's --- 120,155 ---- * <p>When a scanner throws an {@link InputMismatchException}, the scanner * will not pass the token that caused the exception, so that it may be * retrieved or skipped via some other method. * * <p>Depending upon the type of delimiting pattern, empty tokens may be ! * returned. For example, the pattern {@code "\\s+"} will return no empty * tokens since it matches multiple instances of the delimiter. The delimiting ! * pattern {@code "\\s"} could return empty tokens since it only passes one * space at a time. * * <p> A scanner can read text from any object which implements the {@link * java.lang.Readable} interface. If an invocation of the underlying * readable's {@link java.lang.Readable#read} method throws an {@link * java.io.IOException} then the scanner assumes that the end of the input ! * has been reached. The most recent {@code IOException} thrown by the * underlying readable can be retrieved via the {@link #ioException} method. * ! * <p>When a {@code Scanner} is closed, it will close its input source * if the source implements the {@link java.io.Closeable} interface. * ! * <p>A {@code Scanner} is not safe for multithreaded use without * external synchronization. * ! * <p>Unless otherwise mentioned, passing a {@code null} parameter into ! * any method of a {@code Scanner} will cause a ! * {@code NullPointerException} to be thrown. * * <p>A scanner will default to interpreting numbers as decimal unless a * different radix has been set by using the {@link #useRadix} method. The * {@link #reset} method will reset the value of the scanner's radix to ! * {@code 10} regardless of whether it was previously changed. * * <h3> <a name="localized-numbers">Localized numbers</a> </h3> * * <p> An instance of this class is capable of scanning numbers in the standard * formats as well as in the formats of the scanner's locale. A scanner's
*** 160,213 **** * scanner's locale to the initial locale regardless of whether it was * previously changed. * * <p>The localized formats are defined in terms of the following parameters, * which for a particular locale are taken from that locale's {@link ! * java.text.DecimalFormat DecimalFormat} object, <tt>df</tt>, and its and * {@link java.text.DecimalFormatSymbols DecimalFormatSymbols} object, ! * <tt>dfs</tt>. * * <blockquote><dl> * <dt><i>LocalGroupSeparator&nbsp;&nbsp;</i> * <dd>The character used to separate thousands groups, ! * <i>i.e.,</i>&nbsp;<tt>dfs.</tt>{@link * java.text.DecimalFormatSymbols#getGroupingSeparator * getGroupingSeparator()} * <dt><i>LocalDecimalSeparator&nbsp;&nbsp;</i> * <dd>The character used for the decimal point, ! * <i>i.e.,</i>&nbsp;<tt>dfs.</tt>{@link * java.text.DecimalFormatSymbols#getDecimalSeparator * getDecimalSeparator()} * <dt><i>LocalPositivePrefix&nbsp;&nbsp;</i> * <dd>The string that appears before a positive number (may ! * be empty), <i>i.e.,</i>&nbsp;<tt>df.</tt>{@link * java.text.DecimalFormat#getPositivePrefix * getPositivePrefix()} * <dt><i>LocalPositiveSuffix&nbsp;&nbsp;</i> * <dd>The string that appears after a positive number (may be ! * empty), <i>i.e.,</i>&nbsp;<tt>df.</tt>{@link * java.text.DecimalFormat#getPositiveSuffix * getPositiveSuffix()} * <dt><i>LocalNegativePrefix&nbsp;&nbsp;</i> * <dd>The string that appears before a negative number (may ! * be empty), <i>i.e.,</i>&nbsp;<tt>df.</tt>{@link * java.text.DecimalFormat#getNegativePrefix * getNegativePrefix()} * <dt><i>LocalNegativeSuffix&nbsp;&nbsp;</i> * <dd>The string that appears after a negative number (may be ! * empty), <i>i.e.,</i>&nbsp;<tt>df.</tt>{@link * java.text.DecimalFormat#getNegativeSuffix * getNegativeSuffix()} * <dt><i>LocalNaN&nbsp;&nbsp;</i> * <dd>The string that represents not-a-number for * floating-point values, ! * <i>i.e.,</i>&nbsp;<tt>dfs.</tt>{@link * java.text.DecimalFormatSymbols#getNaN * getNaN()} * <dt><i>LocalInfinity&nbsp;&nbsp;</i> * <dd>The string that represents infinity for floating-point ! * values, <i>i.e.,</i>&nbsp;<tt>dfs.</tt>{@link * java.text.DecimalFormatSymbols#getInfinity * getInfinity()} * </dl></blockquote> * * <h4> <a name="number-syntax">Number syntax</a> </h4> --- 160,213 ---- * scanner's locale to the initial locale regardless of whether it was * previously changed. * * <p>The localized formats are defined in terms of the following parameters, * which for a particular locale are taken from that locale's {@link ! * java.text.DecimalFormat DecimalFormat} object, {@code df}, and its and * {@link java.text.DecimalFormatSymbols DecimalFormatSymbols} object, ! * {@code dfs}. * * <blockquote><dl> * <dt><i>LocalGroupSeparator&nbsp;&nbsp;</i> * <dd>The character used to separate thousands groups, ! * <i>i.e.,</i>&nbsp;{@code dfs.}{@link * java.text.DecimalFormatSymbols#getGroupingSeparator * getGroupingSeparator()} * <dt><i>LocalDecimalSeparator&nbsp;&nbsp;</i> * <dd>The character used for the decimal point, ! * <i>i.e.,</i>&nbsp;{@code dfs.}{@link * java.text.DecimalFormatSymbols#getDecimalSeparator * getDecimalSeparator()} * <dt><i>LocalPositivePrefix&nbsp;&nbsp;</i> * <dd>The string that appears before a positive number (may ! * be empty), <i>i.e.,</i>&nbsp;{@code df.}{@link * java.text.DecimalFormat#getPositivePrefix * getPositivePrefix()} * <dt><i>LocalPositiveSuffix&nbsp;&nbsp;</i> * <dd>The string that appears after a positive number (may be ! * empty), <i>i.e.,</i>&nbsp;{@code df.}{@link * java.text.DecimalFormat#getPositiveSuffix * getPositiveSuffix()} * <dt><i>LocalNegativePrefix&nbsp;&nbsp;</i> * <dd>The string that appears before a negative number (may ! * be empty), <i>i.e.,</i>&nbsp;{@code df.}{@link * java.text.DecimalFormat#getNegativePrefix * getNegativePrefix()} * <dt><i>LocalNegativeSuffix&nbsp;&nbsp;</i> * <dd>The string that appears after a negative number (may be ! * empty), <i>i.e.,</i>&nbsp;{@code df.}{@link * java.text.DecimalFormat#getNegativeSuffix * getNegativeSuffix()} * <dt><i>LocalNaN&nbsp;&nbsp;</i> * <dd>The string that represents not-a-number for * floating-point values, ! * <i>i.e.,</i>&nbsp;{@code dfs.}{@link * java.text.DecimalFormatSymbols#getNaN * getNaN()} * <dt><i>LocalInfinity&nbsp;&nbsp;</i> * <dd>The string that represents infinity for floating-point ! * values, <i>i.e.,</i>&nbsp;{@code dfs.}{@link * java.text.DecimalFormatSymbols#getInfinity * getInfinity()} * </dl></blockquote> * * <h4> <a name="number-syntax">Number syntax</a> </h4>
*** 217,302 **** * Rmax is the highest digit in the radix being used (for example, Rmax is 9 in base 10). * * <dl> * <dt><i>NonAsciiDigit</i>: * <dd>A non-ASCII character c for which ! * {@link java.lang.Character#isDigit Character.isDigit}<tt>(c)</tt> * returns&nbsp;true * * <dt><i>Non0Digit</i>: ! * <dd><tt>[1-</tt><i>Rmax</i><tt>] | </tt><i>NonASCIIDigit</i> * * <dt><i>Digit</i>: ! * <dd><tt>[0-</tt><i>Rmax</i><tt>] | </tt><i>NonASCIIDigit</i> * * <dt><i>GroupedNumeral</i>: ! * <dd><tt>(&nbsp;</tt><i>Non0Digit</i> ! * <i>Digit</i><tt>? ! * </tt><i>Digit</i><tt>?</tt> ! * <dd>&nbsp;&nbsp;&nbsp;&nbsp;<tt>(&nbsp;</tt><i>LocalGroupSeparator</i> * <i>Digit</i> * <i>Digit</i> ! * <i>Digit</i><tt> )+ )</tt> * * <dt><i>Numeral</i>: ! * <dd><tt>( ( </tt><i>Digit</i><tt>+ ) ! * | </tt><i>GroupedNumeral</i><tt> )</tt> * * <dt><a name="Integer-regex"><i>Integer</i>:</a> ! * <dd><tt>( [-+]? ( </tt><i>Numeral</i><tt> ! * ) )</tt> ! * <dd><tt>| </tt><i>LocalPositivePrefix</i> <i>Numeral</i> * <i>LocalPositiveSuffix</i> ! * <dd><tt>| </tt><i>LocalNegativePrefix</i> <i>Numeral</i> * <i>LocalNegativeSuffix</i> * * <dt><i>DecimalNumeral</i>: * <dd><i>Numeral</i> ! * <dd><tt>| </tt><i>Numeral</i> * <i>LocalDecimalSeparator</i> ! * <i>Digit</i><tt>*</tt> ! * <dd><tt>| </tt><i>LocalDecimalSeparator</i> ! * <i>Digit</i><tt>+</tt> * * <dt><i>Exponent</i>: ! * <dd><tt>( [eE] [+-]? </tt><i>Digit</i><tt>+ )</tt> * * <dt><a name="Decimal-regex"><i>Decimal</i>:</a> ! * <dd><tt>( [-+]? </tt><i>DecimalNumeral</i> ! * <i>Exponent</i><tt>? )</tt> ! * <dd><tt>| </tt><i>LocalPositivePrefix</i> * <i>DecimalNumeral</i> * <i>LocalPositiveSuffix</i> ! * <i>Exponent</i><tt>?</tt> ! * <dd><tt>| </tt><i>LocalNegativePrefix</i> * <i>DecimalNumeral</i> * <i>LocalNegativeSuffix</i> ! * <i>Exponent</i><tt>?</tt> * * <dt><i>HexFloat</i>: ! * <dd><tt>[-+]? 0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+ ! * ([pP][-+]?[0-9]+)?</tt> * * <dt><i>NonNumber</i>: ! * <dd><tt>NaN ! * | </tt><i>LocalNan</i><tt> * | Infinity ! * | </tt><i>LocalInfinity</i> * * <dt><i>SignedNonNumber</i>: ! * <dd><tt>( [-+]? </tt><i>NonNumber</i><tt> )</tt> ! * <dd><tt>| </tt><i>LocalPositivePrefix</i> * <i>NonNumber</i> * <i>LocalPositiveSuffix</i> ! * <dd><tt>| </tt><i>LocalNegativePrefix</i> * <i>NonNumber</i> * <i>LocalNegativeSuffix</i> * * <dt><a name="Float-regex"><i>Float</i></a>: * <dd><i>Decimal</i> ! * <tt>| </tt><i>HexFloat</i> ! * <tt>| </tt><i>SignedNonNumber</i> * * </dl> * <p>Whitespace is not significant in the above regular expressions. * * @since 1.5 --- 217,302 ---- * Rmax is the highest digit in the radix being used (for example, Rmax is 9 in base 10). * * <dl> * <dt><i>NonAsciiDigit</i>: * <dd>A non-ASCII character c for which ! * {@link java.lang.Character#isDigit Character.isDigit}{@code (c)} * returns&nbsp;true * * <dt><i>Non0Digit</i>: ! * <dd>{@code [1-}<i>Rmax</i>{@code ] | }<i>NonASCIIDigit</i> * * <dt><i>Digit</i>: ! * <dd>{@code [0-}<i>Rmax</i>{@code ] | }<i>NonASCIIDigit</i> * * <dt><i>GroupedNumeral</i>: ! * <dd><code>(&nbsp;</code><i>Non0Digit</i> ! * <i>Digit</i>{@code ? ! * }<i>Digit</i>{@code ?} ! * <dd>&nbsp;&nbsp;&nbsp;&nbsp;<code>(&nbsp;</code><i>LocalGroupSeparator</i> * <i>Digit</i> * <i>Digit</i> ! * <i>Digit</i>{@code )+ )} * * <dt><i>Numeral</i>: ! * <dd>{@code ( ( }<i>Digit</i>{@code + ) ! * | }<i>GroupedNumeral</i>{@code )} * * <dt><a name="Integer-regex"><i>Integer</i>:</a> ! * <dd>{@code ( [-+]? ( }<i>Numeral</i>{@code ! * ) )} ! * <dd>{@code | }<i>LocalPositivePrefix</i> <i>Numeral</i> * <i>LocalPositiveSuffix</i> ! * <dd>{@code | }<i>LocalNegativePrefix</i> <i>Numeral</i> * <i>LocalNegativeSuffix</i> * * <dt><i>DecimalNumeral</i>: * <dd><i>Numeral</i> ! * <dd>{@code | }<i>Numeral</i> * <i>LocalDecimalSeparator</i> ! * <i>Digit</i>{@code *} ! * <dd>{@code | }<i>LocalDecimalSeparator</i> ! * <i>Digit</i>{@code +} * * <dt><i>Exponent</i>: ! * <dd>{@code ( [eE] [+-]? }<i>Digit</i>{@code + )} * * <dt><a name="Decimal-regex"><i>Decimal</i>:</a> ! * <dd>{@code ( [-+]? }<i>DecimalNumeral</i> ! * <i>Exponent</i>{@code ? )} ! * <dd>{@code | }<i>LocalPositivePrefix</i> * <i>DecimalNumeral</i> * <i>LocalPositiveSuffix</i> ! * <i>Exponent</i>{@code ?} ! * <dd>{@code | }<i>LocalNegativePrefix</i> * <i>DecimalNumeral</i> * <i>LocalNegativeSuffix</i> ! * <i>Exponent</i>{@code ?} * * <dt><i>HexFloat</i>: ! * <dd>{@code [-+]? 0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+ ! * ([pP][-+]?[0-9]+)?} * * <dt><i>NonNumber</i>: ! * <dd>{@code NaN ! * | }<i>LocalNan</i>{@code * | Infinity ! * | }<i>LocalInfinity</i> * * <dt><i>SignedNonNumber</i>: ! * <dd>{@code ( [-+]? }<i>NonNumber</i>{@code )} ! * <dd>{@code | }<i>LocalPositivePrefix</i> * <i>NonNumber</i> * <i>LocalPositiveSuffix</i> ! * <dd>{@code | }<i>LocalNegativePrefix</i> * <i>NonNumber</i> * <i>LocalNegativeSuffix</i> * * <dt><a name="Float-regex"><i>Float</i></a>: * <dd><i>Decimal</i> ! * {@code | }<i>HexFloat</i> ! * {@code | }<i>SignedNonNumber</i> * * </dl> * <p>Whitespace is not significant in the above regular expressions. * * @since 1.5
*** 519,529 **** } // Constructors /** ! * Constructs a <code>Scanner</code> that returns values scanned * from the specified source delimited by the specified pattern. * * @param source A character source implementing the Readable interface * @param pattern A delimiting pattern */ --- 519,529 ---- } // Constructors /** ! * Constructs a {@code Scanner} that returns values scanned * from the specified source delimited by the specified pattern. * * @param source A character source implementing the Readable interface * @param pattern A delimiting pattern */
*** 539,560 **** matcher.useAnchoringBounds(false); useLocale(Locale.getDefault(Locale.Category.FORMAT)); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified source. * * @param source A character source implementing the {@link Readable} * interface */ public Scanner(Readable source) { this(Objects.requireNonNull(source, "source"), WHITESPACE_PATTERN); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified input stream. Bytes from the stream are converted * into characters using the underlying platform's * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. * * @param source An input stream to be scanned --- 539,560 ---- matcher.useAnchoringBounds(false); useLocale(Locale.getDefault(Locale.Category.FORMAT)); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified source. * * @param source A character source implementing the {@link Readable} * interface */ public Scanner(Readable source) { this(Objects.requireNonNull(source, "source"), WHITESPACE_PATTERN); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified input stream. Bytes from the stream are converted * into characters using the underlying platform's * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. * * @param source An input stream to be scanned
*** 562,572 **** public Scanner(InputStream source) { this(new InputStreamReader(source), WHITESPACE_PATTERN); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified input stream. Bytes from the stream are converted * into characters using the specified charset. * * @param source An input stream to be scanned * @param charsetName The encoding type used to convert bytes from the --- 562,572 ---- public Scanner(InputStream source) { this(new InputStreamReader(source), WHITESPACE_PATTERN); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified input stream. Bytes from the stream are converted * into characters using the specified charset. * * @param source An input stream to be scanned * @param charsetName The encoding type used to convert bytes from the
*** 597,607 **** private static Readable makeReadable(InputStream source, Charset charset) { return new InputStreamReader(source, charset); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified file. Bytes from the file are converted into * characters using the underlying platform's * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. * * @param source A file to be scanned --- 597,607 ---- private static Readable makeReadable(InputStream source, Charset charset) { return new InputStreamReader(source, charset); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified file. Bytes from the file are converted into * characters using the underlying platform's * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. * * @param source A file to be scanned
*** 610,620 **** public Scanner(File source) throws FileNotFoundException { this((ReadableByteChannel)(new FileInputStream(source).getChannel())); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified file. Bytes from the file are converted into * characters using the specified charset. * * @param source A file to be scanned * @param charsetName The encoding type used to convert bytes from the file --- 610,620 ---- public Scanner(File source) throws FileNotFoundException { this((ReadableByteChannel)(new FileInputStream(source).getChannel())); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified file. Bytes from the file are converted into * characters using the specified charset. * * @param source A file to be scanned * @param charsetName The encoding type used to convert bytes from the file
*** 648,658 **** CharsetDecoder dec) { return Channels.newReader(source, dec, -1); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified file. Bytes from the file are converted into * characters using the underlying platform's * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. * * @param source --- 648,658 ---- CharsetDecoder dec) { return Channels.newReader(source, dec, -1); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified file. Bytes from the file are converted into * characters using the underlying platform's * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. * * @param source
*** 667,677 **** { this(Files.newInputStream(source)); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified file. Bytes from the file are converted into * characters using the specified charset. * * @param source * the path to the file to be scanned --- 667,677 ---- { this(Files.newInputStream(source)); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified file. Bytes from the file are converted into * characters using the specified charset. * * @param source * the path to the file to be scanned
*** 691,711 **** private Scanner(Path source, Charset charset) throws IOException { this(makeReadable(Files.newInputStream(source), charset)); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified string. * * @param source A string to scan */ public Scanner(String source) { this(new StringReader(source), WHITESPACE_PATTERN); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified channel. Bytes from the source are converted into * characters using the underlying platform's * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. * * @param source A channel to scan --- 691,711 ---- private Scanner(Path source, Charset charset) throws IOException { this(makeReadable(Files.newInputStream(source), charset)); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified string. * * @param source A string to scan */ public Scanner(String source) { this(new StringReader(source), WHITESPACE_PATTERN); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified channel. Bytes from the source are converted into * characters using the underlying platform's * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. * * @param source A channel to scan
*** 718,728 **** private static Readable makeReadable(ReadableByteChannel source) { return makeReadable(source, Charset.defaultCharset().newDecoder()); } /** ! * Constructs a new <code>Scanner</code> that produces values scanned * from the specified channel. Bytes from the source are converted into * characters using the specified charset. * * @param source A channel to scan * @param charsetName The encoding type used to convert bytes from the --- 718,728 ---- private static Readable makeReadable(ReadableByteChannel source) { return makeReadable(source, Charset.defaultCharset().newDecoder()); } /** ! * Constructs a new {@code Scanner} that produces values scanned * from the specified channel. Bytes from the source are converted into * characters using the specified charset. * * @param source A channel to scan * @param charsetName The encoding type used to convert bytes from the
*** 1075,1085 **** /** * Closes this scanner. * * <p> If this scanner has not yet been closed then if its underlying * {@linkplain java.lang.Readable readable} also implements the {@link ! * java.io.Closeable} interface then the readable's <tt>close</tt> method * will be invoked. If this scanner is already closed then invoking this * method will have no effect. * * <p>Attempting to perform search operations after a scanner has * been closed will result in an {@link IllegalStateException}. --- 1075,1085 ---- /** * Closes this scanner. * * <p> If this scanner has not yet been closed then if its underlying * {@linkplain java.lang.Readable readable} also implements the {@link ! * java.io.Closeable} interface then the readable's {@code close} method * will be invoked. If this scanner is already closed then invoking this * method will have no effect. * * <p>Attempting to perform search operations after a scanner has * been closed will result in an {@link IllegalStateException}.
*** 1099,1120 **** source = null; closed = true; } /** ! * Returns the <code>IOException</code> last thrown by this ! * <code>Scanner</code>'s underlying <code>Readable</code>. This method ! * returns <code>null</code> if no such exception exists. * * @return the last exception thrown by this scanner's readable */ public IOException ioException() { return lastException; } /** ! * Returns the <code>Pattern</code> this <code>Scanner</code> is currently * using to match delimiters. * * @return this scanner's delimiting pattern. */ public Pattern delimiter() { --- 1099,1120 ---- source = null; closed = true; } /** ! * Returns the {@code IOException} last thrown by this ! * {@code Scanner}'s underlying {@code Readable}. This method ! * returns {@code null} if no such exception exists. * * @return the last exception thrown by this scanner's readable */ public IOException ioException() { return lastException; } /** ! * Returns the {@code Pattern} this {@code Scanner} is currently * using to match delimiters. * * @return this scanner's delimiting pattern. */ public Pattern delimiter() {
*** 1132,1146 **** return this; } /** * Sets this scanner's delimiting pattern to a pattern constructed from ! * the specified <code>String</code>. * * <p> An invocation of this method of the form ! * <tt>useDelimiter(pattern)</tt> behaves in exactly the same way as the ! * invocation <tt>useDelimiter(Pattern.compile(pattern))</tt>. * * <p> Invoking the {@link #reset} method will set the scanner's delimiter * to the <a href= "#default-delimiter">default</a>. * * @param pattern A string specifying a delimiting pattern --- 1132,1146 ---- return this; } /** * Sets this scanner's delimiting pattern to a pattern constructed from ! * the specified {@code String}. * * <p> An invocation of this method of the form ! * {@code useDelimiter(pattern)} behaves in exactly the same way as the ! * invocation {@code useDelimiter(Pattern.compile(pattern))}. * * <p> Invoking the {@link #reset} method will set the scanner's delimiter * to the <a href= "#default-delimiter">default</a>. * * @param pattern A string specifying a delimiting pattern
*** 1234,1249 **** * * <p>A scanner's radix affects elements of its default * number matching regular expressions; see * <a href= "#localized-numbers">localized numbers</a> above. * ! * <p>If the radix is less than <code>Character.MIN_RADIX</code> ! * or greater than <code>Character.MAX_RADIX</code>, then an ! * <code>IllegalArgumentException</code> is thrown. * * <p>Invoking the {@link #reset} method will set the scanner's radix to ! * <code>10</code>. * * @param radix The radix to use when scanning numbers * @return this scanner * @throws IllegalArgumentException if radix is out of range */ --- 1234,1249 ---- * * <p>A scanner's radix affects elements of its default * number matching regular expressions; see * <a href= "#localized-numbers">localized numbers</a> above. * ! * <p>If the radix is less than {@code Character.MIN_RADIX} ! * or greater than {@code Character.MAX_RADIX}, then an ! * {@code IllegalArgumentException} is thrown. * * <p>Invoking the {@link #reset} method will set the scanner's radix to ! * {@code 10}. * * @param radix The radix to use when scanning numbers * @return this scanner * @throws IllegalArgumentException if radix is out of range */
*** 1269,1287 **** } } /** * Returns the match result of the last scanning operation performed ! * by this scanner. This method throws <code>IllegalStateException</code> * if no match has been performed, or if the last match was * not successful. * ! * <p>The various <code>next</code>methods of <code>Scanner</code> * make a match result available if they complete without throwing an * exception. For instance, after an invocation of the {@link #nextInt} * method that returned an int, this method returns a ! * <code>MatchResult</code> for the search of the * <a href="#Integer-regex"><i>Integer</i></a> regular expression * defined above. Similarly the {@link #findInLine}, * {@link #findWithinHorizon}, and {@link #skip} methods will make a * match available if they succeed. * --- 1269,1287 ---- } } /** * Returns the match result of the last scanning operation performed ! * by this scanner. This method throws {@code IllegalStateException} * if no match has been performed, or if the last match was * not successful. * ! * <p>The various {@code next}methods of {@code Scanner} * make a match result available if they complete without throwing an * exception. For instance, after an invocation of the {@link #nextInt} * method that returned an int, this method returns a ! * {@code MatchResult} for the search of the * <a href="#Integer-regex"><i>Integer</i></a> regular expression * defined above. Similarly the {@link #findInLine}, * {@link #findWithinHorizon}, and {@link #skip} methods will make a * match available if they succeed. *
*** 1293,1304 **** throw new IllegalStateException("No match result available"); return matcher.toMatchResult(); } /** ! * <p>Returns the string representation of this <code>Scanner</code>. The ! * string representation of a <code>Scanner</code> contains information * that may be useful for debugging. The exact format is unspecified. * * @return The string representation of this scanner */ public String toString() { --- 1293,1304 ---- throw new IllegalStateException("No match result available"); return matcher.toMatchResult(); } /** ! * <p>Returns the string representation of this {@code Scanner}. The ! * string representation of a {@code Scanner} contains information * that may be useful for debugging. The exact format is unspecified. * * @return The string representation of this scanner */ public String toString() {
*** 1345,1355 **** /** * Finds and returns the next complete token from this scanner. * A complete token is preceded and followed by input that matches * the delimiter pattern. This method may block while waiting for input * to scan, even if a previous invocation of {@link #hasNext} returned ! * <code>true</code>. * * @return the next token * @throws NoSuchElementException if no more tokens are available * @throws IllegalStateException if this scanner is closed * @see java.util.Iterator --- 1345,1355 ---- /** * Finds and returns the next complete token from this scanner. * A complete token is preceded and followed by input that matches * the delimiter pattern. This method may block while waiting for input * to scan, even if a previous invocation of {@link #hasNext} returned ! * {@code true}. * * @return the next token * @throws NoSuchElementException if no more tokens are available * @throws IllegalStateException if this scanner is closed * @see java.util.Iterator
*** 1372,1382 **** } } /** * The remove operation is not supported by this implementation of ! * <code>Iterator</code>. * * @throws UnsupportedOperationException if this method is invoked. * @see java.util.Iterator */ public void remove() { --- 1372,1382 ---- } } /** * The remove operation is not supported by this implementation of ! * {@code Iterator}. * * @throws UnsupportedOperationException if this method is invoked. * @see java.util.Iterator */ public void remove() {
*** 1385,1397 **** /** * Returns true if the next token matches the pattern constructed from the * specified string. The scanner does not advance past any input. * ! * <p> An invocation of this method of the form <tt>hasNext(pattern)</tt> * behaves in exactly the same way as the invocation ! * <tt>hasNext(Pattern.compile(pattern))</tt>. * * @param pattern a string specifying the pattern to scan * @return true if and only if this scanner has another token matching * the specified pattern * @throws IllegalStateException if this scanner is closed --- 1385,1397 ---- /** * Returns true if the next token matches the pattern constructed from the * specified string. The scanner does not advance past any input. * ! * <p> An invocation of this method of the form {@code hasNext(pattern)} * behaves in exactly the same way as the invocation ! * {@code hasNext(Pattern.compile(pattern))}. * * @param pattern a string specifying the pattern to scan * @return true if and only if this scanner has another token matching * the specified pattern * @throws IllegalStateException if this scanner is closed
*** 1403,1415 **** /** * Returns the next token if it matches the pattern constructed from the * specified string. If the match is successful, the scanner advances * past the input that matched the pattern. * ! * <p> An invocation of this method of the form <tt>next(pattern)</tt> * behaves in exactly the same way as the invocation ! * <tt>next(Pattern.compile(pattern))</tt>. * * @param pattern a string specifying the pattern to scan * @return the next token * @throws NoSuchElementException if no such tokens are available * @throws IllegalStateException if this scanner is closed --- 1403,1415 ---- /** * Returns the next token if it matches the pattern constructed from the * specified string. If the match is successful, the scanner advances * past the input that matched the pattern. * ! * <p> An invocation of this method of the form {@code next(pattern)} * behaves in exactly the same way as the invocation ! * {@code next(Pattern.compile(pattern))}. * * @param pattern a string specifying the pattern to scan * @return the next token * @throws NoSuchElementException if no such tokens are available * @throws IllegalStateException if this scanner is closed
*** 1450,1460 **** } /** * Returns the next token if it matches the specified pattern. This * method may block while waiting for input to scan, even if a previous ! * invocation of {@link #hasNext(Pattern)} returned <code>true</code>. * If the match is successful, the scanner advances past the input that * matched the pattern. * * @param pattern the pattern to scan for * @return the next token --- 1450,1460 ---- } /** * Returns the next token if it matches the specified pattern. This * method may block while waiting for input to scan, even if a previous ! * invocation of {@link #hasNext(Pattern)} returned {@code true}. * If the match is successful, the scanner advances past the input that * matched the pattern. * * @param pattern the pattern to scan for * @return the next token
*** 1552,1564 **** /** * Attempts to find the next occurrence of a pattern constructed from the * specified string, ignoring delimiters. * ! * <p>An invocation of this method of the form <tt>findInLine(pattern)</tt> * behaves in exactly the same way as the invocation ! * <tt>findInLine(Pattern.compile(pattern))</tt>. * * @param pattern a string specifying the pattern to search for * @return the text that matched the specified pattern * @throws IllegalStateException if this scanner is closed */ --- 1552,1564 ---- /** * Attempts to find the next occurrence of a pattern constructed from the * specified string, ignoring delimiters. * ! * <p>An invocation of this method of the form {@code findInLine(pattern)} * behaves in exactly the same way as the invocation ! * {@code findInLine(Pattern.compile(pattern))}. * * @param pattern a string specifying the pattern to search for * @return the text that matched the specified pattern * @throws IllegalStateException if this scanner is closed */
*** 1570,1580 **** * Attempts to find the next occurrence of the specified pattern ignoring * delimiters. If the pattern is found before the next line separator, the * scanner advances past the input that matched and returns the string that * matched the pattern. * If no such pattern is detected in the input up to the next line ! * separator, then <code>null</code> is returned and the scanner's * position is unchanged. This method may block waiting for input that * matches the pattern. * * <p>Since this method continues to search through the input looking * for the specified pattern, it may buffer all of the input searching for --- 1570,1580 ---- * Attempts to find the next occurrence of the specified pattern ignoring * delimiters. If the pattern is found before the next line separator, the * scanner advances past the input that matched and returns the string that * matched the pattern. * If no such pattern is detected in the input up to the next line ! * separator, then {@code null} is returned and the scanner's * position is unchanged. This method may block waiting for input that * matches the pattern. * * <p>Since this method continues to search through the input looking * for the specified pattern, it may buffer all of the input searching for
*** 1619,1631 **** /** * Attempts to find the next occurrence of a pattern constructed from the * specified string, ignoring delimiters. * * <p>An invocation of this method of the form ! * <tt>findWithinHorizon(pattern)</tt> behaves in exactly the same way as * the invocation ! * <tt>findWithinHorizon(Pattern.compile(pattern, horizon))</tt>. * * @param pattern a string specifying the pattern to search for * @param horizon the search horizon * @return the text that matched the specified pattern * @throws IllegalStateException if this scanner is closed --- 1619,1631 ---- /** * Attempts to find the next occurrence of a pattern constructed from the * specified string, ignoring delimiters. * * <p>An invocation of this method of the form ! * {@code findWithinHorizon(pattern)} behaves in exactly the same way as * the invocation ! * {@code findWithinHorizon(Pattern.compile(pattern, horizon))}. * * @param pattern a string specifying the pattern to search for * @param horizon the search horizon * @return the text that matched the specified pattern * @throws IllegalStateException if this scanner is closed
*** 1643,1660 **** * scanner advances past the input that matched and returns the string * 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 --- 1643,1660 ---- * scanner advances past the input that matched and returns the string * 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 * 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}, 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
*** 1694,1713 **** * This method will skip input if an anchored match of the specified * pattern succeeds. * * <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 * amount of input. * * <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 * @return this scanner * @throws NoSuchElementException if the specified pattern is not found * @throws IllegalStateException if this scanner is closed --- 1694,1713 ---- * This method will skip input if an anchored match of the specified * pattern succeeds. * * <p>If a match to the specified pattern is not found at the * current position, then no input is skipped and a ! * {@code NoSuchElementException} 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 * amount of input. * * <p>Note that it is possible to skip something without risking a ! * {@code NoSuchElementException} by using a pattern that can ! * match nothing, e.g., {@code sc.skip("[ \t]*")}. * * @param pattern a string specifying the pattern to skip over * @return this scanner * @throws NoSuchElementException if the specified pattern is not found * @throws IllegalStateException if this scanner is closed
*** 1735,1747 **** /** * Skips input that matches a pattern constructed from the specified * string. * ! * <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 * @return this scanner * @throws IllegalStateException if this scanner is closed */ --- 1735,1747 ---- /** * Skips input that matches a pattern constructed from the specified * string. * ! * <p> An invocation of this method of the form {@code skip(pattern)} * behaves in exactly the same way as the invocation ! * {@code skip(Pattern.compile(pattern))}. * * @param pattern a string specifying the pattern to skip over * @return this scanner * @throws IllegalStateException if this scanner is closed */
*** 1765,1775 **** return hasNext(boolPattern()); } /** * 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 * matched. * * @return the boolean scanned from the input --- 1765,1775 ---- return hasNext(boolPattern()); } /** * Scans the next token of the input into a boolean value and returns ! * that value. This method will throw {@code InputMismatchException} * if the next token cannot be translated into a valid boolean value. * If the match is successful, the scanner advances past the input that * matched. * * @return the boolean scanned from the input
*** 1820,1837 **** } return result; } /** ! * 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 --- 1820,1837 ---- } return result; } /** ! * Scans the next token of the input as a {@code byte}. * * <p> An invocation of this method of the form ! * {@code nextByte()} behaves in exactly the same way as the ! * invocation {@code nextByte(radix)}, where {@code radix} * is the default radix of this scanner. * ! * @return the {@code byte} 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
*** 1839,1867 **** public byte nextByte() { return nextByte(defaultRadix); } /** ! * 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 * specified radix. * * @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 --- 1839,1867 ---- public byte nextByte() { return nextByte(defaultRadix); } /** ! * Scans the next token of the input as a {@code byte}. ! * This method will throw {@code InputMismatchException} * 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 {@code byte} 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 * specified radix. * * @param radix the radix used to interpret the token as a byte value ! * @return the {@code byte} 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
*** 1926,1943 **** } return result; } /** ! * 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 --- 1926,1943 ---- } return result; } /** ! * Scans the next token of the input as a {@code short}. * * <p> An invocation of this method of the form ! * {@code nextShort()} behaves in exactly the same way as the ! * invocation {@code nextShort(radix)}, where {@code radix} * is the default radix of this scanner. * ! * @return the {@code short} 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
*** 1945,1973 **** public short nextShort() { return nextShort(defaultRadix); } /** ! * 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 * specified radix. * * @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 --- 1945,1973 ---- public short nextShort() { return nextShort(defaultRadix); } /** ! * Scans the next token of the input as a {@code short}. ! * This method will throw {@code InputMismatchException} * 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 {@code short} 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 * specified radix. * * @param radix the radix used to interpret the token as a short value ! * @return the {@code short} 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
*** 2056,2073 **** result = "-" + result; return result; } /** ! * 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 --- 2056,2073 ---- result = "-" + result; return result; } /** ! * Scans the next token of the input as an {@code int}. * * <p> An invocation of this method of the form ! * {@code nextInt()} behaves in exactly the same way as the ! * invocation {@code nextInt(radix)}, where {@code radix} * is the default radix of this scanner. * ! * @return the {@code int} 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
*** 2075,2103 **** public int nextInt() { return nextInt(defaultRadix); } /** ! * 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 * specified radix. * * @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 --- 2075,2103 ---- public int nextInt() { return nextInt(defaultRadix); } /** ! * Scans the next token of the input as an {@code int}. ! * This method will throw {@code InputMismatchException} * 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 {@code int} 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 * specified radix. * * @param radix the radix used to interpret the token as an int value ! * @return the {@code int} 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
*** 2162,2179 **** } return result; } /** ! * 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 --- 2162,2179 ---- } return result; } /** ! * Scans the next token of the input as a {@code long}. * * <p> An invocation of this method of the form ! * {@code nextLong()} behaves in exactly the same way as the ! * invocation {@code nextLong(radix)}, where {@code radix} * is the default radix of this scanner. * ! * @return the {@code long} 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
*** 2181,2209 **** public long nextLong() { return nextLong(defaultRadix); } /** ! * 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 * specified radix. * * @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 --- 2181,2209 ---- public long nextLong() { return nextLong(defaultRadix); } /** ! * Scans the next token of the input as a {@code long}. ! * This method will throw {@code InputMismatchException} * 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 {@code long} 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 * specified radix. * * @param radix the radix used to interpret the token as an int value ! * @return the {@code long} 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
*** 2304,2333 **** } return result; } /** ! * 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 * appropriate. * ! * @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 --- 2304,2333 ---- } return result; } /** ! * Scans the next token of the input as a {@code float}. ! * This method will throw {@code InputMismatchException} * 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 {@code float} 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 * appropriate. * ! * @return the {@code float} 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
*** 2371,2400 **** } return result; } /** ! * 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 * 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>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 * appropriate. * ! * @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 --- 2371,2400 ---- } return result; } /** ! * Scans the next token of the input as a {@code double}. ! * This method will throw {@code InputMismatchException} * if the next token cannot be translated into a valid double value. * 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 {@code double} 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 * appropriate. * ! * @return the {@code double} 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
*** 2419,2449 **** // 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 * input. * * @return true if and only if this scanner's next token is a valid ! * <code>BigInteger</code> * @throws IllegalStateException if this scanner is closed */ public boolean hasNextBigInteger() { return hasNextBigInteger(defaultRadix); } /** * 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 * any input. * * @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 */ public boolean hasNextBigInteger(int radix) { setRadix(radix); boolean result = hasNext(integerPattern()); --- 2419,2449 ---- // 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} in the default radix using the * {@link #nextBigInteger} method. The scanner does not advance past any * input. * * @return true if and only if this scanner's next token is a valid ! * {@code BigInteger} * @throws IllegalStateException if this scanner is closed */ public boolean hasNextBigInteger() { return hasNextBigInteger(defaultRadix); } /** * Returns true if the next token in this scanner's input can be ! * interpreted as a {@code BigInteger} in the specified radix using * the {@link #nextBigInteger} method. The scanner does not advance past * any input. * * @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} * @throws IllegalStateException if this scanner is closed */ public boolean hasNextBigInteger(int radix) { setRadix(radix); boolean result = hasNext(integerPattern());
*** 2463,2477 **** /** * Scans the next token of the input as a {@link java.math.BigInteger * 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 --- 2463,2477 ---- /** * Scans the next token of the input as a {@link java.math.BigInteger * BigInteger}. * * <p> An invocation of this method of the form ! * {@code nextBigInteger()} behaves in exactly the same way as the ! * invocation {@code nextBigInteger(radix)}, where {@code radix} * is the default radix of this scanner. * ! * @return the {@code BigInteger} 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
*** 2484,2502 **** * Scans the next token of the input as a {@link java.math.BigInteger * 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 --- 2484,2502 ---- * Scans the next token of the input as a {@link java.math.BigInteger * 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 {@code BigInteger} 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 {@code BigInteger} 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
*** 2523,2538 **** } } /** * 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 * input. * * @return true if and only if this scanner's next token is a valid ! * <code>BigDecimal</code> * @throws IllegalStateException if this scanner is closed */ public boolean hasNextBigDecimal() { setRadix(10); boolean result = hasNext(decimalPattern()); --- 2523,2538 ---- } } /** * Returns true if the next token in this scanner's input can be ! * interpreted as a {@code BigDecimal} using the * {@link #nextBigDecimal} method. The scanner does not advance past any * input. * * @return true if and only if this scanner's next token is a valid ! * {@code BigDecimal} * @throws IllegalStateException if this scanner is closed */ public boolean hasNextBigDecimal() { setRadix(10); boolean result = hasNext(decimalPattern());
*** 2551,2568 **** * Scans the next token of the input as a {@link java.math.BigDecimal * 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)} * constructor. * ! * @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 --- 2551,2568 ---- * Scans the next token of the input as a {@link java.math.BigDecimal * 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 {@code BigDecimal} 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)} * constructor. * ! * @return the {@code BigDecimal} 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
*** 2592,2602 **** * <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 * invocation * * <blockquote><pre>{@code * scanner.useDelimiter("\\p{javaWhitespace}+") * .useLocale(Locale.getDefault(Locale.Category.FORMAT)) --- 2592,2602 ---- * <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 ! * {@code scanner.reset()} behaves in exactly the same way as the * invocation * * <blockquote><pre>{@code * scanner.useDelimiter("\\p{javaWhitespace}+") * .useLocale(Locale.getDefault(Locale.Category.FORMAT))
< prev index next >