org.apache.tools.ant.util

Class ReaderInputStream

public class ReaderInputStream extends InputStream

Adapts a Reader as an InputStream. Adapted from StringInputStream.
Constructor Summary
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.
Method Summary
intavailable()
voidclose()
Closes the Stringreader.
voidmark(int limit)
Marks the read limit of the StringReader.
booleanmarkSupported()
intread()
Reads from the Reader, returning the same value.
intread(byte[] b, int off, int len)
Reads from the Reader into a byte array
voidreset()
Resets the StringReader.

Constructor Detail

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.

Method Detail

available

public int available()

Returns: the current number of bytes ready for reading

Throws: IOException if an error occurs

close

public void close()
Closes the Stringreader.

Throws: IOException if the original StringReader fails to be closed

mark

public void mark(int limit)
Marks the read limit of the StringReader.

Parameters: limit the maximum limit of bytes that can be read before the mark position becomes invalid

markSupported

public boolean markSupported()

Returns: false - mark is not supported

read

public int read()
Reads from the Reader, returning the same value.

Returns: the value of the next character in the Reader.

Throws: IOException if the original Reader fails to be read

read

public int read(byte[] b, int off, int len)
Reads from the Reader into a byte array

Parameters: b the byte array to read into off the offset in the byte array len the length in the byte array to fill

Returns: the actual number read into the byte array, -1 at the end of the stream

Throws: IOException if an error occurs

reset

public void reset()
Resets the StringReader.

Throws: IOException if the StringReader fails to be reset

Copyright