Class ByteString
- All Implemented Interfaces:
Serializable
,Comparable
- Direct Known Subclasses:
ByteString.Concrete
,ByteString.Empty
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 ClassesModifier and TypeClassDescriptionstatic class
Class Concretestatic class
Class Emptystatic 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
FieldsModifier and TypeFieldDescriptionstatic final byte[]
Zero length byte array to use as the contents of Empty ByteString -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract byte
byteAt
(int ii) Returns the byte at the specified index.static final 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 final byte
CharToByte8859_1
(char cc) Narrow Unicode char to an 8859_1 encoded byte.static int
compare
(ByteString bs1, String s2) Compare two byte strings lexographically.static int
compare
(ByteString bs1, ByteString bs2) Compare two byte strings lexographically.int
Compares this to another Object.int
Compare this and a String string lexographically.int
compareTo
(ByteString bs) 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.format
(StringBuffer buf) Widen this to Unicode in a StringBuffer.abstract int
Returns the length of this string.int
hashCode()
_more_final int
length()
String compatible entry point for getLength();static void
_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[]
toArray()
Converts this string to a new byte array.toString()
Widen this to a Unicode as in a String
-
Field Details
-
nada
public static final byte[] nadaZero 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
Compare two byte strings lexographically.- Parameters:
bs1
-bs2
-- Returns:
- _more_
- See Also:
-
compare
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
_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 from0
togetLength() - 1
. The first byte of the sequence is at index0
, the next at index1
, 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 isnbytes
. The bytes are copied into the subarray ofdst
starting at indexdstpos
.- 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
Returns a new string that is a substring of this string. The substring begins at the specifiedbeginIndex
and islength
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 aString
compatible version below.- Parameters:
beginIndex
- the beginning index, inclusive.length
- int length of the substring.- Returns:
- the specified substring.
-
substring
- Parameters:
beginIndex
-endindex
-- Returns:
- _more_
- See Also:
-
substring
- Parameters:
beginIndex
-- Returns:
- _more_
- See Also:
-
length
public final int length()String compatible entry point for getLength();- Returns:
- _more_
- See Also:
-
compareTo
Compare this and another byte string lexographically.- Parameters:
bs
-- Returns:
- _more_
- See Also:
-
compareTo
Compare this and a String string lexographically.- Parameters:
ss
-- Returns:
- _more_
- See Also:
-
compareTo
Compares this to another Object. If the Object is a ByteString, this function behaves likecompareTo(ByteString)
. Otherwise, it throws aClassCastException
.- Specified by:
compareTo
in interfaceComparable
- Parameters:
oo
-- Returns:
- _more_
-
format
Widen this to Unicode in a StringBuffer.- Parameters:
buf
-- Returns:
- _more_
-
hashCode
public int hashCode()_more_ -
equals
_more_ -
equalS
Returns true iff this and the String argument represent the same sequence of characters.- Parameters:
ss
-- Returns:
- _more_
-
toString
Widen this to a Unicode as in a String -
main
_more_- Parameters:
args
-
-