Package org.apache.any23.util
Class ReaderInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.any23.util.ReaderInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ReaderInputStream extends InputStream
Adapts aReader
as anInputStream
. Adapted fromStringInputStream
.
-
-
Constructor Summary
Constructors Constructor Description ReaderInputStream(Reader reader)
Construct aReaderInputStream
for the specifiedReader
.ReaderInputStream(Reader reader, String encoding)
Construct aReaderInputStream
for the specifiedReader
, with the specified encoding.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
Closes the Stringreader.void
mark(int limit)
Marks the read limit of the StringReader.boolean
markSupported()
int
read()
Reads from theReader
, returning the same value.int
read(byte[] b, int off, int len)
Reads from theReader
into a byte arrayvoid
reset()
Resets the StringReader.-
Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, skip, transferTo
-
-
-
-
Constructor Detail
-
ReaderInputStream
public ReaderInputStream(Reader reader)
Construct aReaderInputStream
for the specifiedReader
.- Parameters:
reader
-Reader
. Must not benull
.
-
-
Method Detail
-
read
public int read() throws IOException
Reads from theReader
, returning the same value.- Specified by:
read
in classInputStream
- Returns:
- the value of the next character in the
Reader
. - Throws:
IOException
- if the originalReader
fails to be read
-
read
public int read(byte[] b, int off, int len) throws IOException
Reads from theReader
into a byte array- Overrides:
read
in classInputStream
- Parameters:
b
- the byte array to read intooff
- the offset in the byte arraylen
- the length in the byte array to fill- Returns:
- the actual number read into the byte array, -1 at the end of the stream
- Throws:
IOException
- if an error occurs
-
mark
public void mark(int limit)
Marks the read limit of the StringReader.- Overrides:
mark
in classInputStream
- Parameters:
limit
- the maximum limit of bytes that can be read before the mark position becomes invalid
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Returns:
- the current number of bytes ready for reading
- Throws:
IOException
- if an error occurs
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classInputStream
- Returns:
- false - mark is not supported
-
reset
public void reset() throws IOException
Resets the StringReader.- Overrides:
reset
in classInputStream
- Throws:
IOException
- if the StringReader fails to be reset
-
close
public void close() throws IOException
Closes the Stringreader.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- if the original StringReader fails to be closed
-
-