public class ReaderInputStream extends InputStream
Reader
as an InputStream
.
Adapted from StringInputStream
.Constructor and Description |
---|
ReaderInputStream(Reader reader)
Construct a
ReaderInputStream
for the specified Reader . |
ReaderInputStream(Reader reader,
String encoding)
Construct a
ReaderInputStream
for the specified Reader ,
with the specified encoding. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns an estimate of the number of bytes that can be read (or skipped over) from this input
stream without blocking by the next invocation of a method for this input stream.
|
void |
close()
Closes the Reader.
|
void |
mark(int limit)
Marks the read limit of the Reader.
|
boolean |
markSupported()
Tests if this input stream supports the
mark and reset methods. |
int |
read()
Reads from the
Reader , returning the same value. |
int |
read(byte[] b,
int off,
int len)
Reads from the
Reader into a byte array |
void |
reset()
Resets the Reader.
|
read, skip
public ReaderInputStream(Reader reader)
ReaderInputStream
for the specified Reader
.reader
- Reader
. Must not be null
.public int available() throws IOException
InputStream
Note that while some implementations of InputStream
will return the total number of bytes
in the stream, many will not. It is never correct to use the return value of this method to
allocate a buffer intended to hold all data in this stream.
A subclass' implementation of this method may choose to throw an IOException
if this
input stream has been closed by invoking the InputStream.close()
method.
The available
method for class InputStream
always returns 0
.
This method should be overridden by subclasses.
available
in class InputStream
IOException
- if an error occurspublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
- if the original Reader fails to be closedpublic void mark(int limit)
mark
in class InputStream
limit
- the maximum limit of bytes that can be read before the
mark position becomes invalidInputStream.reset()
public boolean markSupported()
InputStream
mark
and reset
methods. Whether
or not mark
and reset
are supported is an invariant property of a
particular input stream instance. The markSupported
method of
InputStream
returns false
.markSupported
in class InputStream
InputStream.mark(int)
,
InputStream.reset()
public int read() throws IOException
Reader
, returning the same value.read
in class InputStream
Reader
.IOException
- if the original Reader
fails to be readpublic int read(byte[] b, int off, int len) throws IOException
Reader
into a byte arrayread
in class InputStream
b
- the byte array to read intooff
- the offset in the byte arraylen
- the length in the byte array to fillIOException
- if an error occursInputStream.read()
public void reset() throws IOException
reset
in class InputStream
IOException
- if the Reader fails to be resetInputStream.mark(int)
,
IOException