java.io.StringBufferInputStream
java.io.InputStream
None
None
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); }
The buffer that stores the data for the input stream.
The size of the buffer, or in other words, the length of the string.
The current stream position.
The String to use.
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.
The number of bytes remaining in the string.
InputStream.available()
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.
The next byte of data or -1 if the end of the string is encountered.
InputStream.read()
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.
An array of bytes to be filled from the stream.
An offset into the byte array.
The number of bytes to read.
The actual number of bytes read or -1 if the end of the string is encountered immediately.
InputStream.read(byte[], int, int)
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.
InputStream.reset()
This method sets the position of the StringBufferInputStream back to the beginning of the internal buffer.
The number of bytes to skip.
The actual number of bytes skipped.
InputStream.skip()
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.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
close() |
InputStream |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
mark(int) |
InputStream |
markSupported() |
InputStream |
notify() |
Object |
notifyAll() |
Object |
read(byte[]) |
InputStream |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
ByteArrayInputStream, InputStream, IOException, String, StringReader