## org.exist.validation.internal
Class BlockingOutputStream

    java.lang.Object
      java.io.OutputStream
          org.exist.validation.internal.BlockingOutputStream

public class BlockingOutputStream
extends java.io.OutputStream

`BlockingOutputStream` is a combination of an output stream and an input stream, connected through a (circular) buffer in memory. It is intended for coupling producer threads to consumer threads via a (byte) stream. When the buffer is full producer threads will be blocked until the buffer has some free space again. When the buffer is empty the consumer threads will be blocked until some bytes are available again.

Constructor Summary
`BlockingOutputStream()`

Method Summary
`int` `available()` The number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.
`void` `close()` Closes this input stream and releases any system resources associated with the stream.
`void` `closeOutputStream()` Equivalent of the `close()` method of an output stream.
`void` `flush()` Flushes this output stream and forces any buffered output bytes to be written out.
`int` `free()` The number of bytes that can be written to this output stream without blocking by the next caller of a method for this output stream.
`int` `read()` Reads the next byte of data from the input stream.
`int` `read(byte[] b, int off, int len)` Reads up to `len` bytes of data from the input stream into an array of bytes.
`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()

Method Detail

### read

    public int read()
             throws java.io.IOException

  Reads the next byte of data from the input stream. The value byte is returned as an `int` in the range `0` to `255`. If no byte is available because the end of the stream has been reached, the value `-1` is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

  Returns:
    the next byte of data, or `-1` if the end of the stream is reached.
  Throws:
    `java.io.IOException` - if an I/O error occurs.

### read

    public int read(byte[] b,
                    int off,
                    int len)
             throws java.io.IOException

  Reads up to `len` bytes of data from the input stream into an array of bytes. An attempt is made to read as many as `len` bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

  This method blocks until input data is available, end of file is detected, or an exception is thrown.

  Parameters:
    `b` - the buffer into which the data is read.
    `off` - the start offset in array `b` at which the data is written.
    `len` - the maximum number of bytes to read.
  Returns:
    the total number of bytes read into the buffer, or `-1` if there is no more data because the end of the stream has been reached.
  Throws:
    `java.io.IOException` - if an I/O error occurs.
    `java.lang.NullPointerException` - if `b` is `null`.

### close

    public void close()
               throws java.io.IOException

  Closes this input stream and releases any system resources associated with the stream.

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

### available

    public int available()

  The number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.

  Returns:
    the number of bytes that can be read from this input stream without blocking.
  Throws:
    `java.io.IOException` - if an I/O error occurs.

### write

    public void write(int b)
               throws java.io.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.

  Parameters:
    `b` - the `byte`.
  Throws:
    `java.io.IOException` - if an I/O error occurs. In particular, an `IOException` may be thrown if the output stream has been closed.

### write

    public void write(byte[] b,
                      int off,
                      int len)
               throws java.io.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.

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

### closeOutputStream

    public void closeOutputStream()
                           throws java.io.IOException

  Equivalent of the `close()` method of an output stream. Renamed to solve the name clash with the `close()` method of the input stream also implemented by this class. Closes this output stream and releases any system resources associated with this stream. A closed stream cannot perform output operations and cannot be reopened.

  This method blocks its caller until all bytes remaining in the buffer are read from the buffer by the receiving threads or an exception occurs.

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

### flush

    public void flush()
               throws java.io.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.

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

### free

    public int free()

  The number of bytes that can be written to this output stream without blocking by the next caller of a method for this output stream.

  Returns:
    the number of bytes that can be written to this output stream without blocking.
  Throws:
    `java.io.IOException` - if an I/O error occurs.

Copyright (C) Wolfgang Meier. All rights reserved.