com.clarkparsia.modularity.io
Class UncloseableOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.clarkparsia.modularity.io.UncloseableOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class UncloseableOutputStream
extends java.io.OutputStream

Title:

Description:

Copyright: Copyright (c) 2009

Company: Clark & Parsia, LLC.

A wrapper around the underlying stream that prevents the underlying stream from being closed (if passed to other methods that are not very nice and close your stream). The initial motivation for this wrapper was ZipOutputStream where you write into multiple separate entries; some methods (which are not aware that they write to a ZipOutputStream) when they finish writing their data they close the stream, which terminates the whole process of producing the zip file.

Author:
Blazej Bulka

Constructor Summary
UncloseableOutputStream(java.io.OutputStream stream)
          Wraps an output stream with a wrapper that does not allow the underlying stream to be closed.
 
Method Summary
 void close()
          Captures the close request, and does NOT forward it to the underlying stream.
 void flush()
          Forwards the call to the underlying stream.
 java.io.OutputStream getUnderlyingStream()
          Gets the underlying stream.
 void write(byte[] b)
          Forwards the call to the underlying stream.
 void write(byte[] b, int off, int len)
          Forwards the call to the underlying stream.
 void write(int b)
          Forwards the call to the underlying stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UncloseableOutputStream

public UncloseableOutputStream(java.io.OutputStream stream)
Wraps an output stream with a wrapper that does not allow the underlying stream to be closed.

Parameters:
stream - the underlying stream to be protected from closing.
Method Detail

close

public void close()
Captures the close request, and does NOT forward it to the underlying stream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream

flush

public void flush()
           throws java.io.IOException
Forwards the call to the underlying stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Forwards the call to the underlying stream.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Forwards the call to the underlying stream.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Forwards the call to the underlying stream.

Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

getUnderlyingStream

public java.io.OutputStream getUnderlyingStream()
Gets the underlying stream. This method may be useful to actually close the underlying stream, when all the calls are finished.

Returns:
the underlying stream.


Copyright © 2004 Evren Sirin. All Rights Reserved.