Package org.postgresql.util
Class ReaderInputStream
java.lang.Object
java.io.InputStream
org.postgresql.util.ReaderInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
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
FieldsModifier and TypeFieldDescriptionprivate final ByteBuffer
private final CharBuffer
private static final int
private final CharsetEncoder
private boolean
true when all of the characters have been read from the reader into inbuf.private final byte[]
private final Reader
-
Constructor Summary
ConstructorsConstructorDescriptionReaderInputStream
(Reader reader) ReaderInputStream
(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
Modifier and TypeMethodDescriptionprivate void
advance()
private void
checkEncodeResult
(CoderResult result) void
close()
int
read()
int
read
(byte[] b, int off, int len) Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
DEFAULT_CHAR_BUFFER_SIZE
private static final int DEFAULT_CHAR_BUFFER_SIZE- See Also:
-
reader
-
encoder
-
bbuf
-
cbuf
-
endOfInput
private boolean endOfInputtrue when all of the characters have been read from the reader into inbuf. -
oneByte
private final byte[] oneByte
-
-
Constructor Details
-
ReaderInputStream
-
ReaderInputStream
ReaderInputStream(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 Details
-
advance
- Throws:
IOException
-
checkEncodeResult
- Throws:
CharacterCodingException
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-