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

java.lang.Object
  extended by java.io.Writer
      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 Writer

A CloseShieldWriter wraps some other Writer, which it uses as its basic sink of data. The class CloseShieldWriter pass 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 even if other components still want to write data on it.

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

Field Summary
 
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
 Writer append(char c)
          
 Writer append(CharSequence csq)
          
 Writer append(CharSequence csq, int start, int end)
          
 void close()
          
 void flush()
          
 int getCloseCount()
          Returns the number of time that close was called.
 T getWrappedWriter()
           Returns the wrapped (original) Writer passed in the constructor.
 String toString()
          
 void write(char[] cbuf)
          
 void write(char[] cbuf, int off, int len)
          
 void write(int c)
          
 void write(String str)
          
 void write(String str, int off, int len)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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

append

public Writer append(char c)
              throws IOException

Specified by:
append in interface Appendable
Overrides:
append in class Writer
Throws:
IOException

append

public Writer append(CharSequence csq)
              throws IOException

Specified by:
append in interface Appendable
Overrides:
append in class Writer
Throws:
IOException

append

public Writer append(CharSequence csq,
                     int start,
                     int end)
              throws IOException

Specified by:
append in interface Appendable
Overrides:
append in class Writer
Throws:
IOException

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
Specified by:
close in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
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

toString

public String toString()

Overrides:
toString in class Object

write

public void write(char[] cbuf)
           throws IOException

Overrides:
write in class Writer
Throws:
IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException

Specified by:
write in class Writer
Throws:
IOException

write

public void write(int c)
           throws IOException

Overrides:
write in class Writer
Throws:
IOException

write

public void write(String str)
           throws IOException

Overrides:
write in class Writer
Throws:
IOException

write

public void write(String str,
                  int off,
                  int len)
           throws IOException

Overrides:
write in class Writer
Throws:
IOException


Copyright © 2008-2011. All Rights Reserved.