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
.
This is a stripped down version of org.apache.commons.io.input.ReaderInputStream
of Apache Commons IO 2.7.
-
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.ReaderInputStream(java.io.Reader reader, java.nio.charset.CharsetEncoder encoder)
Construct a newReaderInputStream
.ReaderInputStream(java.io.Reader reader, java.nio.charset.CharsetEncoder encoder, int bufferSize)
Construct a newReaderInputStream
. -
Method Summary
-
Constructor Details
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader, java.nio.charset.CharsetEncoder encoder)Construct a newReaderInputStream
.- Parameters:
reader
- the targetReader
encoder
- the charset encoder- Since:
- 1.10.9
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader, java.nio.charset.CharsetEncoder encoder, int bufferSize)Construct a newReaderInputStream
.- Parameters:
reader
- the targetReader
encoder
- the charset encoderbufferSize
- the size of the input buffer in number of characters- Since:
- 1.10.9
-
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(byte[] array, int off, int len) throws java.io.IOExceptionRead the specified number of bytes into an array.- Overrides:
read
in classjava.io.InputStream
- Parameters:
array
- the byte array to read intooff
- the offset to start reading bytes intolen
- the number of bytes to read- Returns:
- the number of bytes read or
-1
if the end of the stream has been reached - Throws:
java.io.IOException
- if an I/O error occurs
-
read
public int read(byte[] b) throws java.io.IOExceptionRead the specified number of bytes into an array.- Overrides:
read
in classjava.io.InputStream
- Parameters:
b
- the byte array to read into- Returns:
- the number of bytes read or
-1
if the end of the stream has been reached - Throws:
java.io.IOException
- if an I/O error occurs
-
read
public int read() throws java.io.IOExceptionRead a single byte.- Specified by:
read
in classjava.io.InputStream
- Returns:
- either the byte read or
-1
if the end of the stream has been reached - Throws:
java.io.IOException
- if an I/O error occurs
-
close
public void close() throws java.io.IOExceptionClose the stream. This method will cause the underlyingReader
to be closed.- 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 an I/O error occurs
-