/*************************************** * * * JBoss: The OpenSource J2EE WebOS * * * * Distributable under LGPL license. * * See terms of license at gnu.org. * * * ***************************************/ package org.jboss.util.stream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; /** * An ObjectOutputStream that can conditionally be put into * appending mode. * *
*
Concurrency:
*
This class is not synchronized.
*
* * @version $Revision: 1.1 $ * @author Jason Dillon */ public class AppendingObjectOutputStream extends ObjectOutputStreamAdapter { /** * Construct an AppendingObjectOutputStream. * * @param out An OutputStream stream. * @param append True to append written objects; false * to use default action (writes stream header). * * @throws IOException Any exception thrown by * the underlying OutputStream. */ public AppendingObjectOutputStream(OutputStream out, boolean append) throws IOException { super(createStream(out, append)); } /** * Helper to return a ObjectOutputStream. */ private static ObjectOutputStream createStream(OutputStream out, boolean append) throws IOException { ObjectOutputStream stream; // if we are appending then return an append only stream if (append) { stream = new AppendObjectOutputStream(out); } // else if it already an oos then return it else if (out instanceof ObjectOutputStream) { stream = (ObjectOutputStream)out; } // else wrap the stream in an oos else { stream = new ObjectOutputStream(out); } return stream; } }