org.exist.storage.io
Class BlockingOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.exist.storage.io.BlockingOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class BlockingOutputStream
extends OutputStream

Output stream adapter for a BlockingInputStream.

Author:
Chris Offerman

Constructor Summary
BlockingOutputStream(BlockingInputStream stream)
          Create a new BlockingOutputStream adapter.
 
Method Summary
 void close()
          Closes this output stream.
 void close(Exception ex)
          Closes this output stream, specifying that an exception has occurred.
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
 BlockingInputStream getInputStream()
          BlockingInputStream of this BlockingOutputStream.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockingOutputStream

public BlockingOutputStream(BlockingInputStream stream)
Create a new BlockingOutputStream adapter.

Parameters:
stream - The BlockingInputStream to adapt.
Method Detail

getInputStream

public BlockingInputStream getInputStream()
BlockingInputStream of this BlockingOutputStream.


write

public void write(int b)
           throws IOException
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Specified by:
write in class OutputStream
Parameters:
b - the byte.
Throws:
ExistIOException - if an I/O error occurs. In particular, an ExistIOException may be thrown if the output stream has been closed.
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

Overrides:
write in class OutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

close

public void close()
           throws IOException
Closes this output stream. A closed stream cannot perform output operations and cannot be reopened.

This method blocks its caller until the corresponding input stream is closed or an exception occurs.

Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException - if an I/O error occurs.

close

public void close(Exception ex)
           throws IOException
Closes this output stream, specifying that an exception has occurred. This will cause all consumer calls to be unblocked and throw an IOException with this exception as its cause. BlockingInputStream specific method.

Throws:
IOException - if an I/O error occurs.

flush

public void flush()
           throws IOException
Flushes this output stream and forces any buffered output bytes to be written out.

This methods blocks its caller until all buffered bytes are actually read by the consuming threads.

Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException - if an I/O error occurs.


Copyright (C) Wolfgang Meier. All rights reserved.