Class ByteString

java.lang.Object
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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Class Concrete
    static class 
    Class Empty
    static class 
    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 
    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

    Fields
    Modifier and Type
    Field
    Description
    static final byte[]
    Zero length byte array to use as the contents of Empty ByteString
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    _more_
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract byte
    byteAt(int ii)
    Returns the byte at the specified index.
    static final char
    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 final byte
    Narrow Unicode char to an 8859_1 encoded byte.
    static int
    Compare two byte strings lexographically.
    static int
    Compare two byte strings lexographically.
    int
    Compares this to another Object.
    int
    Compare this and a String string lexographically.
    int
    Compare this and another byte 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
    _more_
    boolean
    Returns true iff this and the String argument represent the same sequence of characters.
    Widen this to Unicode in a StringBuffer.
    abstract int
    Returns the length of this string.
    int
    _more_
    final int
    String compatible entry point for getLength();
    static void
    main(String[] args)
    _more_
    subByteString(int beginIndex, int length)
    Returns a new string that is a substring of this string.
    substring(int beginIndex)
     
    substring(int beginIndex, int endindex)
     
    byte[]
    Converts this string to a new byte array.
    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 Details

    • nada

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

    • ByteString

      protected ByteString()
      _more_
  • Method Details

    • 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:
    • compare

      public static int compare(ByteString bs1, String s2)
      Compare two byte strings lexographically.
      Parameters:
      bs1 -
      s2 -
      Returns:
      _more_
      See Also:
    • 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:
    • 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:
    • substring

      public ByteString substring(int beginIndex)
      Parameters:
      beginIndex -
      Returns:
      _more_
      See Also:
    • length

      public final int length()
      String compatible entry point for getLength();
      Returns:
      _more_
      See Also:
    • compareTo

      public int compareTo(ByteString bs)
      Compare this and another byte string lexographically.
      Parameters:
      bs -
      Returns:
      _more_
      See Also:
    • compareTo

      public int compareTo(String ss)
      Compare this and a String string lexographically.
      Parameters:
      ss -
      Returns:
      _more_
      See Also:
    • 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 -