All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.io.BufferedReader Maven / Gradle / Ivy

/*

This is not an official specification document, and usage is restricted.

NOTICE


(c) 2005-2007 Sun Microsystems, Inc. All Rights Reserved.

Neither this file nor any files generated from it describe a complete specification, and they may only be used as described below. For example, no permission is given for you to incorporate this file, in whole or in part, in an implementation of a Java specification.

Sun Microsystems Inc. owns the copyright in this file and it is provided to you for informative, as opposed to normative, use. The file and any files generated from it may be used to generate other informative documentation, such as a unified set of documents of API signatures for a platform that includes technologies expressed as Java APIs. The file may also be used to produce "compilation stubs," which allow applications to be compiled and validated for such platforms.

Any work generated from this file, such as unified javadocs or compiled stub files, must be accompanied by this notice in its entirety.

This work corresponds to the API signatures of JSR 219: Foundation Profile 1.1. In the event of a discrepency between this work and the JSR 219 specification, which is available at http://www.jcp.org/en/jsr/detail?id=219, the latter takes precedence. */ package java.io; /** * Read text from a character-input stream, buffering characters so as to * provide for the efficient reading of characters, arrays, and lines. * *

The buffer size may be specified, or the default size may be used. The * default is large enough for most purposes. * *

In general, each read request made of a Reader causes a corresponding * read request to be made of the underlying character or byte stream. It is * therefore advisable to wrap a BufferedReader around any Reader whose read() * operations may be costly, such as FileReaders and InputStreamReaders. For * example, * *

 * BufferedReader in
 *   = new BufferedReader(new FileReader("foo.in"));
 * 
* * will buffer the input from the specified file. Without buffering, each * invocation of read() or readLine() could cause bytes to be read from the * file, converted into characters, and then returned, which can be very * inefficient. * *

Programs that use DataInputStreams for textual input can be localized by * replacing each DataInputStream with an appropriate BufferedReader. * * @see FileReader * @see InputStreamReader * * @version 1.29 10/10/01 * @author Mark Reinhold * @since JDK1.1 */ public class BufferedReader extends Reader { /** * Create a buffering character-input stream that uses an input buffer of * the specified size. * * @param in A Reader * @param sz Input-buffer size * * @exception IllegalArgumentException If sz is <= 0 */ public BufferedReader(Reader in, int sz) { } /** * Create a buffering character-input stream that uses a default-sized * input buffer. * * @param in A Reader */ public BufferedReader(Reader in) { } /** * Read a single character. * * @return The character read, as an integer in the range * 0 to 65535 (0x00-0xffff), or -1 if the * end of the stream has been reached * @exception IOException If an I/O error occurs */ public int read() throws IOException { return 0; } /** * Read characters into a portion of an array. * *

This method implements the general contract of the corresponding * {@link Reader#read(char[], int, int) read} method of the * {@link Reader} class. As an additional convenience, it * attempts to read as many characters as possible by repeatedly invoking * the read method of the underlying stream. This iterated * read continues until one of the following conditions becomes * true:

    * *
  • The specified number of characters have been read, * *
  • The read method of the underlying stream returns * -1, indicating end-of-file, or * *
  • The ready method of the underlying stream * returns false, indicating that further input requests * would block. * *
If the first read on the underlying stream returns * -1 to indicate end-of-file then this method returns * -1. Otherwise this method returns the number of characters * actually read. * *

Subclasses of this class are encouraged, but not required, to * attempt to read as many characters as possible in the same fashion. * *

Ordinarily this method takes characters from this stream's character * buffer, filling it from the underlying stream as necessary. If, * however, the buffer is empty, the mark is not valid, and the requested * length is at least as large as the buffer, then this method will read * characters directly from the underlying stream into the given array. * Thus redundant BufferedReaders will not copy data * unnecessarily. * * @param cbuf Destination buffer * @param off Offset at which to start storing characters * @param len Maximum number of characters to read * * @return The number of characters read, or -1 if the end of the * stream has been reached * * @exception IOException If an I/O error occurs */ public int read(char[] cbuf, int off, int len) throws IOException { return 0; } /** * Read a line of text. A line is considered to be terminated by any one * of a line feed ('\n'), a carriage return ('\r'), or a carriage return * followed immediately by a linefeed. * * @return A String containing the contents of the line, not including * any line-termination characters, or null if the end of the * stream has been reached * * @exception IOException If an I/O error occurs */ public String readLine() throws IOException { return null; } /** * Skip characters. * * @param n The number of characters to skip * * @return The number of characters actually skipped * * @exception IllegalArgumentException If n is negative. * @exception IOException If an I/O error occurs */ public long skip(long n) throws IOException { return -1; } /** * Tell whether this stream is ready to be read. A buffered character * stream is ready if the buffer is not empty, or if the underlying * character stream is ready. * * @exception IOException If an I/O error occurs */ public boolean ready() throws IOException { return false; } /** * Tell whether this stream supports the mark() operation, which it does. */ public boolean markSupported() { return false; } /** * Mark the present position in the stream. Subsequent calls to reset() * will attempt to reposition the stream to this point. * * @param readAheadLimit Limit on the number of characters that may be * read while still preserving the mark. After * reading this many characters, attempting to * reset the stream may fail. A limit value larger * than the size of the input buffer will cause a * new buffer to be allocated whose size is no * smaller than limit. Therefore large values * should be used with care. * * @exception IllegalArgumentException If readAheadLimit is < 0 * @exception IOException If an I/O error occurs */ public void mark(int readAheadLimit) throws IOException { } /** * Reset the stream to the most recent mark. * * @exception IOException If the stream has never been marked, * or if the mark has been invalidated */ public void reset() throws IOException { } /** * Close the stream. * * @exception IOException If an I/O error occurs */ public void close() throws IOException { } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy