Class DRDAString
java.lang.Object
org.apache.derby.impl.drda.DRDAString
This class provides functionality for reusing buffers and strings
when parsing DRDA packets. A byte array representing a string is
stored internally. When the string is requested as a
String object, the byte array is converted to a
string, and the string is cached to avoid unnecessary conversion
later.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]Buffer representing the string.private StringThe previously generated string.private booleanTrue if the contents were modified in the previous call tosetBytes.private final DDMWriterKeep the DDMWriter as it contains the current CCSID manager being used -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanequalTo(byte[] buf, int offset, int size) Check whether the internal buffer contains the same data as another byte buffer.byte[]getBytes()Return the internal byte array.intlength()Return the length in bytes of the internal string representation.voidsetBytes(byte[] src, int offset, int size) Modify the internal byte buffer.toString()Convert the internal byte array to a string.booleanCheck whether the contents of theDRDAStringwere modified in the previous call tosetBytes().
-
Field Details
-
buffer
private byte[] bufferBuffer representing the string. -
writer
Keep the DDMWriter as it contains the current CCSID manager being used -
modified
private boolean modifiedTrue if the contents were modified in the previous call tosetBytes. -
cachedString
The previously generated string.
-
-
Constructor Details
-
DRDAString
DRDAString(DDMWriter w) Create a newDRDAStringinstance.- Parameters:
w- aDDMWriterwhich holds current CCSidManager and which encoding is used
-
-
Method Details
-
equalTo
private boolean equalTo(byte[] buf, int offset, int size) Check whether the internal buffer contains the same data as another byte buffer.- Parameters:
buf- a byte arrayoffset- start position in the byte arraysize- how many bytes to read from the byte array- Returns:
trueif the internal buffer contains the same data as the specified byte array
-
setBytes
public void setBytes(byte[] src, int offset, int size) Modify the internal byte buffer. If the new data is equal to the old data, the cached values are not cleared.- Parameters:
src- the new bytesoffset- start offsetsize- number of bytes to use
-
wasModified
public boolean wasModified()Check whether the contents of theDRDAStringwere modified in the previous call tosetBytes().- Returns:
trueif the contents were modified
-
toString
-
length
public int length()Return the length in bytes of the internal string representation.- Returns:
- length of internal representation
-
getBytes
public byte[] getBytes()Return the internal byte array. The returned array should not be modified, as it is used internally inDRDAString. The value of the array might be modified by subsequent calls toDRDAString.setBytes().- Returns:
- internal buffer
-