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

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

public class CloseOnceWriter<T extends Writer>
extends FilterWriter

A CloseOnceWriter wraps some other Writer preventing multiple invocations of the method close().

It forwards all requests to the contained writer, except the close() method that is passed only one time to the underlying stream.

This is useful with some non conforming Writer that don't allow close() to be called multiple times.

Since:
1.2.14
Version:
$Id: CloseOnceWriter.java 527 2014-02-24 19:29:50Z gabriele.contini@gmail.com $
Author:
Gabriele Contini
See Also:
Writer.close()

Field Summary
 
Fields inherited from class java.io.FilterWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
CloseOnceWriter(T source)
          Construct a CloseOnceWriter 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

CloseOnceWriter

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

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.