org.glassfish.jersey.internal.util
Class CommittingOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.glassfish.jersey.internal.util.CommittingOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public abstract class CommittingOutputStream
extends java.io.OutputStream

An abstract committing output stream adapter that performs a commit before the first byte is written to the adapted OutputStream. Concrete implementations of the class typically override the commit operation to perform any initialization on the adapted output stream.

Author:
Paul Sandoz, Marek Potociar (marek.potociar at oracle.com)

Constructor Summary
CommittingOutputStream()
          Construct a new committing output stream using a deferred initialization of the adapted output stream.
CommittingOutputStream(java.io.OutputStream out)
          Construct a new committing output stream using an eager initialization of the adapted output stream.
 
Method Summary
 void close()
           
protected abstract  void commit()
          Perform the commit functionality.
 void flush()
           
protected  java.io.OutputStream getOutputStream()
          Get the adapted output stream.
 boolean isCommitted()
          Determines whether the stream was already committed or not.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommittingOutputStream

public CommittingOutputStream()
Construct a new committing output stream using a deferred initialization of the adapted output stream.

When this constructor is utilized to construct a committing output stream instance, the method getOutputStream() MUST be overridden to return the adapted output stream.

See Also:
adapting constructor

CommittingOutputStream

public CommittingOutputStream(java.io.OutputStream out)
Construct a new committing output stream using an eager initialization of the adapted output stream.

When this constructor is utilized to construct a committing output stream instance, the method getOutputStream() will be ignored and never invoked to retrieve the adapted output stream.

Parameters:
out - the adapted output stream.
Throws:
java.lang.IllegalArgumentException - if supplied output stream is null.
See Also:
deferred initialization constructor
Method Detail

isCommitted

public boolean isCommitted()
Determines whether the stream was already committed or not.

Returns:
true if this stream was already committed, false otherwise.

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException

getOutputStream

protected java.io.OutputStream getOutputStream()
                                        throws java.io.IOException
Get the adapted output stream. The method is called at most once (in case the internal adapted output stream has not been initialized via adapting constructor) as part of the commit operation immediately after the commit() method has been invoked.

This method MUST be overridden if the empty deferred initialization constructor is utilized to construct an instance of this class.

Returns:
the adapted output stream.
Throws:
java.io.IOException

commit

protected abstract void commit()
                        throws java.io.IOException
Perform the commit functionality.

Throws:
java.io.IOException


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.