Package org.apache.tools.ant.util
Class ReaderInputStream
java.lang.Object
java.io.InputStream
org.apache.tools.ant.util.ReaderInputStream
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
StringInputStream
public class ReaderInputStream
extends java.io.InputStream
Adapts a
Reader
as an InputStream
.
Adapted from StringInputStream
.-
Constructor Summary
Constructors Constructor Description ReaderInputStream(java.io.Reader reader)
Construct aReaderInputStream
for the specifiedReader
.ReaderInputStream(java.io.Reader reader, java.lang.String encoding)
Construct aReaderInputStream
for the specifiedReader
, with the specified encoding.ReaderInputStream(java.io.Reader reader, java.nio.charset.Charset charset)
Construct aReaderInputStream
for the specifiedReader
, with the specified encoding. -
Method Summary
Modifier and Type Method Description int
available()
void
close()
Closes the Reader.void
mark(int limit)
Marks the read limit of the Reader.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 Reader.
-
Constructor Details
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader)Construct aReaderInputStream
for the specifiedReader
.- Parameters:
reader
-Reader
. Must not benull
.
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader, java.lang.String encoding)Construct aReaderInputStream
for the specifiedReader
, with the specified encoding.- Parameters:
reader
- non-nullReader
.encoding
- non-nullString
encoding.
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader, java.nio.charset.Charset charset)Construct aReaderInputStream
for the specifiedReader
, with the specified encoding.- Parameters:
reader
- non-nullReader
.charset
- non-nullCharset
charset.- Since:
- Ant 1.10.6
-
-
Method Details
-
read
public int read() throws java.io.IOExceptionReads from theReader
, returning the same value.- Specified by:
read
in classjava.io.InputStream
- Returns:
- the value of the next character in the
Reader
. - Throws:
java.io.IOException
- if the originalReader
fails to be read
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionReads from theReader
into a byte array- Overrides:
read
in classjava.io.InputStream
- 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:
java.io.IOException
- if an error occurs
-
mark
public void mark(int limit)Marks the read limit of the Reader.- Overrides:
mark
in classjava.io.InputStream
- Parameters:
limit
- the maximum limit of bytes that can be read before the mark position becomes invalid
-
available
public int available() throws java.io.IOException- Overrides:
available
in classjava.io.InputStream
- Returns:
- the current number of bytes ready for reading
- Throws:
java.io.IOException
- if an error occurs
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classjava.io.InputStream
- Returns:
- false - mark is not supported
-
reset
public void reset() throws java.io.IOExceptionResets the Reader.- Overrides:
reset
in classjava.io.InputStream
- Throws:
java.io.IOException
- if the Reader fails to be reset
-
close
public void close() throws java.io.IOExceptionCloses the Reader.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
- if the original Reader fails to be closed
-