java.io.Reader to a stream
returning the data in the on-disk modified UTF-8 encoded representation used
by Derby.
Length validation is performed. If required and allowed by the target column type, truncation of blanks will also be performed.
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private int | |
| private byte[] | buffer
Buffer to hold the data read from stream and converted to the modified UTF-8 format. |
| private int | charCount
The number of chars encoded. |
| private final int | charsToTruncate
Number of characters to truncate from this stream. |
| private boolean | |
| private static final int | FIRST_READ
Constant indicating the first iteration of |
| private final StreamHeaderGenerator | hdrGen
The generator for the stream header to use for this stream. |
| private int | headerLength
The length of the header. |
| private int | |
| private static final int | MARK_UNSET_OR_EXCEEDED
Constant indicating that no mark is set in the stream, or that the read ahead limit of the mark has been exceeded. |
| private boolean | multipleBuffer
Tells if the stream content is/was larger than the buffer size. |
| private static final int | READ_BUFFER_RESERVATION
Buffer space reserved for one 3 byte encoded char and the EOF marker. |
| private int | readAheadLimit
Read ahead limit for mark, set through mark(int). |
| private LimitReader | reader
Application's reader wrapped in a LimitReader. |
| private static final char | |
| private final String | typeName
The type name for the column data is inserted into. |
| private final int | valueLength
If positive, length of the expected final value, after truncation if any, in characters. |
| Access | Constructor and Description |
|---|---|
| public | ReaderToUTF8Stream(Reader
application reader appReader, int the expected length of the reader in characters
(positive), or the inverse (maxColWidth * -1) of the maximum column
width if the expected stream length is unknown valueLength, int the number of trailing blanks to truncate numCharsToTruncate, String type name of the column data is inserted into typeName, StreamHeaderGenerator the stream header generator headerGenerator)Create a stream that will truncate trailing blanks if required/allowed. |
| public | ReaderToUTF8Stream(Reader
application reader appReader, int maximum allowed length in number of characters for
the reader, typically the maximum field size maximumLength, String type name of the column data is inserted into typeName, StreamHeaderGenerator the stream header generator headerGenerator)Creates a UTF-8 stream for an application reader whose length isn't known at insertion time. |
| Modifier and Type | Method and Description |
|---|---|
| public final int | available()
Overrides java. Return an optimized version of bytes available to read from the stream. |
| private boolean | |
| private void | |
| public void | |
| private void | fillBuffer(int
offset at which to start filling the buffer, used
to avoid overwriting the stream header data on the first iteration startingOffset)Fills the internal buffer with data read from the source stream. |
| public void | mark(int
the maximum limit of bytes that can be read before
the mark position becomes invalid readAheadLimit)Overrides java. Marks the current position in the stream. |
| public boolean | Returns: true, mark/reset is always supported.Overrides java. Tests if this stream supports mark/reset. |
| public int | Returns: The byte read, or-1 if the end-of-stream is reached.Implements abstract java. Reads a byte from the stream. |
| public int | Returns: The number of bytes read, or-1 if the end-of-stream is
reached.the buffer into which the data is read. b, int the start offset in array off, int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. Reads up to |
| public void | reset()
Overrides java. Repositions this stream to the position at the time the mark method was last called on this input stream. |
| private void |
| blen | back to summary |
|---|---|
| private int blen | |
| boff | back to summary |
|---|---|
| private int boff | |
| buffer | back to summary |
|---|---|
| private byte[] buffer Buffer to hold the data read from stream and converted to the modified UTF-8 format. The initial size is dependent on whether the data value length is known (limited upwards to 32 KB), but it may grow if mark(int) is invoked. | |
| charCount | back to summary |
|---|---|
| private int charCount The number of chars encoded. | |
| charsToTruncate | back to summary |
|---|---|
| private final int charsToTruncate Number of characters to truncate from this stream. The SQL standard allows for truncation of trailing spaces for CLOB, VARCHAR and CHAR. If zero, no characters are truncated, unless the stream length exceeds the maximum length of the column we are inserting into. | |
| eof | back to summary |
|---|---|
| private boolean eof | |
| FIRST_READ | back to summary |
|---|---|
| private static final int FIRST_READ Constant indicating the first iteration of | |
| hdrGen | back to summary |
|---|---|
| private final StreamHeaderGenerator hdrGen The generator for the stream header to use for this stream.
| |
| headerLength | back to summary |
|---|---|
| private int headerLength The length of the header. | |
| mark | back to summary |
|---|---|
| private int mark Stream mark, set through mark(int). | |
| MARK_UNSET_OR_EXCEEDED | back to summary |
|---|---|
| private static final int MARK_UNSET_OR_EXCEEDED Constant indicating that no mark is set in the stream, or that the read ahead limit of the mark has been exceeded. | |
| multipleBuffer | back to summary |
|---|---|
| private boolean multipleBuffer Tells if the stream content is/was larger than the buffer size. | |
| READ_BUFFER_RESERVATION | back to summary |
|---|---|
| private static final int READ_BUFFER_RESERVATION Buffer space reserved for one 3 byte encoded char and the EOF marker. | |
| readAheadLimit | back to summary |
|---|---|
| private int readAheadLimit Read ahead limit for mark, set through mark(int). | |
| reader | back to summary |
|---|---|
| private LimitReader reader Application's reader wrapped in a LimitReader. | |
| SPACE | back to summary |
|---|---|
| private static final char SPACE | |
| typeName | back to summary |
|---|---|
| private final String typeName The type name for the column data is inserted into. | |
| valueLength | back to summary |
|---|---|
| private final int valueLength If positive, length of the expected final value, after truncation if any, in characters. If negative, the maximum length allowed in the column we are inserting into. A negative value means we are working with a stream of unknown length, inserted through one of the JDBC 4.0 "lengthless override" methods. | |
| ReaderToUTF8Stream | back to summary |
|---|---|
| public ReaderToUTF8Stream(Reader appReader, int valueLength, int numCharsToTruncate, String typeName, StreamHeaderGenerator headerGenerator) Create a stream that will truncate trailing blanks if required/allowed. If the stream must be truncated, the number of blanks to truncate is specified to allow the stream to be checked for exact length, as required by JDBC 3.0. If the stream is shorter or longer than specified, an exception is thrown during read.
| |
| ReaderToUTF8Stream | back to summary |
|---|---|
| public ReaderToUTF8Stream(Reader appReader, int maximumLength, String typeName, StreamHeaderGenerator headerGenerator) Creates a UTF-8 stream for an application reader whose length isn't known at insertion time. The application reader is coming in through one of the "lengthless overrides" added in JDBC 4.0, for instance java.sql.PreparedStatement.setCharacterStream(int,Reader). A limit is placed on the length of the application reader. If the reader exceeds the maximum length, truncation of trailing blanks is attempted. If truncation fails, an exception is thrown.
| |
| available | back to summary |
|---|---|
| public final int available() Overrides java. Return an optimized version of bytes available to read from the stream.
Note, it is not exactly per
| |
| canTruncate | back to summary |
|---|---|
| private boolean canTruncate() Determine if trailing blank truncation is allowed. | |
| checkSufficientData | back to summary |
|---|---|
| private void checkSufficientData() throws IOException Validate the length of the stream, take corrective action if allowed. JDBC 3.0 (from tutorial book) requires that an input stream has the correct number of bytes in the stream. If the stream is too long, trailing blank truncation is attempted if allowed. If truncation fails, or is disallowed, an exception is thrown.
| |
| close | back to summary |
|---|---|
| public void close() Overrides java. Implements java. return resources | |
| fillBuffer | back to summary |
|---|---|
| private void fillBuffer(int startingOffset) throws IOException Fills the internal buffer with data read from the source stream. The characters read from the source are converted to the modified UTF-8 encoding, used as the on-disk format by Derby.
| |
| mark | back to summary |
|---|---|
| public void mark(int readAheadLimit) Overrides java. Marks the current position in the stream. Note that this stream is not marked at position zero by default (i.e. in the constructor).
| |
| markSupported | back to summary |
|---|---|
| public boolean markSupported() Overrides java. Tests if this stream supports mark/reset.
The
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Reads a byte from the stream. Characters read from the source stream are converted to the UTF-8 Derby specific encoding.
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Reads up to Characters read from the source stream are converted to the UTF-8 Derby specific encoding.
| |
| reset | back to summary |
|---|---|
| public void reset() throws IOException Overrides java. Repositions this stream to the position at the time the mark method was last called on this input stream.
| |
| truncate | back to summary |
|---|---|
| private void truncate() throws IOException Attempt to truncate the stream by removing trailing blanks. | |