Package org.apache.tools.ant.util

# Class ReaderInputStream

java.lang.Object
java.io.InputStream
org.apache.tools.ant.util.ReaderInputStream

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

Direct Known Subclasses:
  `StringInputStream`

public class ReaderInputStream extends 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(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.
`ReaderInputStream(Reader reader, Charset charset)`
Construct a `ReaderInputStream` for the specified `Reader`, with the specified encoding.
`ReaderInputStream(Reader reader, CharsetEncoder encoder)`
Construct a new `ReaderInputStream`.
`ReaderInputStream(Reader reader, CharsetEncoder encoder, int bufferSize)`
Construct a new `ReaderInputStream`.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close the stream.
`int`
`read()`
Read a single byte.
`int`
`read(byte[] b)`
Read the specified number of bytes into an array.
`int`
`read(byte[] array, int off, int len)`
Read the specified number of bytes into an array.

### Methods inherited from class java.io.InputStream

`available, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ReaderInputStream

public ReaderInputStream(Reader reader, CharsetEncoder encoder)
Construct a new `ReaderInputStream`.

Parameters:
  `reader` - the target `Reader`
  `encoder` - the charset encoder
Since:
  1.10.9

### ReaderInputStream

public ReaderInputStream(Reader reader, CharsetEncoder encoder, int bufferSize)
Construct a new `ReaderInputStream`.

Parameters:
  `reader` - the target `Reader`
  `encoder` - the charset encoder
  `bufferSize` - the size of the input buffer in number of characters
Since:
  1.10.9

### ReaderInputStream

public ReaderInputStream(Reader reader)
Construct a `ReaderInputStream` for the specified `Reader`.

Parameters:
  `reader` - `Reader`. Must not be `null`.

### ReaderInputStream

public ReaderInputStream(Reader reader, String encoding)
Construct a `ReaderInputStream` for the specified `Reader`, with the specified encoding.

Parameters:
  `reader` - non-null `Reader`.
  `encoding` - non-null `String` encoding.

### ReaderInputStream

public ReaderInputStream(Reader reader, Charset charset)
Construct a `ReaderInputStream` for the specified `Reader`, with the specified encoding.

Parameters:
  `reader` - non-null `Reader`.
  `charset` - non-null `Charset` charset.
Since:
  Ant 1.10.6

## Method Details

### read

public int read(byte[] array, int off, int len) throws IOException
Read the specified number of bytes into an array.

Overrides:
  `read` in class `InputStream`
Parameters:
  `array` - the byte array to read into
  `off` - the offset to start reading bytes into
  `len` - the number of bytes to read
Returns:
  the number of bytes read or `-1` if the end of the stream has been reached
Throws:
  `IOException` - if an I/O error occurs

### read

public int read(byte[] b) throws IOException
Read the specified number of bytes into an array.

Overrides:
  `read` in class `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:
  `IOException` - if an I/O error occurs

### read

public int read() throws IOException
Read a single byte.

Specified by:
  `read` in class `InputStream`
Returns:
  either the byte read or `-1` if the end of the stream has been reached
Throws:
  `IOException` - if an I/O error occurs

### close

public void close() throws IOException
Close the stream. This method will cause the underlying `Reader` to be closed.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Overrides:
  `close` in class `InputStream`
Throws:
  `IOException` - if an I/O error occurs