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 a `ReaderInputStream` for the specified `Reader`.
  `ReaderInputStream​(java.io.Reader reader, java.lang.String encoding)` | Construct a `ReaderInputStream` for the specified `Reader`, with the specified encoding.
  `ReaderInputStream​(java.io.Reader reader, java.nio.charset.Charset charset)` | Construct a `ReaderInputStream` for the specified `Reader`, with the specified encoding.
  `ReaderInputStream​(java.io.Reader reader, java.nio.charset.CharsetEncoder encoder)` | Construct a new `ReaderInputStream`.
  `ReaderInputStream​(java.io.Reader reader, java.nio.charset.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​(java.io.Reader reader, java.nio.charset.CharsetEncoder encoder)
    Construct a new `ReaderInputStream`.
    Parameters:
      `reader` - the target `Reader`
      `encoder` - the charset encoder
    Since:
      1.10.9

  - ### ReaderInputStream

    public ReaderInputStream​(java.io.Reader reader, java.nio.charset.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​(java.io.Reader reader)
    Construct a `ReaderInputStream` for the specified `Reader`.
    Parameters:
      `reader` - `Reader`. Must not be `null`.

  - ### ReaderInputStream

    public ReaderInputStream​(java.io.Reader reader, java.lang.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​(java.io.Reader reader, java.nio.charset.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 java.io.IOException
    Read the specified number of bytes into an array.
    Overrides:
      `read` in class `java.io.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:
      `java.io.IOException` - if an I/O error occurs

  - ### read

    public int read​(byte[] b) throws java.io.IOException
    Read the specified number of bytes into an array.
    Overrides:
      `read` in class `java.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.IOException
    Read a single byte.
    Specified by:
      `read` in class `java.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.IOException
    Close the stream. This method will cause the underlying `Reader` to be closed.
    Specified by:
      `close` in interface `java.lang.AutoCloseable`
    Specified by:
      `close` in interface `java.io.Closeable`
    Overrides:
      `close` in class `java.io.InputStream`
    Throws:
      `java.io.IOException` - if an I/O error occurs