com.gc.iotools.stream.writer
Class CloseShieldWriter<T extends Writer>

java.lang.Object
  extended by java.io.Writer
      extended by java.io.FilterWriter
          extended by com.gc.iotools.stream.writer.CloseShieldWriter<T>
Type Parameters:
T - Type of the Writer passed in the constructor.
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class CloseShieldWriter<T extends Writer>
extends FilterWriter

A CloseShieldWriter wraps some other Writer, which it uses as its basic sink of data. The class CloseShieldWriter delegates all requests to the contained writer, except the close() method that is not to the underlying stream.

This class is typically used in cases where a Writer needs to be passed to a component that wants to explicitly close the stream but other components still need to write data on it.

Since:
1.2.8
Version:
$Id: CloseShieldWriter.java 527 2014-02-24 19:29:50Z gabriele.contini@gmail.com $
Author:
dvd.smnt

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

Constructor Detail

CloseShieldWriter

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

Type Parameters:
T - a T object.
Parameters:
source - original Writer
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 FilterWriter
Throws:
IOException

getCloseCount

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

Returns:
Number of times that close was called

getWrappedWriter

public T getWrappedWriter()

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

Returns:
The original Writer passed in the constructor


Copyright © 2008–2014. All rights reserved.