java.io.StringBufferInputStream
StringBufferInputStream
contains an internal buffer that contains bytes that
may be read from the stream. An internal counter keeps track of the next byte to
be supplied by the read
method. See also ByteArrayInputStream
(§22.6).
public classNote that bytes read from aStringBufferInputStream
extends InputStream { protected Stringbuffer
; protected intpos
; protected intcount
; publicStringBufferInputStream
(String s) throws NullPointerException; public intread
(); public intread
(byte[] b, int off, int len) throws NullPointerException, IndexOutOfBoundsException; public longskip
(long n); public intavailable
(); public voidreset
(); }
StringBufferInputStream
are the low-order eight bits of each character in the string; the high-order eight bits of each character are ignored.22.7.1 protected String
buffer
;
A String
that was provided by the creator of the stream. Elements buffer[0]
through buffer[count-1]
are the only bytes that can ever be read from this
stream; element buffer[pos]
is the next byte to be read.
22.7.2 protected int
pos
;
This value should always be nonnegative and not larger than the value of count
.
The next byte to be read from this stream will be buffer[pos]
.
22.7.3 protected int
count
;
This value equals the length of buffer
. It is the number of bytes of data in
buffer
that can ever be read from this stream.
22.7.4 public
StringBufferInputStream
(String s)
throws NullPointerException
This constructor initializes a newly created StringBufferInputStream
so that it
uses s
as its buffer array. The initial value of pos
is 0
and the initial value of
count
is the length of buffer
.
22.7.5 public int
read
()
If pos
equals count
, then -1
is returned to indicate end of file. Otherwise, the
value buffer[pos]&0xff
is returned; just before the return, 1
is added to pos
.
Implements the read
method of InputStream
(§22.3.1).
22.7.6 public int
read
(byte[] b, int off, int len)
throws NullPointerException, IndexOutOfBoundsException
If pos
equals count
, then -1
is returned to indicate end of file. Otherwise, the
number k
of bytes read is equal to the smaller of len
and count-pos
. If k
is positive,
then bytes buffer[pos]
through buffer[pos+k-1]
are copied into b[off]
through b[off+k-1]
in the manner performed by System.arraycopy
(§20.18.16). The value k
is added into pos
and k
is returned.
Overrides the read
method of InputStream
(§22.3.3).
22.7.7 public long
skip
(long n)
The actual number k
of bytes to be skipped is equal to the smaller of n
and
count-pos
. The value k
is added into pos
and k
is returned.
Overrides the skip
method of InputStream
(§22.3.4).
22.7.8 public int
available
()
The quantity count-pos
is returned.
Overrides the available
method of InputStream
(§22.3.5).
22.7.9 public void
reset
()
Overrides the reset
method of InputStream
(§22.3.8).
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 doug.kramer@sun.com