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 aReaderInputStreamfor the specifiedReader.ReaderInputStream(java.io.Reader reader, java.lang.String encoding)Construct aReaderInputStreamfor the specifiedReader, with the specified encoding.ReaderInputStream(java.io.Reader reader, java.nio.charset.Charset charset)Construct aReaderInputStreamfor 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 targetReaderencoder- 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 targetReaderencoder- 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 aReaderInputStreamfor the specifiedReader.- Parameters:
reader-Reader. Must not benull.
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader, java.lang.String encoding)Construct aReaderInputStreamfor the specifiedReader, with the specified encoding.- Parameters:
reader- non-nullReader.encoding- non-nullStringencoding.
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader, java.nio.charset.Charset charset)Construct aReaderInputStreamfor the specifiedReader, with the specified encoding.- Parameters:
reader- non-nullReader.charset- non-nullCharsetcharset.- 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:
readin 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
-1if 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:
readin classjava.io.InputStream- Parameters:
b- the byte array to read into- Returns:
- the number of bytes read or
-1if 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:
readin classjava.io.InputStream- Returns:
- either the byte read or
-1if 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 underlyingReaderto be closed.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException- if an I/O error occurs
-