public class StraightStreamReader
extends java.io.Reader
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 and Description |
---|
StraightStreamReader()
Constructor method for i18n purposes only.
|
StraightStreamReader(java.io.InputStream in)
Create a StraightStreamReader from an InputStream
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the stream.
|
static void |
main(java.lang.String[] args)
Regression test for this class.
|
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.
|
public StraightStreamReader() throws java.lang.InstantiationException
I18NExtractor
).
java.lang.InstantiationException
- Error indicationpublic StraightStreamReader(java.io.InputStream in)
in
- InputStream to wrap a Reader around.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
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 bufferjava.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 readjava.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 skipjava.lang.IllegalArgumentException
- If n is negativejava.io.IOException
- If an I/O error occurspublic static void main(java.lang.String[] args)
This method creates a temporary file in the working directory called "test.txt". This file should not exist before hand, and the program should have create, read, write, and delete access to this file.
args
- command line arguments (ignored)Copyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.