org.apache.derby.iapi.types
Class CharStreamHeaderGenerator

java.lang.Object
  extended by 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:

The length is encoded like this:
            out.writeByte((byte)(byteLength >>> 8));
            out.writeByte((byte)(byteLength >>> 0));
 


Field Summary
private static int MAX_ENCODABLE_LENGTH
          The maximum length that can be encoded by the header.
 
Fields inherited from interface org.apache.derby.iapi.types.StreamHeaderGenerator
DERBY_EOF_MARKER
 
Constructor Summary
CharStreamHeaderGenerator()
           
 
Method Summary
 boolean expectsCharCount()
          A byte count is expected.
 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.
 int generateInto(java.io.ObjectOutput out, long byteLength)
          Generates the header for the specified length.
 int getMaxHeaderLength()
          Returns the maximum header length.
 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.
 int writeEOF(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
Constructor Detail

CharStreamHeaderGenerator

public CharStreamHeaderGenerator()
Method Detail

expectsCharCount

public boolean expectsCharCount()
A byte count is expected.

Specified by:
expectsCharCount in interface StreamHeaderGenerator
Returns:
false.

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:
generateInto in interface StreamHeaderGenerator
Parameters:
buffer - the buffer to write into
offset - starting offset in the buffer
byteLength - 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.IOException
Generates the header for the specified length.

Specified by:
generateInto in interface StreamHeaderGenerator
Parameters:
out - the destination stream
byteLength - 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:
writeEOF in interface StreamHeaderGenerator
Parameters:
buffer - the buffer to write into
offset - starting offset in the buffer
byteLength - 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.IOException
Writes a Derby-specific end-of-stream marker to the destination stream for the specified byte length, if required.

Specified by:
writeEOF in interface StreamHeaderGenerator
Parameters:
out - the destination stream
byteLength - 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:
getMaxHeaderLength in interface StreamHeaderGenerator
Returns:
Maximum header length in bytes.

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.