jsdsi.sexp
Class Sexp

java.lang.Object
  |
  +--jsdsi.sexp.Sexp
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
SexpList, SexpString

public abstract class Sexp
extends java.lang.Object
implements java.io.Serializable

Abstract S-expression superclass. Provides static utility functions. S-expressions are immutable.

Author:
Alexander Morcos, Sameer Ajmani
See Also:
SexpString, SexpList, Serialized Form

Field Summary
static char[] base64Digit
          Maps integers to base-64 digits.
static char[] hexDigit
          Maps integers to hexadecimal digits.
 
Constructor Summary
Sexp()
           
 
Method Summary
static java.lang.String decodeString(byte[] b)
          Converts a byte array to a string using the 8859_1 encoding.
static byte[] encodeString(java.lang.String s)
          Converts a string to a byte array using the 8859_1 encoding.
 int getReadableLen()
          Returns the length of this S-expression as if it were printed on one line.
(package private) abstract  int getReadableLenImpl()
          Returns the length of this S-expression as if it were printed on one line.
static boolean isBase64Digit(int c)
          Tests if a character is a base 64 digit.
static boolean isDecimalDigit(int c)
          Tests if a character is a decimal digit.
static boolean isHexDigit(int c)
          Tests if a character is a hexadecimal digit.
static boolean isTokenChar(int c)
          Tests if a character is a token character.
static boolean isWhiteSpace(int c)
          Tests if a character is whitespace.
(package private) static void writeBase64(byte[] data, java.io.Writer out)
          Encodes data in base-64 and writes it to a character stream.
(package private) static void writeBase64(byte[] data, java.io.Writer out, int offset, int width, int last)
          Encodes data in base-64 and writes it to a character stream.
abstract  void writeCanonical(java.io.OutputStream out)
          Writes this S-expression to a byte stream in canonical form.
(package private) static void writeHex(byte[] data, java.io.Writer out)
          Encodes data in hexadecimal and writes it to a character stream.
(package private) static void writeHex(byte[] data, java.io.Writer out, int offset, int width, int last)
          Encodes data in hexadecimal and writes it to a character stream.
abstract  void writeReadable(java.io.Writer out, int offset, int width, int last)
          Writes this S-expression to a character stream in readable form.
 void writeTransport(java.io.OutputStream out)
          Writes this S-expression to a byte stream in transport form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hexDigit

public static final char[] hexDigit
Maps integers to hexadecimal digits.


base64Digit

public static final char[] base64Digit
Maps integers to base-64 digits.

Constructor Detail

Sexp

public Sexp()
Method Detail

isWhiteSpace

public static final boolean isWhiteSpace(int c)
Tests if a character is whitespace.

Parameters:
c - the character to be tested
Returns:
true if the character is whitespace, false otherwise

isDecimalDigit

public static final boolean isDecimalDigit(int c)
Tests if a character is a decimal digit.

Parameters:
c - the character to be tested
Returns:
true if the character is a digit between 0 and 9 inclusive, false otherwise

isHexDigit

public static final boolean isHexDigit(int c)
Tests if a character is a hexadecimal digit.

Parameters:
c - the character to be tested
Returns:
true if the character is a decimal digit or a letter between 'a' and 'f' upper or lowercase, false otherwise

isBase64Digit

public static final boolean isBase64Digit(int c)
Tests if a character is a base 64 digit.

Parameters:
c - the character to be tested
Returns:
true if the character is a decimal digit, a letter of the alphabet or '+' or '/', false otherwise

isTokenChar

public static final boolean isTokenChar(int c)
Tests if a character is a token character.

Parameters:
c - the character to be tested.
Returns:
true if the character is a legal token character for an S-expression, false otherwise

writeHex

static void writeHex(byte[] data,
                     java.io.Writer out)
              throws java.io.IOException
Encodes data in hexadecimal and writes it to a character stream.

Parameters:
data - the data to encode
out - the character stream
java.io.IOException

writeHex

static void writeHex(byte[] data,
                     java.io.Writer out,
                     int offset,
                     int width,
                     int last)
              throws java.io.IOException
Encodes data in hexadecimal and writes it to a character stream.

Parameters:
data - the data to encode
out - the character stream
offset - spaces indented from left
width - total width of window, in characters
last - spaces reserved on right (e.g., for closing parens)
java.io.IOException

writeBase64

static void writeBase64(byte[] data,
                        java.io.Writer out)
                 throws java.io.IOException
Encodes data in base-64 and writes it to a character stream.

Parameters:
data - the data to encode
out - the character stream
java.io.IOException

writeBase64

static void writeBase64(byte[] data,
                        java.io.Writer out,
                        int offset,
                        int width,
                        int last)
                 throws java.io.IOException
Encodes data in base-64 and writes it to a character stream.

Parameters:
data - the data to encode
out - the character stream
offset - spaces indented from left
width - total width of window, in characters
last - spaces reserved on right (e.g., for closing parens)
java.io.IOException

decodeString

public static java.lang.String decodeString(byte[] b)
Converts a byte array to a string using the 8859_1 encoding.


encodeString

public static byte[] encodeString(java.lang.String s)
Converts a string to a byte array using the 8859_1 encoding.


writeCanonical

public abstract void writeCanonical(java.io.OutputStream out)
                             throws java.io.IOException
Writes this S-expression to a byte stream in canonical form.

java.io.IOException

writeTransport

public final void writeTransport(java.io.OutputStream out)
                          throws java.io.IOException
Writes this S-expression to a byte stream in transport form.

java.io.IOException

writeReadable

public abstract void writeReadable(java.io.Writer out,
                                   int offset,
                                   int width,
                                   int last)
                            throws java.io.IOException
Writes this S-expression to a character stream in readable form.

Parameters:
offset - spaces indented from left
width - total width of window, in characters
last - spaces reserved on right (e.g., for closing parens)
java.io.IOException

getReadableLen

public final int getReadableLen()
Returns the length of this S-expression as if it were printed on one line. Caches result for efficiency.

See Also:
getReadableLenImpl()

getReadableLenImpl

abstract int getReadableLenImpl()
Returns the length of this S-expression as if it were printed on one line.