|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.Reader
com.Ostermiller.util.StraightStreamReader
public class StraightStreamReader
A StraightStreamReader is a bridge from byte streams to character streams: It reads bytes and translates them into characters without using a character encoding. The characters that a StraightStreamReader returns may not be valid Unicode characters but they are guaranteed to be in the 0x00 to 0xFF range. More information about this class is available from ostermiller.org.
Most of the time you want to do character encoding translation when translating bytes to characters. If you are planning on displaying the text, you should always do this and should use an InputStreamReader for the purpose. Sometimes it is useful to treat characters as bytes with some extra bits. In these cases you would want to use a StraightStreamReader.
For top efficiency, consider wrapping an StraightStreamReader within a BufferedReader. For example:
BufferedReader in = new BufferedReader(new StraightStreamReader(System.in));
Field Summary |
---|
Fields inherited from class java.io.Reader |
---|
lock |
Constructor Summary | |
---|---|
StraightStreamReader(java.io.InputStream in)
Create a StraightStreamReader from an InputStream |
Method Summary | |
---|---|
void |
close()
Close the stream. |
void |
mark(int readAheadLimit)
Mark the present position in the stream. |
boolean |
markSupported()
Tell whether this stream supports the mark() operation. |
int |
read()
Read a single character. |
int |
read(char[] cbuf)
Read characters into an array. |
int |
read(char[] cbuf,
int off,
int len)
Read characters into an array. |
boolean |
ready()
Tell whether this stream is ready to be read. |
void |
reset()
Reset the stream. |
long |
skip(long n)
Skip characters. |
Methods inherited from class java.io.Reader |
---|
read |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StraightStreamReader(java.io.InputStream in)
in
- InputStream to wrap a Reader around.Method Detail |
---|
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.Reader
java.io.IOException
- If an I/O error occurspublic void mark(int readAheadLimit) throws java.io.IOException
mark
in class java.io.Reader
readAheadLimit
- Limit on the number of characters that may be read
while still preserving the mark. After reading this many characters,
attempting to reset the stream may fail.
java.io.IOException
- If the stream does not support mark(), or if some other I/O error occurspublic boolean markSupported()
markSupported
in class java.io.Reader
public int read() throws java.io.IOException
read
in class java.io.Reader
java.io.IOException
- If an I/O error occurspublic int read(char[] cbuf) throws java.io.IOException
read
in class java.io.Reader
cbuf
- Destination buffer
java.io.IOException
- If an I/O error occurspublic int read(char[] cbuf, int off, int len) throws java.io.IOException
read
in class java.io.Reader
cbuf
- Destination bufferoff
- Offset at which to start storing characterslen
- Maximum number of characters to read
java.io.IOException
- If an I/O error occurspublic boolean ready() throws java.io.IOException
ready
in class java.io.Reader
java.io.IOException
- If an I/O error occurspublic void reset() throws java.io.IOException
reset
in class java.io.Reader
java.io.IOException
- If the stream has not been marked, or if the mark has been invalidated,
or if the stream does not support reset(), or if some other I/O error occurspublic long skip(long n) throws java.io.IOException
skip
in class java.io.Reader
n
- The number of characters to skip
java.lang.IllegalArgumentException
- If n is negative
java.io.IOException
- If an I/O error occurs
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |