ucar.unidata.util
Class ByteString

java.lang.Object
  extended by ucar.unidata.util.ByteString
All Implemented Interfaces:
Serializable, Comparable
Direct Known Subclasses:
ByteString.Concrete, ByteString.Empty

public abstract class ByteString
extends Object
implements Comparable, Serializable

An immutable array of Byte. Similar to java.lang.String, but byte instead of char.

The motivation for this class is to contain meteorlogical bulletins or observations. The "text" in these is encoded in "International Alphabet Number 5", aka CCITT Recommendation T.50, essentially ISO 646, which we know as 7 bit ASCII. Any data (non-text) portion is an octet (byte) sequence. We intend to store _many_ of these, so doubling the size to String may not be acceptable. Further, since the data has archival value, we wish to minimize alteration and transformation of the data.

Version:
$Revision: 1.14 $ $Date: 2006/05/05 19:19:33 $
Author:
$Author: jeffmc $
See Also:
String, Serialized Form

Nested Class Summary
static class ByteString.Concrete
          Class Concrete
static class ByteString.Empty
          Class Empty
static class ByteString.SubString
          A ByteString implementation whose origin is offset in the underlying byte array and whose length is possibly less than the underlying byte array.
static class ByteString.TrSubString
          A ByteString implementation which which is zero based in the underlying byte array but whose length is possibly less than the underlying byte array.
 
Field Summary
static byte[] nada
          Zero length byte array to use as the contents of Empty ByteString
 
Constructor Summary
protected ByteString()
          _more_
 
Method Summary
abstract  byte byteAt(int ii)
          Returns the byte at the specified index.
static char ByteToChar8859_1(byte bb)
          Widen an 8859_1 encoded byte to Unicode char.
 char charAt(int ii)
          Returns the byte at the specified index, widened to Unicode char.
static byte CharToByte8859_1(char cc)
          Narrow Unicode char to an 8859_1 encoded byte.
static int compare(ByteString bs1, ByteString bs2)
          Compare two byte strings lexographically.
static int compare(ByteString bs1, String s2)
          Compare two byte strings lexographically.
 int compareTo(ByteString bs)
          Compare this and another byte string lexographically.
 int compareTo(Object oo)
          Compares this to another Object.
 int compareTo(String ss)
          Compare this and a String string lexographically.
static byte[] concat(byte[] b1, byte[] b2, byte sep)
          _more_
static ByteString concat(ByteString bs1, ByteString bs2, char sep)
          _more_
 byte[] copyBytes(int srcpos, byte[] dst, int dstpos, int nbytes)
          Copies bytes from this ByteString into the destination byte array.
 boolean equals(Object oo)
          _more_
 boolean equalS(String ss)
          Returns true iff this and the String argument represent the same sequence of characters.
 StringBuffer format(StringBuffer buf)
          Widen this to Unicode in a StringBuffer.
abstract  int getLength()
          Returns the length of this string.
 int hashCode()
          _more_
 int length()
          String compatible entry point for getLength();
static void main(String[] args)
          _more_
 ByteString subByteString(int beginIndex, int length)
          Returns a new string that is a substring of this string.
 ByteString substring(int beginIndex)
           
 ByteString substring(int beginIndex, int endindex)
           
 byte[] toArray()
          Converts this string to a new byte array.
 String toString()
          Widen this to a Unicode as in a String
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

nada

public static final byte[] nada
Zero length byte array to use as the contents of Empty ByteString

Constructor Detail

ByteString

protected ByteString()
_more_

Method Detail

ByteToChar8859_1

public static final char ByteToChar8859_1(byte bb)
Widen an 8859_1 encoded byte to Unicode char. (ISO 8859_1 is the java default encoding). See sun.io.ByteToChar8859_1.

Parameters:
bb -
Returns:
_more_

CharToByte8859_1

public static final byte CharToByte8859_1(char cc)
Narrow Unicode char to an 8859_1 encoded byte. (ISO 8859_1 is the java default encoding). See sun.io.CharToByte8859_1.

Parameters:
cc -
Returns:
_more_

compare

public static int compare(ByteString bs1,
                          ByteString bs2)
Compare two byte strings lexographically.

Parameters:
bs1 -
bs2 -
Returns:
_more_
See Also:
String.compareTo(java.lang.String)

compare

public static int compare(ByteString bs1,
                          String s2)
Compare two byte strings lexographically.

Parameters:
bs1 -
s2 -
Returns:
_more_
See Also:
String.compareTo(java.lang.String)

concat

public static byte[] concat(byte[] b1,
                            byte[] b2,
                            byte sep)
_more_

Parameters:
b1 -
b2 -
sep -
Returns:
_more_

concat

public static ByteString concat(ByteString bs1,
                                ByteString bs2,
                                char sep)
_more_

Parameters:
bs1 -
bs2 -
sep -
Returns:
_more_

getLength

public abstract int getLength()
Returns the length of this string. The length is equal to the number of byte elements in the string.

Returns:
The number of bytes in the string

byteAt

public abstract byte byteAt(int ii)
Returns the byte at the specified index. An index ranges from 0 to getLength() - 1. The first byte of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

Parameters:
ii - the index of the character.
Returns:
the byte at the specified index of this string.

charAt

public char charAt(int ii)
Returns the byte at the specified index, widened to Unicode char.

Parameters:
ii -
Returns:
_more_
See Also:
byteAt(int), String.charAt(int)

copyBytes

public byte[] copyBytes(int srcpos,
                        byte[] dst,
                        int dstpos,
                        int nbytes)
Copies bytes from this ByteString into the destination byte array.

The first byte to be copied is at index srcpos; The total number of bytes to be copied is nbytes. The bytes are copied into the subarray of dst starting at index dstpos.

Parameters:
srcpos - int index of the first byte to copy.
dst - the destination array.
dstpos - int start index in the destination array.
nbytes - int number of bytes to copy
Returns:
_more_

toArray

public byte[] toArray()
Converts this string to a new byte array.

Returns:
a new byte array whose length is the length of this and whose contents are initialized to the byte sequence contained herein.

subByteString

public ByteString subByteString(int beginIndex,
                                int length)
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and is length long.

The resulting substring will share the same byte storage as this.

Note: the parameters and name of this method are somewhat different than java.lang.String.substring(int,int) There is a String compatible version below.

Parameters:
beginIndex - the beginning index, inclusive.
length - int length of the substring.
Returns:
the specified substring.

substring

public ByteString substring(int beginIndex,
                            int endindex)
Parameters:
beginIndex -
endindex -
Returns:
_more_
See Also:
String.substring(int,int)

substring

public ByteString substring(int beginIndex)
Parameters:
beginIndex -
Returns:
_more_
See Also:
String.substring(int)

length

public final int length()
String compatible entry point for getLength();

Returns:
_more_
See Also:
getLength(), String.length()

compareTo

public int compareTo(ByteString bs)
Compare this and another byte string lexographically.

Parameters:
bs -
Returns:
_more_
See Also:
compare(ucar.unidata.util.ByteString, ucar.unidata.util.ByteString)

compareTo

public int compareTo(String ss)
Compare this and a String string lexographically.

Parameters:
ss -
Returns:
_more_
See Also:
compare(ucar.unidata.util.ByteString, ucar.unidata.util.ByteString)

compareTo

public int compareTo(Object oo)
Compares this to another Object. If the Object is a ByteString, this function behaves like compareTo(ByteString). Otherwise, it throws a ClassCastException.

Specified by:
compareTo in interface Comparable
Parameters:
oo -
Returns:
_more_

format

public StringBuffer format(StringBuffer buf)
Widen this to Unicode in a StringBuffer.

Parameters:
buf -
Returns:
_more_

hashCode

public int hashCode()
_more_

Overrides:
hashCode in class Object
Returns:
_more_

equals

public boolean equals(Object oo)
_more_

Overrides:
equals in class Object
Parameters:
oo -
Returns:
_more_

equalS

public boolean equalS(String ss)
Returns true iff this and the String argument represent the same sequence of characters.

Parameters:
ss -
Returns:
_more_

toString

public String toString()
Widen this to a Unicode as in a String

Overrides:
toString in class Object
Returns:
_more_

main

public static void main(String[] args)
_more_

Parameters:
args -