org.apache.derby.impl.drda
Class DRDAString

java.lang.Object
  extended by org.apache.derby.impl.drda.DRDAString

final class DRDAString
extends java.lang.Object

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
private  byte[] buffer
          Buffer representing the string.
private  java.lang.String cachedString
          The previously generated string.
private  CcsidManager ccsidManager
          Object used to convert byte buffer to string.
private  boolean modified
          True if the contents were modified in the previous call to setBytes.
 
Constructor Summary
DRDAString(CcsidManager m)
          Create a new DRDAString instance.
 
Method Summary
private  boolean equalTo(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.
 int length()
          Return the length in bytes of the internal string representation.
 void setBytes(byte[] src, int offset, int size)
          Modify the internal byte buffer.
 java.lang.String toString()
          Convert the internal byte array to a string.
 boolean wasModified()
          Check whether the contents of the DRDAString were modified in the previous call to setBytes().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buffer

private byte[] buffer
Buffer representing the string.


ccsidManager

private final CcsidManager ccsidManager
Object used to convert byte buffer to string.


modified

private boolean modified
True if the contents were modified in the previous call to setBytes.


cachedString

private java.lang.String cachedString
The previously generated string.

Constructor Detail

DRDAString

DRDAString(CcsidManager m)
Create a new DRDAString instance.

Parameters:
m - a CcsidManager value specifying which encoding is used
Method Detail

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 array
offset - start position in the byte array
size - how many bytes to read from the byte array
Returns:
true if 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 bytes
offset - start offset
size - number of bytes to use

wasModified

public boolean wasModified()
Check whether the contents of the DRDAString were modified in the previous call to setBytes().

Returns:
true if the contents were modified

toString

public java.lang.String toString()
Convert the internal byte array to a string. The string value is cached.

Overrides:
toString in class java.lang.Object
Returns:
a String value

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 in DRDAString. The value of the array might be modified by subsequent calls to DRDAString.setBytes().

Returns:
internal buffer

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

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