sdsi.sexp
Class SexpString

java.lang.Object
  |
  +--sdsi.sexp.Sexp
        |
        +--sdsi.sexp.SexpString
All Implemented Interfaces:
java.io.Serializable

public class SexpString
extends Sexp

This class represents simple S-Expressions. These are S-Expession which are just byte-strings.

Author:
Alexander Morcos, Sameer Ajmani
See Also:
Sexp, Serialized Form

Field Summary
(package private)  SimpleString content
           
(package private)  SimpleString display
           
 
Fields inherited from class sdsi.sexp.Sexp
base64Digit, hexDigit
 
Constructor Summary
SexpString(byte[] contents)
          Create a new SexpString with no display-hint and content equal to the byte array given.
SexpString(java.io.PushbackInputStream p)
          Create a new SexpString by parsing an S-Expression out of the input stream.
SexpString(java.lang.String contents)
          Create a new SexpString with no display-hint and content equal to the String given.
SexpString(java.lang.String display_type, byte[] contents)
          Create a new SexpString with the given display-hint and content.
SexpString(java.lang.String display_type, java.lang.String contents)
          Create a new SexpString with the given display-hint and content.
 
Method Summary
 byte[] bytesContent()
          Returns the bytes of this SexpString, not including the display hint.
 int compareTo(SexpString other)
          Compares the string representation of two SexpStrings lexicographically.
 boolean equals(SexpString other)
          Tests if two SexpStrings are equal.
 int getCanonLen()
          Calculates the length of the canonical representation of this S-expression.
 byte[] getCanonRep()
          Generates the canonical representation of this S-expression.
(package private)  int getReadableLen()
           
 boolean startsWith(SexpString other)
          Tests if the string representation of this SexpString starts with the string representation of another SexpString.
 java.lang.String stringContent()
          Returns the SexpString as a String, without the display hint.
 java.lang.String toReadableString(int offset, int width, int last)
          Returns a readable string representation of this S-expression.
 
Methods inherited from class sdsi.sexp.Sexp
base64ToInt, base64ToOctet, isBase64Digit, isDecimalDigit, isHexDigit, isTokenChar, isWhiteSpace, parse, toString, toString, toVerbatimString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

display

SimpleString display

content

SimpleString content
Constructor Detail

SexpString

public SexpString(java.lang.String contents)
Create a new SexpString with no display-hint and content equal to the String given.

Parameters:
contents - the contents of the SexpString.

SexpString

public SexpString(java.lang.String display_type,
                  java.lang.String contents)
Create a new SexpString with the given display-hint and content.

Parameters:
display_type - the value of the display hint of the S-Expression.
contents - the content of the S-Expression.

SexpString

public SexpString(byte[] contents)
Create a new SexpString with no display-hint and content equal to the byte array given.

Parameters:
contents - the contents of the SexpString.

SexpString

public SexpString(java.lang.String display_type,
                  byte[] contents)
Create a new SexpString with the given display-hint and content.

Parameters:
display_type - the value of the display hint of the S-Expression.
contents - the content of the S-Expression.

SexpString

public SexpString(java.io.PushbackInputStream p)
           throws SexpException
Create a new SexpString by parsing an S-Expression out of the input stream. Assumes that the S-Expression to parse is not a list.

Parameters:
p - the PushbackInputStream which contains the bytes of an S-Expression.
Throws:
SexpException - if there was a problem parsing the S-Expression
Method Detail

stringContent

public java.lang.String stringContent()
Returns the SexpString as a String, without the display hint.

Returns:
a String representing the content of the SexpString.

bytesContent

public byte[] bytesContent()
Returns the bytes of this SexpString, not including the display hint.

Returns:
a byte array containing the bytes of this SexpString.

toReadableString

public java.lang.String toReadableString(int offset,
                                         int width,
                                         int last)
Description copied from class: Sexp
Returns a readable string representation of this S-expression. Given format parameters, returns a nicely formatted readable representation of this S-expression, using base-64 and hexadecimal representation to handle unprintable characters.

Specified by:
toReadableString in class Sexp
Parameters:
offset - the number of spaces that should appear before every line of the string.
width - the total width that the string should take up in characters.
last - the number of spaces that should be left at the end of every line (for possible closing parens).
Returns:
a nicely formatted string representation of this S-expression.

getReadableLen

int getReadableLen()
Specified by:
getReadableLen in class Sexp

getCanonLen

public int getCanonLen()
Description copied from class: Sexp
Calculates the length of the canonical representation of this S-expression. @return the length of the canonical representation.

Specified by:
getCanonLen in class Sexp

getCanonRep

public byte[] getCanonRep()
Description copied from class: Sexp
Generates the canonical representation of this S-expression.

Specified by:
getCanonRep in class Sexp
Returns:
a byte array containing exactly the canonical representation.

compareTo

public int compareTo(SexpString other)
              throws SexpException
Compares the string representation of two SexpStrings lexicographically. Requires that their display types are equal for them to be compared. If the display types are equal then the contents of the SexpStrings are converted into verbatim string representations and compared without the leading lengths.

Parameters:
other - the SexpString to be compared.
Returns:
the value 0 if the argument SexpString is equal to this string; a value less than 0 if this SexpString is lexicographically less than the SexpString argument; and a value greater than 0 if this SexpString is lexicographically greater than the SexpString argument.
Throws:
SexpException - if the display types are not equal.

startsWith

public boolean startsWith(SexpString other)
Tests if the string representation of this SexpString starts with the string representation of another SexpString. The test is performed on the verbatim string representations of SexpStrings with no display type and without the leading lengths.

Parameters:
other - the SexpString to serve as a prefix
Returns:
true if the character sequence represented by the argument is a prefix of the character sequence represented by this SexpString; false otherwise.

equals

public boolean equals(SexpString other)
Tests if two SexpStrings are equal.

Parameters:
other - the SexpString to test equality with
Returns:
true if both SexpStrings have the same display type and content, false otherwise.