|
com.Ostermiller.util Java Utilities |
|||||||
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));
Constructor Summary | |
---|---|
StraightStreamReader(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 |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StraightStreamReader(InputStream in)
in
- InputStream to wrap a Reader around.Method Detail |
---|
public void close() throws IOException
close
in interface Closeable
close
in class Reader
IOException
- If an I/O error occurspublic void mark(int readAheadLimit) throws IOException
mark
in class 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.
IOException
- If the stream does not support mark(), or if some other I/O error occurspublic boolean markSupported()
markSupported
in class Reader
public int read() throws IOException
read
in class Reader
IOException
- If an I/O error occurspublic int read(char[] cbuf) throws IOException
read
in class Reader
cbuf
- Destination buffer
IOException
- If an I/O error occurspublic int read(char[] cbuf, int off, int len) throws IOException
read
in class Reader
cbuf
- Destination bufferoff
- Offset at which to start storing characterslen
- Maximum number of characters to read
IOException
- If an I/O error occurspublic boolean ready() throws IOException
ready
in class Reader
IOException
- If an I/O error occurspublic void reset() throws IOException
reset
in class Reader
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 IOException
skip
in class Reader
n
- The number of characters to skip
IllegalArgumentException
- If n is negative
IOException
- If an I/O error occurs
|
com.Ostermiller.util Java Utilities |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2001-2012 by Stephen Ostermiller