org.jboss.util.stream
Class AutoResetObjectOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.ObjectOutputStream
          extended byorg.jboss.util.stream.ObjectOutputStreamAdapter (src) 
              extended byorg.jboss.util.stream.AutoResetObjectOutputStream
All Implemented Interfaces:
java.io.DataOutput, java.io.ObjectOutput, java.io.ObjectStreamConstants

public class AutoResetObjectOutputStream
extends ObjectOutputStreamAdapter (src)

An ObjectOutputStream that will auto reset after n objects have been written to the underlying stream.

Concurrency

This class is not synchronized.


Nested Class Summary
 
Nested classes inherited from class java.io.ObjectOutputStream
java.io.ObjectOutputStream.PutField
 
Field Summary
protected  int after
          Number of objects to write before resetting.
protected  int count
          Number of objects written so far.
 
Fields inherited from class org.jboss.util.stream.ObjectOutputStreamAdapter (src)
out
 
Fields inherited from interface java.io.ObjectStreamConstants
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING
 
Constructor Summary
AutoResetObjectOutputStream(java.io.ObjectOutputStream out, int after)
          Construct a new AutoResetObjectOutputStream.
 
Method Summary
 int getCount()
          Get the number of objects written to the stream so far.
 int getResetAfter()
          Get the number of objects that must be written before resetting the stream.
 void reset()
          Resets the object counter as well as the nested stream.
 void setResetAfter(int after)
          Set the number of objects that must be written before resetting the stream.
protected  void writeObjectOverride(java.lang.Object obj)
          Write the given object and reset if the number of objects written (including this one) exceeds the after count.
 
Methods inherited from class org.jboss.util.stream.ObjectOutputStreamAdapter (src)
close, defaultWriteObject, flush, putFields, useProtocolVersion, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFields, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.io.ObjectOutputStream
annotateClass, annotateProxyClass, drain, enableReplaceObject, replaceObject, writeClassDescriptor, writeObject, writeStreamHeader, writeUnshared
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

after

protected int after
Number of objects to write before resetting.


count

protected int count
Number of objects written so far.

Constructor Detail

AutoResetObjectOutputStream

public AutoResetObjectOutputStream(java.io.ObjectOutputStream out,
                                   int after)
                            throws java.io.IOException
Construct a new AutoResetObjectOutputStream.

Parameters:
out - An ObjectOutputStream stream.
after - Number of objects to write before resetting.
Throws:
java.lang.IllegalArgumentException - After <= 0
java.io.IOException - Any exception thrown by the underlying OutputStream.
Method Detail

setResetAfter

public void setResetAfter(int after)
Set the number of objects that must be written before resetting the stream.

Parameters:
after - Number of objects to write before resetting.
Throws:
java.lang.IllegalArgumentException - After <= 0

getResetAfter

public final int getResetAfter()
Get the number of objects that must be written before resetting the stream.

Returns:
Number of objects to write before resetting.

getCount

public final int getCount()
Get the number of objects written to the stream so far.

Returns:
The number of objects written to the stream so far.

writeObjectOverride

protected void writeObjectOverride(java.lang.Object obj)
                            throws java.io.IOException
Write the given object and reset if the number of objects written (including this one) exceeds the after count.

Overrides:
writeObjectOverride in class ObjectOutputStreamAdapter (src)
Parameters:
obj - Object to write.
Throws:
java.io.IOException - Any exception thrown by the underlying stream.

reset

public void reset()
           throws java.io.IOException
Resets the object counter as well as the nested stream.

Overrides:
reset in class ObjectOutputStreamAdapter (src)
Throws:
java.io.IOException