com.Ostermiller.util Java Utilities


com.Ostermiller.util
Class NoCloseWriter

java.lang.Object
  extended by java.io.Writer
      extended by com.Ostermiller.util.NoCloseWriter
All Implemented Interfaces:
NoCloseStream, Closeable, Flushable, Appendable

public class NoCloseWriter
extends Writer
implements NoCloseStream

A writer with a close method with no effect. More information about this class is available from ostermiller.org.

This class is designed to wrap a normal writer so that it can be passed to methods that write to it and may erroneously close it. This class is a workaround when the method cannot be modified because it is in a library.

Since:
ostermillerutils 1.01.00
Author:
Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities

Constructor Summary
NoCloseWriter(Writer out)
          Protect a new writer.
 
Method Summary
 void close()
          Has no effect.
 void flush()
          
 void reallyClose()
          Actually closes this stream and releases any system resources associated with the stream, as opposed to the close() method, which does nothing.
 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.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NoCloseWriter

public NoCloseWriter(Writer out)
Protect a new writer.

Parameters:
out - The writer that is being protected.
Method Detail

write

public void write(int c)
           throws IOException

Overrides:
write in class Writer
Throws:
IOException

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(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

flush

public void flush()
           throws IOException

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

close

public void close()
           throws IOException
Has no effect.

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException
Since:
ostermillerutils 1.01.00
See Also:
reallyClose()

reallyClose

public void reallyClose()
                 throws IOException
Actually closes this stream and releases any system resources associated with the stream, as opposed to the close() method, which does nothing.

Specified by:
reallyClose in interface NoCloseStream
Throws:
IOException - if an I/O error occurs.

com.Ostermiller.util Java Utilities


Copyright © 2001-2012 by Stephen Ostermiller