public class ReaderInputStream
extends java.io.InputStream
ReaderInputStream accepts a UTF-16 char stream (Reader) as input and converts it to a UTF-8 byte stream (InputStream) as output.
This is the inverse of java.io.InputStreamReader which converts a binary stream to a character stream.
Modifier and Type | Field and Description |
---|---|
private java.nio.ByteBuffer |
bbuf |
private java.nio.CharBuffer |
cbuf |
private static int |
DEFAULT_CHAR_BUFFER_SIZE |
private java.nio.charset.CharsetEncoder |
encoder |
private boolean |
endOfInput
true when all of the characters have been read from the reader into inbuf.
|
private byte[] |
oneByte |
private java.io.Reader |
reader |
private static java.nio.charset.Charset |
UTF_8 |
Constructor and Description |
---|
ReaderInputStream(java.io.Reader reader) |
ReaderInputStream(java.io.Reader reader,
int charBufferSize)
Allow ReaderInputStreamTest to use small buffers to force UTF-16
surrogate pairs to cross buffer boundaries in interesting ways.
|
Modifier and Type | Method and Description |
---|---|
private void |
advance() |
private void |
checkEncodeResult(java.nio.charset.CoderResult result) |
void |
close() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
private static final int DEFAULT_CHAR_BUFFER_SIZE
private static final java.nio.charset.Charset UTF_8
private final java.io.Reader reader
private final java.nio.charset.CharsetEncoder encoder
private final java.nio.ByteBuffer bbuf
private final java.nio.CharBuffer cbuf
private boolean endOfInput
private final byte[] oneByte
public ReaderInputStream(java.io.Reader reader)
ReaderInputStream(java.io.Reader reader, int charBufferSize)
private void advance() throws java.io.IOException
java.io.IOException
private void checkEncodeResult(java.nio.charset.CoderResult result) throws java.nio.charset.CharacterCodingException
java.nio.charset.CharacterCodingException
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException