com.gc.iotools.stream.os
Class CloseOnceOutputStream<T extends OutputStream>

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by com.gc.iotools.stream.os.CloseOnceOutputStream<T>
Type Parameters:
T - Type of the OutputStream passed in the constructor.
All Implemented Interfaces:
Closeable, Flushable

public class CloseOnceOutputStream<T extends OutputStream>
extends FilterOutputStream

A decorating OutputStream that prevents multiple invocations of the close() method on the underlying stream.

Multiple invocation of the close() method will result in only one invocation of the same method on the underlying stream. This is useful with some non standard OutputStream that don't allow close() to be called multiple times.

Since:
1.2.14
Version:
$Id: CloseOnceOutputStream.java 523 2013-01-02 15:46:17Z gabriele.contini@gmail.com $
Author:
Gabriele Contini

Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
CloseOnceOutputStream(T source)
          Construct a CloseOnceOutputStream that forwards the calls to the source OutputStream passed in the constructor.
 
Method Summary
 void close()
          
 int getCloseCount()
          Returns the number of time that close was called.
 T getWrappedOutputStream()
           Returns the wrapped (original) OutputStream passed in the constructor.
 
Methods inherited from class java.io.FilterOutputStream
flush, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CloseOnceOutputStream

public CloseOnceOutputStream(T source)
Construct a CloseOnceOutputStream that forwards the calls to the source OutputStream passed in the constructor.

Parameters:
source - original OutputStream
Method Detail

close

public void close()
           throws IOException

Multiple invocation of this method will result in only one invocation of the close() on the underlying stream.

Specified by:
close in interface Closeable
Overrides:
close in class FilterOutputStream
Throws:
IOException

getCloseCount

public int getCloseCount()
Returns the number of time that close was called.

Returns:
Number of times that close was called
See Also:
com.gc.iotools.stream.is.inspection.DiagnosticOutputStream

getWrappedOutputStream

public T getWrappedOutputStream()

Returns the wrapped (original) OutputStream passed in the constructor.

Returns:
The original OutputStream passed in the constructor


Copyright © 2008–2014. All rights reserved.