Package org.postgresql.util
Class ReaderInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.postgresql.util.ReaderInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
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.
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
advance()
private void
checkEncodeResult(java.nio.charset.CoderResult result)
void
close()
int
read()
int
read(byte[] b, int off, int len)
-
-
-
Field Detail
-
DEFAULT_CHAR_BUFFER_SIZE
private static final int DEFAULT_CHAR_BUFFER_SIZE
- See Also:
- Constant Field Values
-
UTF_8
private static final java.nio.charset.Charset UTF_8
-
reader
private final java.io.Reader reader
-
encoder
private final java.nio.charset.CharsetEncoder encoder
-
bbuf
private final java.nio.ByteBuffer bbuf
-
cbuf
private final java.nio.CharBuffer cbuf
-
endOfInput
private boolean endOfInput
true when all of the characters have been read from the reader into inbuf.
-
oneByte
private final byte[] oneByte
-
-
Constructor Detail
-
ReaderInputStream
public ReaderInputStream(java.io.Reader reader)
-
ReaderInputStream
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. Because this constructor is package-private, the unit test must be in the same package.
-
-
Method Detail
-
advance
private void advance() throws java.io.IOException
- Throws:
java.io.IOException
-
checkEncodeResult
private void checkEncodeResult(java.nio.charset.CoderResult result) throws java.nio.charset.CharacterCodingException
- Throws:
java.nio.charset.CharacterCodingException
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
-