Top Description Fields Constructors Methods
org.apache.tools.ant.util

public Class ReaderInputStream

extends InputStream
Class Inheritance
Known Direct Subclasses
org.apache.tools.ant.filters.StringInputStream
Imports
java.io.IOException, .InputStream, .Reader, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetEncoder, .CoderResult, .CodingErrorAction, java.util.Objects

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.

Field Summary

Modifier and TypeField and Description
private static final int
private final CharsetEncoder
private final CharBuffer
encoderIn

CharBuffer used as input for the decoder.

private final ByteBuffer
encoderOut

ByteBuffer used as output for the decoder.

private boolean
private static final int
private CoderResult
private final Reader

Constructor Summary

AccessConstructor and Description
public
ReaderInputStream(final Reader
the target Reader
reader
,
final CharsetEncoder
the charset encoder
encoder
)

Construct a new ReaderInputStream.

public
ReaderInputStream(final Reader
the target Reader
reader
,
final CharsetEncoder
the charset encoder
encoder
,
final int
the size of the input buffer in number of characters
bufferSize
)

Construct a new ReaderInputStream.

public
ReaderInputStream(Reader
Reader. Must not be null.
reader
)

Construct a ReaderInputStream for the specified Reader.

public
ReaderInputStream(Reader
non-null Reader.
reader
,
String
non-null String encoding.
encoding
)

Construct a ReaderInputStream for the specified Reader, with the specified encoding.

public
ReaderInputStream(Reader
non-null Reader.
reader
,
Charset
non-null Charset charset.
charset
)

Construct a ReaderInputStream for the specified Reader, with the specified encoding.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Close the stream.
private void
fillBuffer()

Fills the internal char buffer from the reader.

public int

Returns:

the number of bytes read or -1 if the end of the stream has been reached
read
(final byte[]
the byte array to read into
array
,
int
the offset to start reading bytes into
off
,
int
the number of bytes to read
len
)

Overrides java.io.InputStream.read.

Read the specified number of bytes into an array.
public int

Returns:

the number of bytes read or -1 if the end of the stream has been reached
read
(final byte[]
the byte array to read into
b
)

Overrides java.io.InputStream.read.

Read the specified number of bytes into an array.
public int

Returns:

either the byte read or -1 if the end of the stream has been reached
read
()

Implements abstract java.io.InputStream.read.

Read a single byte.
Inherited from java.io.InputStream:
availablemarkmarkSupportednullInputStreamreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

DEFAULT_BUFFER_SIZEback to summary
private static final int DEFAULT_BUFFER_SIZE

Hides java.io.InputStream.DEFAULT_BUFFER_SIZE.

encoderback to summary
private final CharsetEncoder encoder
encoderInback to summary
private final CharBuffer encoderIn

CharBuffer used as input for the decoder. It should be reasonably large as we read data from the underlying Reader into this buffer.

encoderOutback to summary
private final ByteBuffer encoderOut

ByteBuffer used as output for the decoder. This buffer can be small as it is only used to transfer data from the decoder to the buffer provided by the caller.

endOfInputback to summary
private boolean endOfInput
EOFback to summary
private static final int EOF
lastCoderResultback to summary
private CoderResult lastCoderResult
readerback to summary
private final Reader reader

Constructor Detail

ReaderInputStreamback to summary
public ReaderInputStream(final Reader reader, final CharsetEncoder encoder)

Construct a new ReaderInputStream.

Parameters
reader:Reader

the target Reader

encoder:CharsetEncoder

the charset encoder

Since
1.10.9
ReaderInputStreamback to summary
public ReaderInputStream(final Reader reader, final CharsetEncoder encoder, final int bufferSize)

Construct a new ReaderInputStream.

Parameters
reader:Reader

the target Reader

encoder:CharsetEncoder

the charset encoder

bufferSize:int

the size of the input buffer in number of characters

Since
1.10.9
ReaderInputStreamback to summary
public ReaderInputStream(Reader reader)

Construct a ReaderInputStream for the specified Reader.

Parameters
reader:Reader

Reader. Must not be null.

ReaderInputStreamback to summary
public ReaderInputStream(Reader reader, String encoding)

Construct a ReaderInputStream for the specified Reader, with the specified encoding.

Parameters
reader:Reader

non-null Reader.

encoding:String

non-null String encoding.

ReaderInputStreamback to summary
public ReaderInputStream(Reader reader, Charset charset)

Construct a ReaderInputStream for the specified Reader, with the specified encoding.

Parameters
reader:Reader

non-null Reader.

charset:Charset

non-null Charset charset.

Since
Ant 1.10.6

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Close the stream. This method will cause the underlying Reader to be closed.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
fillBufferback to summary
private void fillBuffer() throws IOException

Fills the internal char buffer from the reader.

Exceptions
IOException:
If an I/O error occurs
readback to summary
public int read(final byte[] array, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Read the specified number of bytes into an array.

Parameters
array:byte[]

the byte array to read into

off:int

the offset to start reading bytes into

len:int

the number of bytes to read

Returns:int

the number of bytes read or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
readback to summary
public int read(final byte[] b) throws IOException

Overrides java.io.InputStream.read.

Read the specified number of bytes into an array.

Parameters
b:byte[]

the byte array to read into

Returns:int

the number of bytes read or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Read a single byte.

Returns:int

either the byte read or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs