Top Description Inners Fields Constructors Methods
org.apache.derby.iapi.jdbc

public Class CharacterStreamDescriptor

extends Object
Class Inheritance
Imports
java.io.InputStream, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.types.PositionedStream

A description of a byte stream representing characters. The description is used by decoders to properly configure themselves. Note that encoding is not included in the description, because all internal byte streams are expected to be using the modified UTF-8 encoding (see DataInput).

The information in the description is only guaranteed to be valid at the moment it is passed to the decoder object. As the decoder works on the stream, the information in the descriptor will be outdated.

To create a stream descriptor, obtain a Builder instance and set the required parameters.

See Also
Builder

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
CharacterStreamDescriptor.Builder

The builder for the CharacterStreamDescriptor class.

Field Summary

Modifier and TypeField and Description
public static final long
BEFORE_FIRST

Constant for the character position, when it is positioned before the first character in the stream (i.e. at the very beginning of the stream or in the header).

private final boolean
bufferable

Tells if the stream can be buffered or not.

private final long
byteLength

The byte length of the stream, 0 if unknown.

private final long
charLength

The character length of the stream, 0 if unknown.

private final long
curBytePos

The current byte position.

private final long
curCharPos

The current character position.

private final long
dataOffset

First data byte in the byte stream.

private final long
maxCharLength

The maximum allowed character length.

private final boolean
positionAware

Tells if the stream is aware of its own position.

private final InputStream
stream

Reference to the stream we are describing.

Constructor Summary

AccessConstructor and Description
private
CharacterStreamDescriptor(CharacterStreamDescriptor.Builder
object builder
b
)

Creates a character stream descriptor, using the supplied builder.

Method Summary

Modifier and TypeMethod and Description
public long
public long
public long
public long

Returns:

The current character position, where the first character is at position 1, or BEFORE_FIRST if the stream is positioned before the first character.
getCurCharPos
()

Returns the current character position.

public long

Returns:

The first position in the stream containing real data.
getDataOffset
()

Returns the first index of the described stream that contains real data.

public long

Returns:

The max allowed character length of the stream, or 0 if no limit has been set.
getMaxCharLength
()

Returns the imposed maximum character length on the described stream.

public PositionedStream

Returns:

A PositionedStream reference.
getPositionedStream
()

Returns the associated positioned stream, if the stream is position aware.

public InputStream

Returns:

An InputStream reference.
getStream
()

Returns the associated stream.

public boolean

Returns:

true if the stream should be buffered for improved performance, false if it should not be buffered.
isBufferable
()

Tells if the described stream should be buffered or not.

public boolean

Returns:

true if the stream is position aware, @{code false} otherwise.
isPositionAware
()

Tells if the described stream is aware of its own position, and that it can reposition itself on request.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

BEFORE_FIRSTback to summary
public static final long BEFORE_FIRST

Constant for the character position, when it is positioned before the first character in the stream (i.e. at the very beginning of the stream or in the header).

bufferableback to summary
private final boolean bufferable

Tells if the stream can be buffered or not.

byteLengthback to summary
private final long byteLength

The byte length of the stream, 0 if unknown.

charLengthback to summary
private final long charLength

The character length of the stream, 0 if unknown.

curBytePosback to summary
private final long curBytePos

The current byte position.

curCharPosback to summary
private final long curCharPos

The current character position.

dataOffsetback to summary
private final long dataOffset

First data byte in the byte stream.

maxCharLengthback to summary
private final long maxCharLength

The maximum allowed character length.

positionAwareback to summary
private final boolean positionAware

Tells if the stream is aware of its own position.

streamback to summary
private final InputStream stream

Reference to the stream we are describing.

Constructor Detail

CharacterStreamDescriptorback to summary
private CharacterStreamDescriptor(CharacterStreamDescriptor.Builder b)

Creates a character stream descriptor, using the supplied builder.

Use the builder to create instances of this class.

Parameters
b:CharacterStreamDescriptor.Builder

object builder

See Also
Builder

Method Detail

getByteLengthback to summary
public long getByteLength()
getCharLengthback to summary
public long getCharLength()
getCurBytePosback to summary
public long getCurBytePos()
getCurCharPosback to summary
public long getCurCharPos()

Returns the current character position.

Returns:long

The current character position, where the first character is at position 1, or BEFORE_FIRST if the stream is positioned before the first character.

getDataOffsetback to summary
public long getDataOffset()

Returns the first index of the described stream that contains real data.

The information is typically used to filter out meta data at the head of the stream, and to correctly reset the stream.

Returns:long

The first position in the stream containing real data.

getMaxCharLengthback to summary
public long getMaxCharLength()

Returns the imposed maximum character length on the described stream.

The default value is Long.MAX_VALUE.

Returns:long

The max allowed character length of the stream, or 0 if no limit has been set.

getPositionedStreamback to summary
public PositionedStream getPositionedStream()

Returns the associated positioned stream, if the stream is position aware.

Returns:PositionedStream

A PositionedStream reference.

Exceptions
ClassCastException:
if the stream cannot be cast to PositionedStream
IllegalArgumentException:
if the method is called and the assoicated stream isn't described as position aware.
See Also
isPositionAware
getStreamback to summary
public InputStream getStream()

Returns the associated stream.

Returns:InputStream

An InputStream reference.

isBufferableback to summary
public boolean isBufferable()

Tells if the described stream should be buffered or not.

Some of the reasons a stream should not be buffered at this level, are the stream is already buffered, or it serves bytes directly from a byte array in memory.

Returns:boolean

true if the stream should be buffered for improved performance, false if it should not be buffered.

isPositionAwareback to summary
public boolean isPositionAware()

Tells if the described stream is aware of its own position, and that it can reposition itself on request.

Returns:boolean

true if the stream is position aware, @{code false} otherwise.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

org.apache.derby.iapi.jdbc back to summary

public Class CharacterStreamDescriptor.Builder

extends Object
Class Inheritance

The builder for the CharacterStreamDescriptor class. The builder is used to avoid having a large set of constructors. See the build method for pre-build field validation. Note that the validation is only performed in sane builds.

Field Summary

Modifier and TypeField and Description
private boolean
private long
private long
private long
private long
private long
private static final long
DEFAULT_MAX_CHAR_LENGTH

Default max character length is unlimited.

private long
private boolean
private InputStream

Constructor Summary

AccessConstructor and Description
public
Builder()

Creates a builder object.

Method Summary

Modifier and TypeMethod and Description
public CharacterStreamDescriptor.Builder

Returns:

The builder.
bufferable
(boolean
true if buffering is advised, false if not
bufferable
)

Sets if the stream should be buffered, defaults to false.

public CharacterStreamDescriptor

Returns:

A character stream descriptor instance.
build
()

Creates a descriptor object based on the parameters kept in the builder instance.

public CharacterStreamDescriptor.Builder

Returns:

The builder.
byteLength
(long
the byte length of the stream (including header)
length
)

Sets the byte length of the stream, defaults to 0.

public CharacterStreamDescriptor.Builder

Returns:

The builder.
charLength
(long
the character length of the stream
length
)

Sets the character length of the stream, defaults to 0.

public CharacterStreamDescriptor.Builder

Returns:

The builder.
copyState
(CharacterStreamDescriptor
the descriptor to copy
csd
)

Copies the state of the specified descriptor.

public CharacterStreamDescriptor.Builder

Returns:

The builder.
curBytePos
(long
the current byte position
pos
)

Sets the current byte position, defaults to 0.

public CharacterStreamDescriptor.Builder

Returns:

The builder.
curCharPos
(long
the current character position,starting at 1
pos
)

Sets the current character position, defaults to 1.

public CharacterStreamDescriptor.Builder

Returns:

The builder.
dataOffset
(long
first index with user data, zero based
offset
)

Sets the offset of the user data, defaults to 0.

public CharacterStreamDescriptor.Builder

Returns:

The builder.
maxCharLength
(long
maximum number of characters
length
)

Imposes a length limit on the stream, expressed in number of characters, defaults to Long.MAX_VALUE.

public CharacterStreamDescriptor.Builder

Returns:

The builder.
positionAware
(boolean
true if the stream can reposition itself, false if not
positionAware
)

Sets if the stream can reposition itself or not, defaults to false.

public CharacterStreamDescriptor.Builder

Returns:

The builder.
stream
(InputStream
the stream
stream
)

Sets the stream described by the descriptor.

public String

Returns:

The textual representation of the builder.
toString
()

Overrides java.lang.Object.toString.

Returns a textual representation of the builder.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bufferableback to summary
private boolean bufferable
byteLengthback to summary
private long byteLength
charLengthback to summary
private long charLength
curBytePosback to summary
private long curBytePos
curCharPosback to summary
private long curCharPos
dataOffsetback to summary
private long dataOffset
DEFAULT_MAX_CHAR_LENGTHback to summary
private static final long DEFAULT_MAX_CHAR_LENGTH

Default max character length is unlimited.

maxCharLengthback to summary
private long maxCharLength
positionAwareback to summary
private boolean positionAware
streamback to summary
private InputStream stream

Constructor Detail

Builderback to summary
public Builder()

Creates a builder object.

Method Detail

bufferableback to summary
public CharacterStreamDescriptor.Builder bufferable(boolean bufferable)

Sets if the stream should be buffered, defaults to false.

Parameters
bufferable:boolean

true if buffering is advised, false if not

Returns:CharacterStreamDescriptor.Builder

The builder.

buildback to summary
public CharacterStreamDescriptor build()

Creates a descriptor object based on the parameters kept in the builder instance.

Default values will be used for parameters for which a value hasn't been set.

Note

Parameter validation is only performed in sane builds.

Returns:CharacterStreamDescriptor

A character stream descriptor instance.

byteLengthback to summary
public CharacterStreamDescriptor.Builder byteLength(long length)

Sets the byte length of the stream, defaults to 0.

A length of 0 means the length is unknown.

Parameters
length:long

the byte length of the stream (including header)

Returns:CharacterStreamDescriptor.Builder

The builder.

charLengthback to summary
public CharacterStreamDescriptor.Builder charLength(long length)

Sets the character length of the stream, defaults to 0.

Headers are not included in this length, only the user data. A length of 0 means the length is unknown.

Parameters
length:long

the character length of the stream

Returns:CharacterStreamDescriptor.Builder

The builder.

copyStateback to summary
public CharacterStreamDescriptor.Builder copyState(CharacterStreamDescriptor csd)

Copies the state of the specified descriptor.

Parameters
csd:CharacterStreamDescriptor

the descriptor to copy

Returns:CharacterStreamDescriptor.Builder

The builder.

curBytePosback to summary
public CharacterStreamDescriptor.Builder curBytePos(long pos)

Sets the current byte position, defaults to 0.

Parameters
pos:long

the current byte position

Returns:CharacterStreamDescriptor.Builder

The builder.

curCharPosback to summary
public CharacterStreamDescriptor.Builder curCharPos(long pos)

Sets the current character position, defaults to 1.

There is a special value for when the stream is position in the header area - BEFORE_FIRST.

Parameters
pos:long

the current character position,starting at 1

Returns:CharacterStreamDescriptor.Builder

The builder.

See Also
BEFORE_FIRST
dataOffsetback to summary
public CharacterStreamDescriptor.Builder dataOffset(long offset)

Sets the offset of the user data, defaults to 0.

Parameters
offset:long

first index with user data, zero based

Returns:CharacterStreamDescriptor.Builder

The builder.

maxCharLengthback to summary
public CharacterStreamDescriptor.Builder maxCharLength(long length)

Imposes a length limit on the stream, expressed in number of characters, defaults to Long.MAX_VALUE.

Parameters
length:long

maximum number of characters

Returns:CharacterStreamDescriptor.Builder

The builder.

positionAwareback to summary
public CharacterStreamDescriptor.Builder positionAware(boolean positionAware)

Sets if the stream can reposition itself or not, defaults to false.

Parameters
positionAware:boolean

true if the stream can reposition itself, false if not

Returns:CharacterStreamDescriptor.Builder

The builder.

streamback to summary
public CharacterStreamDescriptor.Builder stream(InputStream stream)

Sets the stream described by the descriptor.

The stream is not allowed to be null.

Parameters
stream:InputStream

the stream

Returns:CharacterStreamDescriptor.Builder

The builder.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a textual representation of the builder.

Returns:String

The textual representation of the builder.