com.gc.iotools.stream.is
Class CloseOnceInputStream<T extends InputStream>

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by com.gc.iotools.stream.is.CloseOnceInputStream<T>
Type Parameters:
T - Type of the InputStream passed in the constructor.
All Implemented Interfaces:
Closeable

public class CloseOnceInputStream<T extends InputStream>
extends FilterInputStream

A CloseOnceInputStream contains some other input stream, which it uses as its basic source of data. The class CloseOnceInputStream pass all requests to the contained input stream, except the close() method that is passed only one time to 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 buggy InputStream that don't allow close() to be called multiple times.

Since:
1.2.6
Version:
$Id: CloseOnceInputStream.java 463 2011-01-21 23:54:17Z dvd.smnt@gmail.com $
Author:
dvd.smnt

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
CloseOnceInputStream(T source)
          Construct a CloseOnceInputStream that forwards the calls to the source InputStream passed in the constructor.
 
Method Summary
 void close()
          
 int getCloseCount()
          Returns the number of time that close was called.
 T getWrappedInputStream()
           Returns the wrapped (original) InputStream passed in the constructor.
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CloseOnceInputStream

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

Parameters:
source - original InputStream
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 FilterInputStream
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:
DiagnosticInputStream

getWrappedInputStream

public T getWrappedInputStream()

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

Returns:
The original InputStream passed in the constructor


Copyright © 2008-2011. All Rights Reserved.