|
Chapter 11 The java.io Package |
|
StringBufferInputStream
Name
StringBufferInputStream
- Class Name:
-
java.io.StringBufferInputStream
- Superclass:
-
java.io.InputStream
- Immediate Subclasses:
-
None
- Interfaces Implemented:
-
None
- Availability:
-
Deprecated as of JDK 1.1
The StringBufferInputStream
class represents a byte stream whose data source is a String.
This class is similar to the ByteArrayInputStream
class, which uses a byte array
as its data source.
StringBufferInputStream is
deprecated as of JDK 1.1 because it does not correctly convert characters
to bytes. The StringReader
class should now be used to create a character stream from a
String.
public class java.io.StringBufferInputStream extends java.io.InputStream {
// Variables
protected String buffer;
protected int count;
protected int pos;
// Constructor
public StringBufferInputStream(String s);
// Instance Methods
public synchronized int available();
public synchronized int read();
public synchronized int read(byte[] b, int off, int len);
public synchronized void reset();
public synchronized long skip(long n);
}
- Description
-
The buffer that stores the data for the input stream.
- Description
-
The size of the buffer, or in other words, the length of the string.
- Description
-
The current stream position.
- Parameters
-
- s
-
The String to use.
- Description
-
This constructor creates a StringBufferInputStream
that uses the given String
as its data source. Note that the data is not copied, so changes made to
the String affect the data
that the StringBufferInputStream
returns.
- Returns
-
The number of bytes remaining in the string.
- Overrides
-
InputStream.available()
- Description
-
This method returns the number of bytes that are left in the string. This
is the length of the string, count,
minus the current stream position, pos.
- Returns
-
The next byte of data or -1 if the end of the string is encountered.
- Overrides
-
InputStream.read()
- Description
-
This method returns the next byte from the string. The method takes the
next character from the string and returns the low eight bits of that character
as a byte, which is not the correct way to convert characters into bytes.
The method cannot block.
- Parameters
-
- b
-
An array of bytes to be filled from the stream.
- off
-
An offset into the byte array.
- len
-
The number of bytes to read.
- Returns
-
The actual number of bytes read or -1 if the end of the string is encountered
immediately.
- Overrides
-
InputStream.read(byte[], int, int)
- Description
-
This method copies bytes from the internal buffer into the given array
b, starting at index off
and continuing for len bytes.
The method takes each character from the string and returns the low eight
bits of that character as a byte, which is not the correct way to convert
characters into bytes.
- Overrides
-
InputStream.reset()
- Description
-
This method sets the position of the StringBufferInputStream
back to the beginning of the internal buffer.
- Parameters
-
- n
-
The number of bytes to skip.
- Returns
-
The actual number of bytes skipped.
- Overrides
-
InputStream.skip()
- Description
-
This method skips n bytes of
the string. If you try to skip past the end of the string, the stream is
positioned at the end of the string.
ByteArrayInputStream,
InputStream,
IOException,
String,
StringReader
|
|