Top Description Inners Fields Constructors Methods
org.xnio.streams

public Class BufferPipeOutputStream

extends OutputStream
Class Inheritance
Imports
java.io.Flushable, .IOException, .OutputStream, java.nio.ByteBuffer, org.xnio.BrokenPipeException, .Buffers, .Pooled

An OutputStream implementation which writes out ByteBuffers to a consumer.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
private Pooled<ByteBuffer>
buffer

References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.
private final BufferPipeOutputStream.BufferWriter
private boolean

Constructor Summary

AccessConstructor and Description
public
BufferPipeOutputStream(final BufferPipeOutputStream.BufferWriter
the writer task
bufferWriterTask
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
public Pooled<ByteBuffer>

Returns:

the current pooled buffer, or null if none was pending
breakPipe
()
References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

Break the pipe and return any filling pooled buffer.

private void
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

private static IOException
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.

private void
flush(boolean eof)

private Pooled<ByteBuffer>
getBuffer()
References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

private void
send(boolean eof)

private void
send(Pooled<ByteBuffer> buffer, boolean eof)
References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

public void
write(final int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(final byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from java.io.OutputStream:
nullOutputStreamwrite

Field Detail

bufferback to summary
private Pooled<ByteBuffer> buffer

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

bufferWriterTaskback to summary
private final BufferPipeOutputStream.BufferWriter bufferWriterTask
closedback to summary
private boolean closed

Constructor Detail

BufferPipeOutputStreamback to summary
public BufferPipeOutputStream(final 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:BufferPipeOutputStream.BufferWriter

the writer task

Exceptions
IOException:
if an error occurs while initializing the stream

Method Detail

breakPipeback to summary
public Pooled<ByteBuffer> breakPipe()

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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 BufferWriter#accept(org.xnio.Pooled, boolean) are unblocked, preferably with a BrokenPipeException.

Returns:Pooled<ByteBuffer>

the current pooled buffer, or null if none was pending

checkClosedback to summary
private void checkClosed() throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Exceptions
IOException:
if an I/O error occurs.
closedback to summary
private static IOException closed()
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Exceptions
IOException:
if an I/O error occurs.
flushback to summary
private void flush(boolean eof) throws IOException
getBufferback to summary
private Pooled<ByteBuffer> getBuffer() throws IOException

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

sendback to summary
private void send(boolean eof) throws IOException
sendback to summary
private void send(Pooled<ByteBuffer> buffer, boolean eof) throws IOException

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

writeback to summary
public void write(final int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

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:int

the byte.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(final byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

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.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
org.xnio.streams back to summary

public Interface BufferPipeOutputStream.BufferWriter

extends Flushable

A buffer writer for an BufferPipeOutputStream.

Method Summary

Modifier and TypeMethod and Description
public void
accept(Pooled<ByteBuffer>
the buffer to send
pooledBuffer
,
boolean
true if this is the last buffer which will be sent
eof
)
References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

Accept a buffer.

public void
flush()

Redeclares java.io.Flushable.flush.

Flushes this stream by writing any buffered output to the underlying stream.

public Pooled<ByteBuffer>

Returns:

the new buffer
getBuffer
(boolean
true if this is the first buffer in the stream, false otherwise
firstBuffer
)
References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

Get a new buffer to be filled.

Method Detail

acceptback to summary
public void accept(Pooled<ByteBuffer> pooledBuffer, boolean eof) throws IOException

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Accept a buffer. If this is the last buffer that will be sent, the eof flag will be set to true. This method should block until the entire buffer is consumed, or an error occurs. This method may also block until some other condition, such as flow control, is met.

Parameters
pooledBuffer:Pooled<ByteBuffer>

the buffer to send

eof:boolean

true if this is the last buffer which will be sent

Exceptions
IOException:
if an I/O error occurs
flushback to summary
public void flush() throws IOException

Redeclares java.io.Flushable.flush.

Flushes this stream by writing any buffered output to the underlying stream. This method should block until the data is fully flushed. This method may also block until some other condition, such as flow control, is met.

Exceptions
IOException:
If an I/O error occurs
getBufferback to summary
public Pooled<ByteBuffer> getBuffer(boolean firstBuffer) throws IOException

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Get a new buffer to be filled. The new buffer may, for example, include a prepended header. This method may block until a buffer is available or until some other condition, such as flow control, is met.

Parameters
firstBuffer:boolean

true if this is the first buffer in the stream, false otherwise

Returns:Pooled<ByteBuffer>

the new buffer

Exceptions
IOException:
if an I/O error occurs