org.apache.derby.iapi.services.io
Class FormatIdOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.FilterOutputStream
          extended byjava.io.DataOutputStream
              extended byorg.apache.derby.iapi.services.io.FormatIdOutputStream
All Implemented Interfaces:
java.io.DataOutput, ErrorInfo, java.io.ObjectOutput

public class FormatIdOutputStream
extends java.io.DataOutputStream
implements java.io.ObjectOutput, ErrorInfo

A stream for serializing objects with format id tags.

An ObjectOutput (henceforth 'out') preceeds objects it writes with a format id. The companion FormatIdInputStream (henceforth 'in') uses these format ids in parsing the stored data. The stream can be thought of as containing a sequence of (formatId,object) pairs interspersed with other data. The assumption is that out.writeObject() produces these pairs and in.readObject() uses the format ids to construct objects from the pairs that out.writeObject produced. The description below describes each supported pair and how in.readObject() processes it.

  1. (NULL_FORMAT_ID, nothing) in.readObject() returns null.
  2. (SRING_FORMAT_ID, UTF8 encoded string)in.readObject reads and returns this string.
  3. (SERIALIZABLE_FORMAT_ID,serialized object) in.readObject() reads the object using java serialization and returns it.
  4. (A format id for a Storable, isNull flag and object if isNull == false) (see note 1) in.readObject() reads the boolean isNull flag. If is null is true, in.readObject() returns a Storable object of the correct class which is null. If ifNull is false, in.readObject() restores the object using its readExternal() method.
  5. (A format id for a Formatable which is not Storable, the stored object) (see note 1) in.readObject restores the object using its readExternal() method.

Note 1: The FormatIdInputStream uses Monitor.newInstanceFromIdentifier(format id) to get the class.

Note 2: An object may support more than one of the following interfaces Storable, Formatable, Serializable. In this case out.writeObject use the first of these interfaces which the object supports (based on the order listed here) to determine how to write the object.


Field Summary
 
Fields inherited from class java.io.DataOutputStream
written
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
FormatIdOutputStream(java.io.OutputStream out)
          Constructor for a FormatIdOutputStream
 
Method Summary
 java.lang.String getErrorInfo()
           
 java.lang.Exception getNestedException()
           
 void setOutput(java.io.OutputStream out)
          Set the OutputStream for this FormatIdOutputStream to the stream provided.
 void writeObject(java.lang.Object ref)
          Write a format id for the object provied followed by the object itself to this FormatIdOutputStream.
 
Methods inherited from class java.io.DataOutputStream
flush, size, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
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
 
Methods inherited from interface java.io.ObjectOutput
close, flush, write, write, write
 
Methods inherited from interface java.io.DataOutput
writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 

Constructor Detail

FormatIdOutputStream

public FormatIdOutputStream(java.io.OutputStream out)
Constructor for a FormatIdOutputStream

Parameters:
out - output goes here.
Method Detail

writeObject

public void writeObject(java.lang.Object ref)
                 throws java.io.IOException
Write a format id for the object provied followed by the object itself to this FormatIdOutputStream.

Specified by:
writeObject in interface java.io.ObjectOutput
Parameters:
ref - a reference to the object.
Throws:
java.io.IOException - the exception.

setOutput

public void setOutput(java.io.OutputStream out)
Set the OutputStream for this FormatIdOutputStream to the stream provided. It is the responsibility of the caller to flush or close (as required) the previous stream this class was attached to.

Parameters:
out - The new output stream.

getErrorInfo

public java.lang.String getErrorInfo()
Specified by:
getErrorInfo in interface ErrorInfo

getNestedException

public java.lang.Exception getNestedException()
Specified by:
getNestedException in interface ErrorInfo

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.