org.opencyc.api
Class CfaslOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--java.io.BufferedOutputStream
                    |
                    +--org.opencyc.api.CfaslOutputStream

public class CfaslOutputStream
extends java.io.BufferedOutputStream

A CFASL translating buffered output stream. All Java-native types which have logical sublisp equivalents are translated automatically by this stream. Classes implementing the CfaslTranslatingObject interface are translated using their writeObject() method. Other CYC objects, such as binding-lists and formulas, should be explicitly coerced before being sent, unless they inherit from a class which can be translated automatically.

Author:
Christopher, Dan Lipofsky

Copyright 2001 Cycorp, Inc., license is open source GNU LGPL.

the license

www.opencyc.org

OpenCyc at SourceForge

THIS SOFTWARE AND KNOWLEDGE BASE CONTENT ARE PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENCYC ORGANIZATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND KNOWLEDGE BASE CONTENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Field Summary
static int API_TRACE_DETAILED
          Detailed api trace.
static int API_TRACE_MESSAGES
          Message-level api trace.
static int API_TRACE_NONE
          No api trace.
protected static int CFASL_ASSERTION
           
protected static int CFASL_ASSERTION_DEF
           
protected static int CFASL_ASSERTION_SHELL
           
protected static int CFASL_AXIOM
           
protected static int CFASL_AXIOM_DEF
           
protected static int CFASL_BTREE_HIGH
           
protected static int CFASL_BTREE_LEAF
           
protected static int CFASL_BTREE_LOW
           
protected static int CFASL_BTREE_LOW_HIGH
           
protected static int CFASL_BYTE_VECTOR
           
protected static int CFASL_CHARACTER
           
protected static int CFASL_CONSTANT
           
protected static int CFASL_DICTIONARY
           
protected static int CFASL_DOTTED
           
protected static int CFASL_GUID
           
protected static int CFASL_HASHTABLE
           
protected static int CFASL_IMMEDIATE_FIXNUM_CUTOFF
          Binary values for assembling CFASL messages.
protected static int CFASL_IMMEDIATE_FIXNUM_OFFSET
           
protected static int CFASL_INDEX
           
protected static int CFASL_KEYWORD
           
protected static int CFASL_LIST
           
protected static int CFASL_N_16BIT_INT
           
protected static int CFASL_N_24BIT_INT
           
protected static int CFASL_N_32BIT_INT
           
protected static int CFASL_N_8BIT_INT
           
protected static int CFASL_N_BIGNUM
           
protected static int CFASL_N_FLOAT
           
protected static int CFASL_NART
           
protected static int CFASL_NIL
           
protected static int CFASL_P_16BIT_INT
           
protected static int CFASL_P_24BIT_INT
           
protected static int CFASL_P_32BIT_INT
           
protected static int CFASL_P_8BIT_INT
           
protected static int CFASL_P_BIGNUM
           
protected static int CFASL_P_FLOAT
           
protected static int CFASL_SERVER_DEATH
           
protected static int CFASL_SOURCE
           
protected static int CFASL_SOURCE_DEF
           
protected static int CFASL_SPECIAL_OBJECT
           
protected static int CFASL_STRING
           
protected static int CFASL_SYMBOL
           
protected static int CFASL_VARIABLE
           
protected static int CFASL_VECTOR
           
 int trace
          Parameter that, when true, causes a trace of the messages to and from the server.
 
Fields inherited from class java.io.BufferedOutputStream
buf, count
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
CfaslOutputStream(java.io.OutputStream out)
          Creates a new CfaslOutputStream to write data to the specified underlying output stream with the default buffer size.
CfaslOutputStream(java.io.OutputStream out, int size)
          Creates a new CfaslOutputStream to write data to the specified underlying output stream with the specified buffer size.
 
Method Summary
 void writeAssertion(CycAssertion cycAssertion)
          Writes a CycAssertion object to this CfaslOutputStream.
 void writeBigInteger(java.math.BigInteger v)
          Writes a BigInteger to this CFASL output stream as a CFASL Bignum (unless it is small enough to be transmitted as a CFASL Fixnum, in which case it is passed on to writeFixnum(long)).
protected  void writeBignum(long v)
          Writes a long integer to this CFASL output stream as a Bignum.
 void writeBoolean(boolean v)
          Writes a boolean onto this CFASL output stream.
 void writeByteArray(byte[] bytes)
          Writes a byte array to this CfaslOutputStream.
 void writeChar(char v)
          Writes a one byte character onto this CFASL output stream.
 void writeConstant(CycConstant cycConstant)
          Writes a CycConstant object to this CfaslOutputStream.
 void writeDottedList(CycList dottedList)
          Writes an improper (dotted) CycList of Objects to this CfaslOutputStream as a CFASL dotted list.
 void writeDouble(double v)
          Writes a double onto this CfaslOutputStream.
protected  void writeFixnum(int v)
          Writes an integer to this CFASL output stream as a Fixnum.
 void writeGuid(Guid guid)
          Writes a Guid object to this CfaslOutputStream.
 void writeInt(long v)
          Writes a long integer to this CFASL output stream.
 void writeKeyword(CycSymbol cycSymbol)
          Writes a keyword symbol object to this CfaslOutputStream.
 void writeList(java.util.List list)
          Writes a List of Objects to this CfaslOutputStream as a CFASL List.
 void writeList(java.lang.Object[] list)
          Writes an array of Objects to this CfaslOutputStream as a CFASL List.
 void writeNart(CycNart cycNart)
          Writes a CycNart object to this CfaslOutputStream.
 void writeObject(java.lang.Object o)
          Writes a generic object to this CfaslOutputStream.
 void writeString(java.lang.String s)
          Writes a String to this CfaslOutputStream.
 void writeSymbol(CycSymbol cycSymbol)
          Writes a CycSymbol object to this CfaslOutputStream.
 void writeVariable(CycVariable cycVariable)
          Writes a CycVariable object to this CfaslOutputStream.
 
Methods inherited from class java.io.BufferedOutputStream
flush, write, write
 
Methods inherited from class java.io.FilterOutputStream
close, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

API_TRACE_NONE

public static final int API_TRACE_NONE
No api trace.

API_TRACE_MESSAGES

public static final int API_TRACE_MESSAGES
Message-level api trace.

API_TRACE_DETAILED

public static final int API_TRACE_DETAILED
Detailed api trace.

trace

public int trace
Parameter that, when true, causes a trace of the messages to and from the server.

CFASL_IMMEDIATE_FIXNUM_CUTOFF

protected static final int CFASL_IMMEDIATE_FIXNUM_CUTOFF
Binary values for assembling CFASL messages.

CFASL_IMMEDIATE_FIXNUM_OFFSET

protected static final int CFASL_IMMEDIATE_FIXNUM_OFFSET

CFASL_P_8BIT_INT

protected static final int CFASL_P_8BIT_INT

CFASL_N_8BIT_INT

protected static final int CFASL_N_8BIT_INT

CFASL_P_16BIT_INT

protected static final int CFASL_P_16BIT_INT

CFASL_N_16BIT_INT

protected static final int CFASL_N_16BIT_INT

CFASL_P_24BIT_INT

protected static final int CFASL_P_24BIT_INT

CFASL_N_24BIT_INT

protected static final int CFASL_N_24BIT_INT

CFASL_P_32BIT_INT

protected static final int CFASL_P_32BIT_INT

CFASL_N_32BIT_INT

protected static final int CFASL_N_32BIT_INT

CFASL_P_FLOAT

protected static final int CFASL_P_FLOAT

CFASL_N_FLOAT

protected static final int CFASL_N_FLOAT

CFASL_KEYWORD

protected static final int CFASL_KEYWORD

CFASL_SYMBOL

protected static final int CFASL_SYMBOL

CFASL_NIL

protected static final int CFASL_NIL

CFASL_LIST

protected static final int CFASL_LIST

CFASL_VECTOR

protected static final int CFASL_VECTOR

CFASL_STRING

protected static final int CFASL_STRING

CFASL_CHARACTER

protected static final int CFASL_CHARACTER

CFASL_DOTTED

protected static final int CFASL_DOTTED

CFASL_HASHTABLE

protected static final int CFASL_HASHTABLE

CFASL_BTREE_LOW_HIGH

protected static final int CFASL_BTREE_LOW_HIGH

CFASL_BTREE_LOW

protected static final int CFASL_BTREE_LOW

CFASL_BTREE_HIGH

protected static final int CFASL_BTREE_HIGH

CFASL_BTREE_LEAF

protected static final int CFASL_BTREE_LEAF

CFASL_P_BIGNUM

protected static final int CFASL_P_BIGNUM

CFASL_N_BIGNUM

protected static final int CFASL_N_BIGNUM

CFASL_GUID

protected static final int CFASL_GUID

CFASL_BYTE_VECTOR

protected static final int CFASL_BYTE_VECTOR

CFASL_CONSTANT

protected static final int CFASL_CONSTANT

CFASL_NART

protected static final int CFASL_NART

CFASL_ASSERTION

protected static final int CFASL_ASSERTION

CFASL_ASSERTION_SHELL

protected static final int CFASL_ASSERTION_SHELL

CFASL_ASSERTION_DEF

protected static final int CFASL_ASSERTION_DEF

CFASL_SOURCE

protected static final int CFASL_SOURCE

CFASL_SOURCE_DEF

protected static final int CFASL_SOURCE_DEF

CFASL_AXIOM

protected static final int CFASL_AXIOM

CFASL_AXIOM_DEF

protected static final int CFASL_AXIOM_DEF

CFASL_VARIABLE

protected static final int CFASL_VARIABLE

CFASL_INDEX

protected static final int CFASL_INDEX

CFASL_SPECIAL_OBJECT

protected static final int CFASL_SPECIAL_OBJECT

CFASL_DICTIONARY

protected static final int CFASL_DICTIONARY

CFASL_SERVER_DEATH

protected static final int CFASL_SERVER_DEATH
Constructor Detail

CfaslOutputStream

public CfaslOutputStream(java.io.OutputStream out)
Creates a new CfaslOutputStream to write data to the specified underlying output stream with the default buffer size.
Parameters:
out - the underlying output stream.

CfaslOutputStream

public CfaslOutputStream(java.io.OutputStream out,
                         int size)
Creates a new CfaslOutputStream to write data to the specified underlying output stream with the specified buffer size.
Parameters:
out - the underlying output stream.
size - the buffer size.
Method Detail

writeBoolean

public void writeBoolean(boolean v)
                  throws java.io.IOException
Writes a boolean onto this CFASL output stream. What is actually written is either the symbol T or NIL.
Parameters:
v - the boolean value to be written

writeChar

public void writeChar(char v)
               throws java.io.IOException
Writes a one byte character onto this CFASL output stream. Crudely converts from Unicode to 8-bit ASCII.
Parameters:
v - the character to be written

writeInt

public void writeInt(long v)
              throws java.io.IOException
Writes a long integer to this CFASL output stream. It may be written as either a CFASL Fixnum or a CFASL Bignum, depending on its size. For legacy reasons it is called writeInt instead of writeLong.
Parameters:
the - long integer to be written

writeFixnum

protected void writeFixnum(int v)
                    throws java.io.IOException
Writes an integer to this CFASL output stream as a Fixnum. This method is protected because it does no size checking, so the calling method must be wise as to what fits in a Fixnum.
Parameters:
v - the integer to be written

writeBignum

protected void writeBignum(long v)
                    throws java.io.IOException
Writes a long integer to this CFASL output stream as a Bignum. This method is protected because it does no size checking, so the calling method must be wise as to whether Fixnum or Bignum is better.
Parameters:
v - the long integer to be written

writeBigInteger

public void writeBigInteger(java.math.BigInteger v)
                     throws java.io.IOException
Writes a BigInteger to this CFASL output stream as a CFASL Bignum (unless it is small enough to be transmitted as a CFASL Fixnum, in which case it is passed on to writeFixnum(long)).
Parameters:
v - the BigInteger to be written

writeDouble

public void writeDouble(double v)
                 throws java.io.IOException
Writes a double onto this CfaslOutputStream. The double is encoded as the sign (part of the opcode), significand, and exponent, such that the original double can be reconstructed as sign * significand * 2^exp. All parts are integers with the significand as small as possible.
Parameters:
v - the double value to be written

writeString

public void writeString(java.lang.String s)
                 throws java.io.IOException
Writes a String to this CfaslOutputStream.
Parameters:
s - the string to be written

writeByteArray

public void writeByteArray(byte[] bytes)
                    throws java.io.IOException
Writes a byte array to this CfaslOutputStream.
Parameters:
bytes - the byte array to be written.

writeList

public void writeList(java.util.List list)
               throws java.io.IOException
Writes a List of Objects to this CfaslOutputStream as a CFASL List.
Parameters:
list - the list of objects to be written

writeDottedList

public void writeDottedList(CycList dottedList)
                     throws java.io.IOException
Writes an improper (dotted) CycList of Objects to this CfaslOutputStream as a CFASL dotted list.
Parameters:
improperList - the list of objects to be written

writeList

public void writeList(java.lang.Object[] list)
               throws java.io.IOException
Writes an array of Objects to this CfaslOutputStream as a CFASL List.
Parameters:
list - the array of objects to be written

writeGuid

public void writeGuid(Guid guid)
               throws java.io.IOException
Writes a Guid object to this CfaslOutputStream.
Parameters:
guid - the Guid to be written

writeSymbol

public void writeSymbol(CycSymbol cycSymbol)
                 throws java.io.IOException
Writes a CycSymbol object to this CfaslOutputStream.
Parameters:
cycSymbol - the CycSymbol to be written

writeKeyword

public void writeKeyword(CycSymbol cycSymbol)
                  throws java.io.IOException
Writes a keyword symbol object to this CfaslOutputStream.
Parameters:
cycSymbol - the keyword to be written

writeVariable

public void writeVariable(CycVariable cycVariable)
                   throws java.io.IOException
Writes a CycVariable object to this CfaslOutputStream.
Parameters:
cycVariable - the CycVariable to be written

writeConstant

public void writeConstant(CycConstant cycConstant)
                   throws java.io.IOException
Writes a CycConstant object to this CfaslOutputStream.
Parameters:
cycConstant - the CycConstant to be written

writeNart

public void writeNart(CycNart cycNart)
               throws java.io.IOException
Writes a CycNart object to this CfaslOutputStream.
Parameters:
cycNart - the CycNart to be written

writeAssertion

public void writeAssertion(CycAssertion cycAssertion)
                    throws java.io.IOException
Writes a CycAssertion object to this CfaslOutputStream.
Parameters:
cycAssertion - the CycAssertion to be written

writeObject

public void writeObject(java.lang.Object o)
                 throws java.io.IOException
Writes a generic object to this CfaslOutputStream.
Parameters:
o - the object to be written
Throws:
java.lang.RuntimeException - if the Object cannot be translated.