Package org.apache.derby.iapi.types
Class CharStreamHeaderGenerator
- java.lang.Object
-
- org.apache.derby.iapi.types.CharStreamHeaderGenerator
-
- All Implemented Interfaces:
StreamHeaderGenerator
public final class CharStreamHeaderGenerator extends java.lang.Object implements StreamHeaderGenerator
Generates stream headers for non-Clob string data types.The stream header encodes the byte length of the stream. Since two bytes are used for the header, the maximum encodable length is 65535 bytes. There are three special cases, all handled by encoding zero into the header and possibly appending an EOF-marker to the stream:
- Unknown length - with EOF marker
- Length longer than maximum encodable length - with EOF marker
- Length of zero - no EOF marker
out.writeByte((byte)(byteLength >>> 8)); out.writeByte((byte)(byteLength >>> 0));
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[]DERBY_EOF_MARKERThe Derby-specific end-of-stream marker.private static intMAX_ENCODABLE_LENGTHThe maximum length that can be encoded by the header.
-
Constructor Summary
Constructors Constructor Description CharStreamHeaderGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexpectsCharCount()A byte count is expected.intgenerateInto(byte[] buffer, int offset, long byteLength)Generates the header for the specified length and writes it into the provided buffer, starting at the specified offset.intgenerateInto(java.io.ObjectOutput out, long byteLength)Generates the header for the specified length.intgetMaxHeaderLength()Returns the maximum header length.intwriteEOF(byte[] buffer, int offset, long byteLength)Writes a Derby-specific end-of-stream marker to the buffer for a stream of the specified byte length, if required.intwriteEOF(java.io.ObjectOutput out, long byteLength)Writes a Derby-specific end-of-stream marker to the destination stream for the specified byte length, if required.static intwriteEOFMarker(byte[] buffer, int offset)Write the EOF marker to a byte array and return the EOF marker's lengthstatic intwriteEOFMarker(java.io.ObjectOutput out)Write the EOF marker to an Object stream and return the EOF marker's length
-
-
-
Field Detail
-
DERBY_EOF_MARKER
private static final byte[] DERBY_EOF_MARKER
The Derby-specific end-of-stream marker.
-
MAX_ENCODABLE_LENGTH
private static final int MAX_ENCODABLE_LENGTH
The maximum length that can be encoded by the header.- See Also:
- Constant Field Values
-
-
Method Detail
-
expectsCharCount
public boolean expectsCharCount()
A byte count is expected.- Specified by:
expectsCharCountin interfaceStreamHeaderGenerator- Returns:
false.
-
writeEOFMarker
public static int writeEOFMarker(byte[] buffer, int offset)Write the EOF marker to a byte array and return the EOF marker's length
-
writeEOFMarker
public static int writeEOFMarker(java.io.ObjectOutput out) throws java.io.IOExceptionWrite the EOF marker to an Object stream and return the EOF marker's length- Throws:
java.io.IOException
-
generateInto
public int generateInto(byte[] buffer, int offset, long byteLength)Generates the header for the specified length and writes it into the provided buffer, starting at the specified offset.- Specified by:
generateIntoin interfaceStreamHeaderGenerator- Parameters:
buffer- the buffer to write intooffset- starting offset in the bufferbyteLength- the length to encode in the header- Returns:
- The number of bytes written into the buffer.
-
generateInto
public int generateInto(java.io.ObjectOutput out, long byteLength) throws java.io.IOExceptionGenerates the header for the specified length.- Specified by:
generateIntoin interfaceStreamHeaderGenerator- Parameters:
out- the destination streambyteLength- the byte length to encode in the header- Returns:
- The number of bytes written to the destination stream.
- Throws:
java.io.IOException- if writing to the destination stream fails
-
writeEOF
public int writeEOF(byte[] buffer, int offset, long byteLength)Writes a Derby-specific end-of-stream marker to the buffer for a stream of the specified byte length, if required.- Specified by:
writeEOFin interfaceStreamHeaderGenerator- Parameters:
buffer- the buffer to write intooffset- starting offset in the bufferbyteLength- the byte length of the stream- Returns:
- Number of bytes written (zero or more).
-
writeEOF
public int writeEOF(java.io.ObjectOutput out, long byteLength) throws java.io.IOExceptionWrites a Derby-specific end-of-stream marker to the destination stream for the specified byte length, if required.- Specified by:
writeEOFin interfaceStreamHeaderGenerator- Parameters:
out- the destination streambyteLength- the length of the stream- Returns:
- Number of bytes written (zero or more).
- Throws:
java.io.IOException- if writing to the destination stream fails
-
getMaxHeaderLength
public int getMaxHeaderLength()
Returns the maximum header length.- Specified by:
getMaxHeaderLengthin interfaceStreamHeaderGenerator- Returns:
- Maximum header length in bytes.
-
-