T
- Type of the Writer passed in the constructor.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.
Writer.close()
out
Constructor and Description |
---|
CloseOnceWriter(T source)
Construct a
CloseOnceWriter that forwards the calls to the
source Writer passed in the constructor. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
int |
getCloseCount()
Returns the number of time that close was called.
|
T |
getWrappedWriter()
Returns the wrapped (original)
Writer passed in the
constructor. |
flush, write, write, write
public CloseOnceWriter(T source)
CloseOnceWriter
that forwards the calls to the
source Writer passed in the constructor.source
- original Writerpublic void close() throws IOException
Multiple invocation of this method will result in only one invocation of
the close()
on the underlying stream.
close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterWriter
IOException
public int getCloseCount()
public T getWrappedWriter()
Returns the wrapped (original) Writer
passed in the
constructor.
Writer
passed in the constructorCopyright © 2008–2016. All rights reserved.