Package org.restlet.engine.io
Class ReaderInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.restlet.engine.io.ReaderInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ReaderInputStream extends java.io.InputStreamInput stream based on a reader. The implementation relies on the NIOCharsetEncoderclass.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBufferbyteBufferThe NIO byte buffer.private java.nio.CharBuffercharBufferThe NIO character buffer.private java.nio.charset.CharsetEncodercharsetEncoderThe character set encoder.private booleanendReachedIndicates if the end of the wrapped reader has been reached.private java.io.BufferedReaderreaderThe wrapped reader.
-
Constructor Summary
Constructors Constructor Description ReaderInputStream(java.io.Reader reader)Constructor.ReaderInputStream(java.io.Reader reader, CharacterSet characterSet)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()Closes the wrapped reader.intread()intread(byte[] b, int off, int len)
-
-
-
Field Detail
-
byteBuffer
private final java.nio.ByteBuffer byteBuffer
The NIO byte buffer.
-
charBuffer
private final java.nio.CharBuffer charBuffer
The NIO character buffer.
-
charsetEncoder
private final java.nio.charset.CharsetEncoder charsetEncoder
The character set encoder.
-
endReached
private volatile boolean endReached
Indicates if the end of the wrapped reader has been reached.
-
reader
private final java.io.BufferedReader reader
The wrapped reader.
-
-
Constructor Detail
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader) throws java.io.IOExceptionConstructor. Uses theCharacterSet.ISO_8859_1character set by default.- Parameters:
reader- The reader to wrap as an input stream.- Throws:
java.io.IOException
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader, CharacterSet characterSet) throws java.io.IOExceptionConstructor.- Parameters:
reader- The reader to wrap as an input stream.characterSet- The character set to use for encoding.- Throws:
java.io.IOException
-
-
Method Detail
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.InputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionCloses the wrapped reader.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
-