java.io.CharArrayReader
java.io.Reader
None
None
New as of JDK 1.1
The CharArrayReader class represents a stream whose data comes from a character array. This class is similar to ByteArrayInputStream, but it deals with a Java character stream rather than a byte stream. Furthermore, this class supports marking a position in the stream, which ByteArrayInputStream does not.
The position of the end of the stream depends on the constructor used. If the CharArrayReader(char[] buf) constructor is used, the end of the stream is the end of the character array. If the CharArrayReader(char[] buf, int offset, int length) constructor is used, the end of the stream is reached at the index given by offset+length.
public class java.io.CharArrayReader extends java.io.Reader { // Variables protected char[] buf; protected int count; protected int markedPos; protected int pos; // Constructors public CharArrayReader(char[] buf); public CharArrayReader(char[] buf, int offset, int length); // Instance Methods public void close(); public void mark(int readAheadLimit); public boolean markSupported(); public int read(); public int read(char[] b, int off, int len); public boolean ready(); public void reset(); public long skip(long n); }
The buffer represented by this reader.
The size of the buffer, or in other words, the length of the array.
The buffer position when mark() was called. If mark() has not been called, this variable is 0.
The current position in the buffer.
The reader source.
This constructor creates a CharArrayReader object that uses the given array of characters as its data source. The data is not copied, so changes made to the array affect the data that the CharArrayReader returns.
The reader source.
An offset into the array.
The number of bytes to read.
This constructor creates a CharArrayReader that uses, as its data source, length characters in a given array of bytes, starting at offset characters from the beginning of the array. The data is not copied, so changes made to the array affect the data that the CharArrayReader returns.
Reader.close()
This method closes the reader by removing the link between this CharArrayReader and the array it was created with.
The maximum number of characters that can be read before the saved position becomes invalid.
If the stream is closed or any other kind of I/O error occurs.
Reader.mark(int)
This method causes the CharArrayReader to remember its current position. A subsequent call to reset() causes the object to return to that saved position, and thus reread a portion of the buffer. Because the data for this stream comes from a char array, there is no limit on reading ahead, so readAheadLimit is ignored.
The boolean value true.
Reader.markSupported()
This method returns true to indicate that this class supports mark() and reset().
The next character or -1 if the end of the stream is encountered.
If the stream is closed or any other kind of I/O error occurs.
Reader.read()
This method returns the next character in the array.
An array of characters to be filled from the stream.
An offset into the character array.
The number of characters to read.
The actual number of characters read or -1 if the end of the stream is encountered immediately.
If the stream is closed or any other kind of I/O error occurs.
Reader.read(char[], int, int)
This method copies up to len characters from its internal array into the given array b, starting at index off.
A boolean value that indicates whether the stream is ready to be read.
If the stream is closed or any other kind of I/O error occurs.
Reader.ready()
If there is any data left to be read from the character array, this method returns true.
If the stream is closed or any other kind of I/O error occurs.
Reader.reset()
This method resets the position of the CharArrayReader to the position that was saved by calling the mark() method. If mark() has not been called, the CharArrayReader is reset to read from the beginning of the array.
The number of characters to skip.
The actual number of characters skipped.
If the stream is closed or any other kind of I/O error occurs.
Reader.skip()
This method skips n characters of input. If you try to skip past the end of the array, the stream is positioned at the end of the array.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals (Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
read(char[]) |
Reader |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
IOException, Reader, String
This HTML Help has been published using the chm2web software. |