org.freehep.util.io
Class TaggedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.freehep.util.io.CompressableOutputStream
              extended by org.freehep.util.io.BitOutputStream
                  extended by org.freehep.util.io.ByteOrderOutputStream
                      extended by org.freehep.util.io.ByteCountOutputStream
                          extended by org.freehep.util.io.TaggedOutputStream
All Implemented Interfaces:
Closeable, DataOutput, Flushable, FinishableOutputStream, TaggedOutput

public abstract class TaggedOutputStream
extends ByteCountOutputStream
implements TaggedOutput

Class to write Tagged blocks to a Stream. The tagged blocks (Tags) contain a tagID and a Length, so that known and unknown tags (read with the TaggedInputStream) can again be written. The stream also allows to write Actions, which again come with a actionCode and a length. A concrete implementation of this stream should encode/write the TagHeader. All Concrete tags should be inherited from the Tag class and implement their write methods.

Version:
$Id: TaggedOutputStream.java 10195 2006-12-15 20:32:24Z duns $
Author:
Mark Donszelmann, Charles Loomis

Field Summary
protected  ActionSet actionSet
          Set of actions that can be used by this Stream
protected  TagSet tagSet
          Set of tags that can be used by this Stream
 
Fields inherited from class org.freehep.util.io.ByteOrderOutputStream
little, written
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
TaggedOutputStream(OutputStream out, TagSet tagSet, ActionSet actionSet)
          Create a Tagged Output stream.
TaggedOutputStream(OutputStream out, TagSet tagSet, ActionSet actionSet, boolean littleEndian)
          Create a Tagged Output stream.
 
Method Summary
protected  TagHeader createTagHeader(Tag tag, long len)
          Returns newly created TagHeader.
protected  int getTagAlignment()
          Specifies tag alignment: 1 byte, 2 short, 4 int and 8 long.
 void writeAction(Action action)
          Write action.
protected abstract  void writeActionHeader(ActionHeader header)
          Writes the ActionHeader, which includes an actionCode and a length.
 void writeTag(Tag tag)
          Write a tag.
protected abstract  void writeTagHeader(TagHeader header)
          Writes the TagHeader, which includes a TagID and a length.
 
Methods inherited from class org.freehep.util.io.ByteCountOutputStream
append, close, getBufferLength, getLength, popBuffer, popBufferBytes, pushBuffer, write
 
Methods inherited from class org.freehep.util.io.ByteOrderOutputStream
size, writeAsciiZString, writeBoolean, writeByte, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeInt, writeLong, writeShort, writeShort, writeString, writeUnsignedByte, writeUnsignedByte, writeUnsignedInt, writeUnsignedInt, writeUnsignedShort, writeUnsignedShort, writeUTF, writeUTF
 
Methods inherited from class org.freehep.util.io.BitOutputStream
byteAlign, finish, flushByte, minBits, minBits, minBits, writeBitFlag, writeFBits, writeSBits, writeUBits
 
Methods inherited from class org.freehep.util.io.CompressableOutputStream
startCompressing, write
 
Methods inherited from class java.io.FilterOutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.freehep.util.io.TaggedOutput
close
 
Methods inherited from interface java.io.DataOutput
write, write
 

Field Detail

tagSet

protected TagSet tagSet
Set of tags that can be used by this Stream


actionSet

protected ActionSet actionSet
Set of actions that can be used by this Stream

Constructor Detail

TaggedOutputStream

public TaggedOutputStream(OutputStream out,
                          TagSet tagSet,
                          ActionSet actionSet)
Create a Tagged Output stream.

Parameters:
out - stream to write
tagSet - allowable tag set
actionSet - allowable action set

TaggedOutputStream

public TaggedOutputStream(OutputStream out,
                          TagSet tagSet,
                          ActionSet actionSet,
                          boolean littleEndian)
Create a Tagged Output stream.

Parameters:
out - stream to write
tagSet - allowable tag set
actionSet - allowable action set
littleEndian - true if stream is little endian
Method Detail

writeTagHeader

protected abstract void writeTagHeader(TagHeader header)
                                throws IOException
Writes the TagHeader, which includes a TagID and a length.

Parameters:
header - TagHeader to write
Throws:
IOException - if write fails

getTagAlignment

protected int getTagAlignment()
Specifies tag alignment: 1 byte, 2 short, 4 int and 8 long.

Returns:
tag alignment

writeTag

public void writeTag(Tag tag)
              throws IOException
Description copied from interface: TaggedOutput
Write a tag.

Specified by:
writeTag in interface TaggedOutput
Parameters:
tag - tag to write
Throws:
IOException - if write fails

createTagHeader

protected TagHeader createTagHeader(Tag tag,
                                    long len)
Returns newly created TagHeader. The default implementation creates a tagHeader from tagID and length. This method is called "after" the tag information is written, but the tag header is inserted before the tag info into the stream. Its called after since it needs the length of the tag info.


writeActionHeader

protected abstract void writeActionHeader(ActionHeader header)
                                   throws IOException
Writes the ActionHeader, which includes an actionCode and a length.

Parameters:
header - ActionHeader to write
Throws:
IOException - if write fails

writeAction

public void writeAction(Action action)
                 throws IOException
Write action.

Parameters:
action - action to write
Throws:
IOException - if write fails


Copyright © 2000-2007 FreeHEP. All Rights Reserved.