com.tivoli.twg.libs
Class CompUnicodeString

java.lang.Object
  extended bycom.tivoli.twg.libs.CompUnicodeString
All Implemented Interfaces:
java.io.Serializable

public class CompUnicodeString
extends java.lang.Object
implements java.io.Serializable

A class for converting strings encoded using the NetFinity-style compressed unicode format to and from straight unicode Java Strings. NetFinity-style compressed unicode format is a 7 bits-per-byte format, with the high bit (bit 7) set to indicate that the next byte provides additional data bits, or clear if all higher bits are zero. This causes the following mapping:

   0u0001 - 0u007F <-> one byte coding
                       [ 0 (b06) (b05) (b04) (b01) (b00) (b03) (b02) ]
   0u0080 - 0u3FFF <-> two byte coding, with bit 7 of byte 1 set
                       [ 1 (b06) (b05) (b04) (b01) (b00) (b03) (b02) ]
                       [ 0 (b13) (b12) (b11) (b08) (b07) (b10) (b09) ]
   0u4000 - 0uFFFF <-> three byte coding, with bit 7 of byte 1 and
                       2 set
                       [ 1 (b06) (b05) (b04) (b01) (b00) (b03) (b02) ]
                       [ 1 (b13) (b12) (b11) (b08) (b07) (b10) (b09) ]
                       [ 0   0     0     0   (b15) (b14)   0     0   ]
 

Also, bit 0 is exchanged with bit 2, and bit 1 is exchanged with bit 3 in each of the encoded bytes.

See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
CompUnicodeString(byte[] comp_ucode, int start_offset)
          Creates a CompUnicodeString from a byte array encoded in NetFinity-style compressed unicode format.
CompUnicodeString(java.lang.String s)
          Creates a CompUnicodeString from a provided String.
 
Method Summary
 byte[] getCompUnicode()
          Return byte array with compressed unicode encoding of value.
static int GetEncodedLength(java.lang.String s)
          Compute number of bytes needed for compressed unicode encoding of a given string.
 java.lang.String getString()
          Return value of compressed unicode string as String.
static boolean isEqual(java.lang.String str, byte[] buf, int off)
          Compare a Java string with a compressed unicode string in a byte array.
static java.lang.String readString(byte[] strbuf, int off)
          Read compressed unicode encoded string as java string
static int writeString(java.lang.String str, byte[] buf, int off)
          Write compressed unicode encoding of string into buffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

CompUnicodeString

public CompUnicodeString(java.lang.String s)
Creates a CompUnicodeString from a provided String.

Parameters:
s - the unicode string value

CompUnicodeString

public CompUnicodeString(byte[] comp_ucode,
                         int start_offset)
Creates a CompUnicodeString from a byte array encoded in NetFinity-style compressed unicode format.

Parameters:
comp_ucode - Array of bytes containing encoded string
start_offset - Offset in array of beginning of encoded string
Method Detail

GetEncodedLength

public static final int GetEncodedLength(java.lang.String s)
Compute number of bytes needed for compressed unicode encoding of a given string.

Parameters:
s - - string which is to be converted

getString

public final java.lang.String getString()
Return value of compressed unicode string as String.


getCompUnicode

public final byte[] getCompUnicode()
Return byte array with compressed unicode encoding of value.


isEqual

public static boolean isEqual(java.lang.String str,
                              byte[] buf,
                              int off)
Compare a Java string with a compressed unicode string in a byte array.

Parameters:
str - - string to be compared
buf - - buffer containing compressed unicode string
off - - offset of compressed unicode string in buffer
Returns:
true if equal, false if not

readString

public static final java.lang.String readString(byte[] strbuf,
                                                int off)
Read compressed unicode encoded string as java string

Parameters:
strbuf - - buffer containing string
off - - offset of string
Returns:
string read from buffer

writeString

public static final int writeString(java.lang.String str,
                                    byte[] buf,
                                    int off)
Write compressed unicode encoding of string into buffer

Parameters:
str - - string to be encoded
buf - - buffer to write to
off - - offset of start of write
Returns:
offset of next available byte after write