com.hdcookbook.grin.io.binary
Class GrinDataOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by java.io.DataOutputStream
              extended by com.hdcookbook.grin.io.binary.GrinDataOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.DataOutput, java.io.Flushable

public class GrinDataOutputStream
extends java.io.DataOutputStream

GrinDataOutputStream is a convenience DataOutputStream subclass that knows how to write out certain Objects and Object arrays, including null. This class is used by the GrinBinaryWriter to write out information about show nodes.

See Also:
GrinBinaryWriter, GrinDataInputStream

Field Summary
 
Fields inherited from class java.io.DataOutputStream
written
 
Fields inherited from class java.io.FilterOutputStream
out
 
Method Summary
 void writeColor(java.awt.Color color)
          Writes out a Color instance.
 void writeCommands(Command[] commands)
          Writes out the reference to an array of references to the given commands.
 void writeFeatureReference(Feature feature)
          Writes out a reference of a Feature.
 void writeFeaturesArrayReference(Feature[] features)
          Reads in refereces of Features and returns an array of Features corresponding to the references.
 void writeIntArray(int[] array)
          Writes out an array of integers.
 void writeNonNull()
          Writes out an indication to the binary file that the object is not null.
 void writeNull()
          Writes out an indication to the binary file that the object is null.
 void writeRCHandlerReference(RCHandler handler)
          Writes out a reference of an RCHandler.
 void writeRCHandlersArrayReference(RCHandler[] handlers)
          Writes out refereces of RCHandler in the array.
 void writeRectangle(java.awt.Rectangle rect)
          Writes out a Rectangle instance.
 void writeRectangleArray(java.awt.Rectangle[] array)
          Writes out an array of Rectangles.
 void writeSegmentReference(Segment segment)
          Writes out a reference of a segment.
 void writeSharedIntArray(int[] array)
           
 void writeSharedRectangle(java.awt.Rectangle r)
           
 void writeSharedRectangleArray(java.awt.Rectangle[] r)
           
 void writeString(java.lang.String string)
          Writes out a reference to a String instance.
 void writeStringArray(java.lang.String[] array)
          Writes out an array of Strings.
 void writeSuperClassData(Command command)
          Writes out information common to all Command types.
 void writeSuperClassData(Feature feature)
          Writes out information common to all Feature types.
 void writeSuperClassData(RCHandler handler)
          Writes out information common to all RCHandler types.
 void writeSuperClassData(Segment segment)
          Writes out information common to all Segment types.
 
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.DataOutput
write
 

Method Detail

writeColor

public void writeColor(java.awt.Color color)
                throws java.io.IOException
Writes out a Color instance.

Parameters:
color - The color instance to write out.
Throws:
java.io.IOException - if IO error occurs.

writeRectangle

public void writeRectangle(java.awt.Rectangle rect)
                    throws java.io.IOException
Writes out a Rectangle instance.

Parameters:
rect - The rectangle to write out.
Throws:
java.io.IOException - if IO error occurs.

writeRectangleArray

public void writeRectangleArray(java.awt.Rectangle[] array)
                         throws java.io.IOException
Writes out an array of Rectangles.

Parameters:
array - An array of rectangles to write out.
Throws:
java.io.IOException - if IO error occurs.

writeIntArray

public void writeIntArray(int[] array)
                   throws java.io.IOException
Writes out an array of integers.

Parameters:
array - An array of integers to write out.
Throws:
java.io.IOException - if IO error occurs.

writeSharedIntArray

public void writeSharedIntArray(int[] array)
                         throws java.io.IOException
Throws:
java.io.IOException

writeSharedRectangle

public void writeSharedRectangle(java.awt.Rectangle r)
                          throws java.io.IOException
Throws:
java.io.IOException

writeSharedRectangleArray

public void writeSharedRectangleArray(java.awt.Rectangle[] r)
                               throws java.io.IOException
Throws:
java.io.IOException

writeString

public void writeString(java.lang.String string)
                 throws java.io.IOException
Writes out a reference to a String instance. Internally, this method keeps track of the Strings passed in as a parameter, keeps it in an array, and writes out an integer index on that array to the stream. The collected String array table is written out at the beginning of the binary file.

Parameters:
string - The String to write out.
Throws:
java.io.IOException - if IO error occurs.

writeStringArray

public void writeStringArray(java.lang.String[] array)
                      throws java.io.IOException
Writes out an array of Strings.

Parameters:
array - An array of Strings to write out.
Throws:
java.io.IOException - if IO error occurs.

writeFeatureReference

public void writeFeatureReference(Feature feature)
                           throws java.io.IOException
Writes out a reference of a Feature. This method should be used when the user is writing out an extension feature or command, and need to record about a feature that is referred by that extension.

Parameters:
feature - The feature to write out.
Throws:
java.io.IOException - if IO error occurs, or if no such feature exists in the show that this GrinDataInputStream is working with.

writeSegmentReference

public void writeSegmentReference(Segment segment)
                           throws java.io.IOException
Writes out a reference of a segment. This method should be used when the user is writing out an extension feature or command, and need to record about a segment that is referred by that extension.

Parameters:
segment - The segment to write out.
Throws:
java.io.IOException - if IO error occurs, or if no such feature exists in the show that this GrinDataInputStream is working with.

writeRCHandlerReference

public void writeRCHandlerReference(RCHandler handler)
                             throws java.io.IOException
Writes out a reference of an RCHandler. This method should be used when the user is writing out an extension feature or command, and need to record about an RCHandler that is referred by that extension.

Parameters:
handler - The RCHandler to write out.
Throws:
java.io.IOException - if IO error occurs, or if no such RCHandler exists in the show that this GrinDataInputStream is working with.

writeFeaturesArrayReference

public void writeFeaturesArrayReference(Feature[] features)
                                 throws java.io.IOException
Reads in refereces of Features and returns an array of Features corresponding to the references.

Throws:
java.io.IOException

writeRCHandlersArrayReference

public void writeRCHandlersArrayReference(RCHandler[] handlers)
                                   throws java.io.IOException
Writes out refereces of RCHandler in the array.

Throws:
java.io.IOException

writeCommands

public void writeCommands(Command[] commands)
                   throws java.io.IOException
Writes out the reference to an array of references to the given commands.

Parameters:
commands - An array of commands to write out to.
Throws:
java.io.IOException

writeNull

public void writeNull()
               throws java.io.IOException
Writes out an indication to the binary file that the object is null. One can use this when writing out objects that could possibly be null.
 
 public void writeInstanceData(GrinDataOutputStream out) {
    .... 
    if (myObject == null) {
       out.writeNull();
    } else {
       out.writeNonNull();
       ... write "myObject" content to "out" ...
    }
    ...
 }
 
Note that such null check is already done for all the convenience methods provided in this class, such as writeString(String), writeRectangle(Rect), writeColor(Color) etc.

Throws:
java.io.IOException
See Also:
writeNonNull(), GrinDataInputStream.isNull()

writeNonNull

public void writeNonNull()
                  throws java.io.IOException
Writes out an indication to the binary file that the object is not null. One can use this when writing out objects that could possibly be null.

Throws:
java.io.IOException
See Also:
writeNull(), GrinDataInputStream.isNull()

writeSuperClassData

public void writeSuperClassData(Feature feature)
                         throws java.io.IOException
Writes out information common to all Feature types. This method writes out following information.

Parameters:
feature - Feature instance to write out.
Throws:
java.io.IOException
See Also:
GrinDataInputStream.readSuperClassData(Feature)

writeSuperClassData

public void writeSuperClassData(RCHandler handler)
                         throws java.io.IOException
Writes out information common to all RCHandler types. This method writes out following information.

Parameters:
handler - RCHandler instance to write out.
Throws:
java.io.IOException
See Also:
GrinDataInputStream.readSuperClassData(RCHandler)

writeSuperClassData

public void writeSuperClassData(Segment segment)
                         throws java.io.IOException
Writes out information common to all Segment types. This method writes out following information.

Parameters:
segment - Segment instance to write out.
Throws:
java.io.IOException
See Also:
GrinDataInputStream.readSuperClassData(Segment)

writeSuperClassData

public void writeSuperClassData(Command command)
Writes out information common to all Command types. Currently there is no shared data for Commands.

Parameters:
command - Command instance to write out.
Throws:
java.io.IOException
See Also:
GrinDataInputStream.readSuperClassData(Command)