3909N/A * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Reads text from a character-input stream, buffering characters so as to 0N/A * provide for the efficient reading of characters, arrays, and lines. 0N/A * <p> The buffer size may be specified, or the default size may be used. The 0N/A * default is large enough for most purposes. 0N/A * <p> In general, each read request made of a Reader causes a corresponding 0N/A * read request to be made of the underlying character or byte stream. It is 0N/A * therefore advisable to wrap a BufferedReader around any Reader whose read() 0N/A * operations may be costly, such as FileReaders and InputStreamReaders. For 0N/A * = new BufferedReader(new FileReader("foo.in")); 0N/A * will buffer the input from the specified file. Without buffering, each 0N/A * invocation of read() or readLine() could cause bytes to be read from the 0N/A * file, converted into characters, and then returned, which can be very 0N/A * <p> Programs that use DataInputStreams for textual input can be localized by 0N/A * replacing each DataInputStream with an appropriate BufferedReader. 0N/A * @see InputStreamReader 3471N/A * @see java.nio.file.Files#newBufferedReader 0N/A * @author Mark Reinhold 0N/A /** If the next character is a line feed, skip it */ 0N/A /** The skipLF flag when the mark was set */ 0N/A * Creates a buffering character-input stream that uses an input buffer of 0N/A * the specified size. 0N/A * @param in A Reader 0N/A * @param sz Input-buffer size 0N/A * @exception IllegalArgumentException If sz is <= 0 0N/A * Creates a buffering character-input stream that uses a default-sized 0N/A * @param in A Reader 0N/A /** Checks to make sure that the stream has not been closed */ 0N/A * Fills the input buffer, taking the mark into account if it is valid. 0N/A /* Gone past read-ahead limit: Invalidate mark */ 0N/A /* Shuffle in the current buffer */ 0N/A /* Reallocate buffer to accommodate read-ahead limit */ 0N/A * Reads a single character. 0N/A * @return The character read, as an integer in the range 0N/A * 0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the 0N/A * end of the stream has been reached 0N/A * @exception IOException If an I/O error occurs 0N/A * Reads characters into a portion of an array, reading from the underlying 0N/A * stream if necessary. 0N/A /* If the requested length is at least as large as the buffer, and 0N/A if there is no mark/reset activity, and if line feeds are not 0N/A being skipped, do not bother to copy the characters into the 0N/A local buffer. In this way buffered streams will cascade 0N/A * Reads characters into a portion of an array. 0N/A * <p> This method implements the general contract of the corresponding 0N/A * <code>{@link Reader#read(char[], int, int) read}</code> method of the 0N/A * <code>{@link Reader}</code> class. As an additional convenience, it 0N/A * attempts to read as many characters as possible by repeatedly invoking 0N/A * the <code>read</code> method of the underlying stream. This iterated 0N/A * <code>read</code> continues until one of the following conditions becomes 0N/A * <li> The specified number of characters have been read, 0N/A * <li> The <code>read</code> method of the underlying stream returns 0N/A * <code>-1</code>, indicating end-of-file, or 0N/A * <li> The <code>ready</code> method of the underlying stream 0N/A * returns <code>false</code>, indicating that further input requests 0N/A * </ul> If the first <code>read</code> on the underlying stream returns 0N/A * <code>-1</code> to indicate end-of-file then this method returns 0N/A * <code>-1</code>. Otherwise this method returns the number of characters 0N/A * <p> Subclasses of this class are encouraged, but not required, to 0N/A * attempt to read as many characters as possible in the same fashion. 0N/A * <p> Ordinarily this method takes characters from this stream's character 0N/A * buffer, filling it from the underlying stream as necessary. If, 0N/A * however, the buffer is empty, the mark is not valid, and the requested 0N/A * length is at least as large as the buffer, then this method will read 0N/A * characters directly from the underlying stream into the given array. 0N/A * Thus redundant <code>BufferedReader</code>s will not copy data 0N/A * @param cbuf Destination buffer 0N/A * @param off Offset at which to start storing characters 0N/A * @param len Maximum number of characters to read 0N/A * @return The number of characters read, or -1 if the end of the 0N/A * stream has been reached 0N/A * @exception IOException If an I/O error occurs 0N/A if (n <=
0)
return n;
0N/A * Reads a line of text. A line is considered to be terminated by any one 0N/A * of a line feed ('\n'), a carriage return ('\r'), or a carriage return 0N/A * followed immediately by a linefeed. 0N/A * @param ignoreLF If true, the next '\n' will be skipped 0N/A * @return A String containing the contents of the line, not including 0N/A * any line-termination characters, or null if the end of the 0N/A * stream has been reached 0N/A * @see java.io.LineNumberReader#readLine() 0N/A * @exception IOException If an I/O error occurs 0N/A /* Skip a leftover '\n', if necessary */ 0N/A if ((c ==
'\n') || (c ==
'\r')) {
0N/A * Reads a line of text. A line is considered to be terminated by any one 0N/A * of a line feed ('\n'), a carriage return ('\r'), or a carriage return 0N/A * followed immediately by a linefeed. 0N/A * @return A String containing the contents of the line, not including 0N/A * any line-termination characters, or null if the end of the 0N/A * stream has been reached 0N/A * @exception IOException If an I/O error occurs 3471N/A * @see java.nio.file.Files#readAllLines 0N/A * @param n The number of characters to skip 0N/A * @return The number of characters actually skipped 0N/A * @exception IllegalArgumentException If <code>n</code> is negative. 0N/A * @exception IOException If an I/O error occurs 0N/A * Tells whether this stream is ready to be read. A buffered character 0N/A * stream is ready if the buffer is not empty, or if the underlying 0N/A * character stream is ready. 0N/A * @exception IOException If an I/O error occurs 0N/A * If newline needs to be skipped and the next char to be read 0N/A * is a newline character, then just skip it right away. 0N/A /* Note that in.ready() will return true if and only if the next 0N/A * read on the stream will not block. 0N/A * Tells whether this stream supports the mark() operation, which it does. 0N/A * Marks the present position in the stream. Subsequent calls to reset() 0N/A * will attempt to reposition the stream to this point. 0N/A * @param readAheadLimit Limit on the number of characters that may be 0N/A * read while still preserving the mark. An attempt 0N/A * to reset the stream after reading characters 0N/A * up to this limit or beyond may fail. 0N/A * A limit value larger than the size of the input 0N/A * buffer will cause a new buffer to be allocated 0N/A * whose size is no smaller than limit. 0N/A * Therefore large values should be used with care. 0N/A * @exception IllegalArgumentException If readAheadLimit is < 0 0N/A * @exception IOException If an I/O error occurs 0N/A * Resets the stream to the most recent mark. 0N/A * @exception IOException If the stream has never been marked, 0N/A * or if the mark has been invalidated 0N/A :
"Stream not marked");