sexp
Class SimpleString

java.lang.Object
  |
  +--sexp.SimpleString

public class SimpleString
extends Object

This class represents the lowest-level S-Expression object. TODO: Complete JavaDoc documentation of public methods. Note, {presentation,display}-hint handling is in Sexp.

Version:
$Id: SimpleString.java,v 1.1.1.2 2002/05/08 22:48:27 tep Exp $
Author:
Per Harald Myrvang <perm@pasta.cs.uit.no>
See Also:
SExpression, Sexp, SList

Field Summary
private static String __me
           
 String byte_encoding
          Encoding used when converting from a byte array to whatever.
private static boolean debug
           
protected static String default_encoding
           
private  int length
           
private  byte[] string
           
 String string_encoding
          Encoding used when converting from a String to whatever.
 
Constructor Summary
SimpleString()
          Creates and initializes new SimpleString.
SimpleString(byte[] data)
          Constructor accepting "raw" data (in a byte array).
SimpleString(String data)
          Constructor accepting an initial string.
 
Method Summary
 int allocated()
          Get length of allocated storage space.
 void append(byte c)
          Append a byte to this object.
 void append(byte[] ba)
          Append a byte-array to this object.
 void append(String str)
          Append a String to this object.
 void append(String str, String enc)
          Append a String to this object, using the specified encoding.
 Object clone()
          Duplicate this object.
 int compareTo(byte[] ba)
          Compare this object with the given byte-array.
 int compareTo(byte[] ba, int len)
          Compare a number of bytes of this object with the given byte-array.
 int compareTo(SimpleString sim)
          Compare this object with some other SimpleString object.
 int compareTo(SimpleString sim, int len)
          Compare a number of bytes of this object with some other SimpleString object.
 int compareTo(String str)
          Compare this object with the given String.
 int compareTo(String str, int len)
          Compare a number of bytes of this object with the given String.
 int compareTo(String str, int len, String enc)
          Compare a number of bytes of this object with the given String, using the given encoding.
 int compareTo(String str, String enc)
          Compare this object with the given String, using the given encoding.
protected  void debugDump()
           
 boolean equals(byte[] that)
          See if this SimpleString is equal to the given Object.
 boolean equals(String that)
          See if this SimpleString is equal to the given Object.
 void finalize()
           
 void free()
          Destroy and free the resouces associated with this object.
 byte[] getByteArray()
          Get access to the raw byte array.
 void grow()
          Increase size of object.
 void grow(int growth)
          Increase size of object.
 boolean isList()
           
 int length()
          Get length of stored data.
 String toString()
          Convert this object to a string using the default byte encoding (ISO8859-1).
 String toString(String enc)
          Convert this object to a string using the given byte encoding.
 
Methods inherited from class java.lang.Object
, equals, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

__me

private static final String __me

default_encoding

protected static String default_encoding

string_encoding

public String string_encoding
Encoding used when converting from a String to whatever.

byte_encoding

public String byte_encoding
Encoding used when converting from a byte array to whatever.

debug

private static boolean debug

string

private byte[] string

length

private int length
Constructor Detail

SimpleString

public SimpleString()
Creates and initializes new SimpleString. Allocates a initial byte buffer of 16 bytes to hold data.

SimpleString

public SimpleString(byte[] data)
             throws SexpException
Constructor accepting "raw" data (in a byte array).

SimpleString

public SimpleString(String data)
Constructor accepting an initial string.
See Also:
SimpleString#getRaw()
Method Detail

finalize

public void finalize()
              throws Throwable
Overrides:
finalize in class Object

grow

public void grow(int growth)
Increase size of object. Mostly used internally. If you know you're going to fill this SimpleString with 1211 bytes, call ss.grow(1211 - ss.allocated) to save some overhead.
Parameters:
growth - number of bytes object should be increased with

grow

public void grow()
Increase size of object. Space allocated is set to roughly 3/2 the current string length, plus 16.

length

public int length()
Get length of stored data.
Returns:
length of stored data

allocated

public int allocated()
Get length of allocated storage space.
Returns:
length of allocated storage space.

getByteArray

public byte[] getByteArray()
Get access to the raw byte array. This is dangerous, and breaks with the property of immutability.
Returns:
raw byte array (not a copy).

append

public void append(byte c)
Append a byte to this object. The object is resized internally if neccessary.
Parameters:
c - byte to be appended

append

public void append(byte[] ba)
Append a byte-array to this object. The object is resized internally if neccessary.
Parameters:
ba - byte-array to be appended

append

public void append(String str)
Append a String to this object. The String is converted into a byte-array object using the ISO8859-1 encoding. The object is resized internally if neccessary.
Parameters:
str - String to be appended

append

public void append(String str,
                   String enc)
            throws UnsupportedEncodingException
Append a String to this object, using the specified encoding. The object is resized internally if neccessary.
Parameters:
str - String to be appended
enc - encoding to use
Throws:
UnsupportedEncodingException - if the encoding isn't supported.

clone

public Object clone()
             throws CloneNotSupportedException
Duplicate this object.
Overrides:
clone in class Object
Returns:
Object reference to this object's clone.

free

public void free()
Destroy and free the resouces associated with this object.

isList

public boolean isList()

toString

public String toString()
Convert this object to a string using the default byte encoding (ISO8859-1).
Overrides:
toString in class Object
Returns:
String representation of this object.
Throws:
RuntimeException - if byte-to-string conversion failed

toString

public String toString(String enc)
                throws UnsupportedEncodingException
Convert this object to a string using the given byte encoding.
Parameters:
enc - Encoding to use
Returns:
String representation of this object.
Throws:
RuntimeException - if byte-to-string conversion failed

equals

public boolean equals(String that)
See if this SimpleString is equal to the given Object.
Parameters:
that - String to compare this object with.
Returns:
true if both objects are equal, false if they're not.
See Also:
compareTo(java.lang.String)

equals

public boolean equals(byte[] that)
See if this SimpleString is equal to the given Object.
Parameters:
that - String to compare this object with.
Returns:
true if both objects are equal, false if they're not.
See Also:
compareTo(byte[])

compareTo

public int compareTo(byte[] ba,
                     int len)
Compare a number of bytes of this object with the given byte-array. The comparison is done on a per-element basis.
Parameters:
ba - byte-array to compare this object with.
len - number of bytes to compare.
Returns:
integer value that's less than, equal to, or greater than zero, if this object is less than, equal to, or greater than the byte-array.

compareTo

public int compareTo(byte[] ba)
Compare this object with the given byte-array. The comparison is done on a per-element basis.
Parameters:
ba - byte-array to compare this object with.
Returns:
integer value that's less than, equal to, or greater than zero, if this object is less than, equal to, or greater than the byte-array.

compareTo

public int compareTo(SimpleString sim,
                     int len)
Compare a number of bytes of this object with some other SimpleString object. The comparison is done on a per-element basis.
Parameters:
sim - SimpleString to compare this object with.
len - number of bytes to compare.
Returns:
integer value that's less than, equal to, or greater than zero, if this object is less than, equal to, or greater than the given SimpleString object.

compareTo

public int compareTo(SimpleString sim)
Compare this object with some other SimpleString object. The comparison is done on a per-element basis.
Parameters:
sim - SimpleString to compare this object with.
Returns:
integer value that's less than, equal to, or greater than zero, if this object is less than, equal to, or greater than the given SimpleString object.

compareTo

public int compareTo(String str,
                     int len,
                     String enc)
              throws UnsupportedEncodingException
Compare a number of bytes of this object with the given String, using the given encoding. The String is converted to a byte-array using the given encoding.
Parameters:
str - String to compare this object with.
len - number of bytes to compare.
enc - encoding to use
Returns:
integer value that's less than, equal to, or greater than zero, if this object is less than, equal to, or greater than the String.
Throws:
UnsupportedEncodingException - if the encoding isn't supported.

compareTo

public int compareTo(String str,
                     int len)
Compare a number of bytes of this object with the given String. The String is converted into a byte-array using the ISO8859_1 encoding.
Parameters:
str - String to compare this object with.
len - number of bytes to compare.
Returns:
integer value that's less than, equal to, or greater than zero, if this object is less than, equal to, or greater than the String.

compareTo

public int compareTo(String str,
                     String enc)
              throws UnsupportedEncodingException
Compare this object with the given String, using the given encoding. The String is converted to a byte-array using the given encoding.
Parameters:
str - String to compare this object with.
enc - encoding to use
Returns:
integer value that's less than, equal to, or greater than zero, if this object is less than, equal to, or greater than the String.
Throws:
UnsupportedEncodingException - if the encoding isn't supported.

compareTo

public int compareTo(String str)
Compare this object with the given String. The String is converted into a byte-array using the ISO8859_1 encoding.
Parameters:
str - String to compare this object with.
Returns:
integer value that's less than, equal to, or greater than zero, if this object is less than, equal to, or greater than the String.

debugDump

protected void debugDump()