java.io.BufferedInputStream
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.
public classBufferedInputStream
extends FilterInputStream { protected byte[]buf
; protected intcount
= 0; protected intpos
= 0; protected intmarkpos
= -1; protected intmarklimit
= 0; publicBufferedInputStream
(InputStream in); publicBufferedInputStream
(InputStream in, int size); public intread
() throws IOException; public intread
(byte[] b) throws IOException, NullPointerException; public intread
(byte[] b, int off, int len) throws IOException, NullPointerException, IndexOutOfBoundsException; public longskip
(long n) throws IOException; public intavailable
() throws IOException; public voidmark
(int readlimit); public voidreset
() throws IOException; public booleanmarkSupported
(); }
22.10.1 protected byte[]
buf
;
The internal buffer array. When necessary, it may be replaced by another array of a different size.
22.10.2 protected int
count
= 0;
This value is always in the range 0
through buf.length
; elements buf[0]
through buf[count-1]
contain buffered input data obtained from the underlying
input stream.
22.10.3 protected int
pos
= 0;
This value is always in the range 0
through count
. If it is less than count
, then
buf[pos]
is the next byte to be supplied as input; if it is equal to count
, then the
next read
or skip
operation will require more bytes to be read from the contained
input stream.
22.10.4 protected int
markpos
= -1;
This value is always in the range -1
through pos
. If there is no marked position in
the input stream, this field is -1
. If there is a marked position in the input stream,
then buf[markpos]
is the first byte to be supplied as input after a reset
operation.
If markpos
is not -1
, then all bytes from positions buf[markpos]
through
buf[pos-1]
must remain in the buffer array (though they may be moved to
another place in the buffer array, with suitable adjustments to the values of count
,
pos
, and markpos
); they may not be discarded unless and until the difference
between pos
and markpos
exceeds marklimit
.
22.10.5 protected int
marklimit
;
Whenever the difference between pos
and markpos
exceeds marklimit
, then the
mark may be dropped by setting markpos
to -1
.
22.10.6 public
BufferedInputStream
(InputStream in)
This constructor initializes a newly created BufferedInputStream
by saving its
argument, the input stream in
, for later use. An internal buffer array is created and
stored in buf
.
22.10.7 public
BufferedInputStream
(InputStream in, int size)
This constructor initializes a newly created BufferedInputStream
by saving its
argument, the input stream in
, for later use. An internal buffer array of length
size
is created and stored in buf
.
22.10.8 public int
read
() throws IOException
See the general contract of the read
method of InputStream
(§22.3.1).
Overrides the read
method of FilterInputStream
(§22.9.3).
22.10.9 public int
read
(byte[] b)
throws IOException, NullPointerException
See the general contract of the read
method of InputStream
(§22.3.2).
Overrides the read
method of FilterInputStream
(§22.9.4).
22.10.10 public int
read
(byte[] b, int off, int len)
throws IOException, NullPointerException, IndexOutOfBoundsException
See the general contract of the read
method of InputStream
(§22.3.3).
Overrides the read
method of FilterInputStream
(§22.9.5).
22.10.11 public long
skip
(long n) throws IOException
See the general contract of the skip
method of InputStream
(§22.3.4).
Overrides the skip
method of FilterInputStream
(§22.9.6).
22.10.12 public int
available
() throws IOException
See the general contract of the available
method of InputStream
(§22.3.5).
Overrides the available
method of FilterInputStream
(§22.9.7).
22.10.13 public void
mark
(int readlimit)
The field marklimit
is set equal to the argument and markpos
is set equal to pos
Overrides the mark
method of FilterInputStream
(§22.9.9).
22.10.14 public void
reset
() throws IOException
See the general contract of the reset
method of InputStream
(§22.3.8).
If markpos
is -1
(no mark has been set or the mark has been invalidated), an IOException
is thrown. Otherwise, pos
is set equal to markpos
.
Overrides the reset
method of FilterInputStream
(§22.9.10).
22.10.15 public boolean
markSupported
()
This method returns true
(a BufferedInputStream
always supports mark
).
Overrides the markSupported
method of FilterInputStream
(§22.9.11).
Contents | Prev | Next | Index
Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to [email protected]