java::io::BufferedInputStream Class Reference

Inheritance diagram for java::io::BufferedInputStream:

Inheritance graph
java::lang::Objectjava::lang::Interfacejava::io::InputStream
[legend]
Collaboration diagram for java::io::BufferedInputStream:

Collaboration graph
java::lang::Objectjava::lang::Interfacejava::lang::ObjectRefjava::io::InputStreamjava::lang::Comparable
[legend]

List of all members.


Detailed Description

A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the mark and reset methods.

When the BufferedInputStream is created, an internal buffer array is created. As bytes from the stream are read or skipped, the internal buffer is refilled as necessary from the contained input stream, many bytes at a time. The mark operation remembers a point in the input stream and the reset operation causes all the bytes read since the most recent mark operation to be reread before new bytes are taken from the contained input stream.

Author:
Arthur van Hoff
Version:
1.42, 12/03/01
Since:
JDK1.0

Public Member Functions

 BufferedInputStream (const Ref< InputStream > &in=0, jint size=2048)
 Creates a BufferedInputStream by assigning the argument in to the field this.in so as to remember it for later use.
virtual jint read ()
 Reads the next byte of data from this input stream.
virtual jint read (Array< jbyte > &b, jint off=0, jint len=-1)
 Reads up to len bytes of data from this input stream into an array of bytes.
virtual jlong skip (jlong n)
 Skips over and discards n bytes of data from the input stream.
virtual jint available ()
 Returns the number of bytes that can be read from this input stream without blocking.
virtual void close ()
 Closes this input stream and releases any system resources associated with the stream.
virtual void mark (jint readlimit=0)
 Marks the current position in this input stream.
virtual void reset ()
 Repositions this stream to the position at the time the mark method was last called on this input stream.
virtual jboolean markSupported ()
 Tests if this input stream supports the mark and reset methods.

Constructor & Destructor Documentation

java::io::BufferedInputStream::BufferedInputStream ( const Ref< InputStream > &  in = 0,
jint  size = 2048 
)

Creates a BufferedInputStream by assigning the argument in to the field this.in so as to remember it for later use.

Parameters:
in the underlying input stream, or null if this instance is to be created without an underlying stream.


Member Function Documentation

virtual jint java::io::BufferedInputStream::read (  )  [virtual]

Reads the next byte of data from this input stream.

The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

This method simply performs in.read() and returns the result.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Exceptions:
IOException if an I/O error occurs.

Implements java::io::InputStream.

virtual jint java::io::BufferedInputStream::read ( Array< jbyte > &  b,
jint  off = 0,
jint  len = -1 
) [virtual]

Reads up to len bytes of data from this input stream into an array of bytes.

This method blocks until some input is available.

This method simply performs in.read(b, off, len) and returns the result.

Parameters:
b the buffer into which the data is read.
off the start offset of the data.
len the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Exceptions:
IOException if an I/O error occurs.

Implements java::io::InputStream.

virtual jlong java::io::BufferedInputStream::skip ( jlong  n  )  [virtual]

Skips over and discards n bytes of data from the input stream.

The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

This method simply performs in.skip(n).

Parameters:
n the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Exceptions:
IOException if an I/O error occurs.

Implements java::io::InputStream.

virtual jint java::io::BufferedInputStream::available (  )  [virtual]

Returns the number of bytes that can be read from this input stream without blocking.

This method simply performs in.available(n) and returns the result.

Returns:
the number of bytes that can be read from the input stream without blocking.
Exceptions:
IOException if an I/O error occurs.

Reimplemented from java::io::InputStream.

virtual void java::io::BufferedInputStream::close (  )  [virtual]

Closes this input stream and releases any system resources associated with the stream.

This method simply performs in.close().

Exceptions:
IOException if an I/O error occurs.

Reimplemented from java::io::InputStream.

virtual void java::io::BufferedInputStream::mark ( jint  readlimit = 0  )  [virtual]

Marks the current position in this input stream.

A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit argument tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

This method simply performs in.mark(readlimit).

Parameters:
readlimit the maximum limit of bytes that can be read before the mark position becomes invalid.

Reimplemented from java::io::InputStream.

virtual void java::io::BufferedInputStream::reset (  )  [virtual]

Repositions this stream to the position at the time the mark method was last called on this input stream.

This method simply performs in.reset().

Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parse, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails. If this happens within readlimit bytes, it allows the outer code to reset the stream and try another parser.

Exceptions:
IOException if the stream has not been marked or if the mark has been invalidated.

Reimplemented from java::io::InputStream.

virtual jboolean java::io::BufferedInputStream::markSupported (  )  [virtual]

Tests if this input stream supports the mark and reset methods.

This method simply performs in.markSupported().

Returns:
true if this stream type supports the mark and reset method; false otherwise.

Reimplemented from java::io::InputStream.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:26 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3