- java.lang.Object
-
- java.io.OutputStream
-
- org.xnio.streams.BufferPipeOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class BufferPipeOutputStream extends java.io.OutputStream
AnOutputStream
implementation which writes outByteBuffer
s to a consumer.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
BufferPipeOutputStream.BufferWriter
A buffer writer for anBufferPipeOutputStream
.
-
Constructor Summary
Constructors Constructor Description BufferPipeOutputStream(BufferPipeOutputStream.BufferWriter bufferWriterTask)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Pooled<java.nio.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)
-
-
-
Constructor Detail
-
BufferPipeOutputStream
public BufferPipeOutputStream(BufferPipeOutputStream.BufferWriter bufferWriterTask) throws java.io.IOException
Construct a new instance. The internal buffers will have a capacity ofbufferSize
. The givenbufferWriterTask
will be called to send buffers, flush the output stream, and handle the end-of-file condition.- Parameters:
bufferWriterTask
- the writer task- Throws:
java.io.IOException
- if an error occurs while initializing the stream
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
breakPipe
public Pooled<java.nio.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 onBufferPipeOutputStream.BufferWriter.accept(org.xnio.Pooled, boolean)
are unblocked, preferably with aBrokenPipeException
.- Returns:
- the current pooled buffer, or
null
if none was pending
-
-