Package org.xnio.streams

# Class BufferPipeOutputStream

java.lang.Object
java.io.OutputStream
org.xnio.streams.BufferPipeOutputStream

All Implemented Interfaces:
  `Closeable`, `Flushable`, `AutoCloseable`

public class BufferPipeOutputStream extends OutputStream
An `OutputStream` implementation which writes out `ByteBuffer`s to a consumer.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static interface`
`BufferPipeOutputStream.BufferWriter`
A buffer writer for an `BufferPipeOutputStream`.

## Constructor Summary

Constructors
Constructor
Description
`BufferPipeOutputStream(BufferPipeOutputStream.BufferWriter bufferWriterTask)`
Construct a new instance.

## Method Summary

Modifier and Type
Method
Description
`Pooled<ByteBuffer>`
`breakPipe()`
Break the pipe and return any filling pooled buffer.
`void`
`close()`
`void`
`flush()`
`void`
`write(byte[] b, int off, int len)`
`void`
`write(int b)`

### Methods inherited from class java.io.OutputStream

`nullOutputStream, write`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### BufferPipeOutputStream

public BufferPipeOutputStream(BufferPipeOutputStream.BufferWriter bufferWriterTask) throws IOException
Construct a new instance. The internal buffers will have a capacity of `bufferSize`. The given `bufferWriterTask` will be called to send buffers, flush the output stream, and handle the end-of-file condition.

Parameters:
  `bufferWriterTask` - the writer task
Throws:
  `IOException` - if an error occurs while initializing the stream

## Method Details

### write

public void write(int b) throws IOException

Specified by:
  `write` in class `OutputStream`
Throws:
  `IOException`

### write

public void write(byte[] b, int off, int len) throws IOException

Overrides:
  `write` in class `OutputStream`
Throws:
  `IOException`

### flush

public void flush() throws IOException

Specified by:
  `flush` in interface `Flushable`
Overrides:
  `flush` in class `OutputStream`
Throws:
  `IOException`

### close

public void close() throws IOException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Overrides:
  `close` in class `OutputStream`
Throws:
  `IOException`

### breakPipe

public Pooled<ByteBuffer> breakPipe()
Break the pipe and return any filling pooled buffer. Sets the stream to an EOF condition. Callers to this method should ensure that any threads blocked on `BufferPipeOutputStream.BufferWriter.accept(org.xnio.Pooled, boolean)` are unblocked, preferably with a `BrokenPipeException`.

Returns:
  the current pooled buffer, or `null` if none was pending