Package org.jgrapes.io.util
Class ByteBufferOutputStream
java.lang.Object
java.io.OutputStream
org.jgrapes.io.util.ByteBufferOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
An
OutputStream
that is backed by ByteBuffer
s obtained from a
queue.When a byte buffer is full, a Output
event (default) is
generated and a new buffer is fetched from the queue.
-
Constructor Summary
ConstructorDescriptionByteBufferOutputStream
(IOSubchannel channel) Creates a new instance that usesOutput
events to dispatch buffers on the given channel, using the channel’s response pipeline.ByteBufferOutputStream
(IOSubchannel channel, EventPipeline eventPipeline) Creates a new instance that usesOutput
events to dispatch buffers on the given channel, using the given event pipeline. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Flushes any remaining data with the end of record flag set (unlesssuppressEndOfRecord()
has been called) and fires aClose
event (unlesssuppressClose()
has been called).void
flush()
Creates and fires aOutput
event with the buffer being filled if it contains any data.Suppresses sending of a close event when the stream is closed.Suppresses setting the end of record flag when the stream is flushed or closed.void
write
(byte[] data) void
write
(byte[] data, int offset, int length) void
write
(int data) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
ByteBufferOutputStream
Creates a new instance that usesOutput
events to dispatch buffers on the given channel, using the given event pipeline.- Parameters:
channel
- the channel to fire events oneventPipeline
- the event pipeline used for firing events
-
ByteBufferOutputStream
Creates a new instance that usesOutput
events to dispatch buffers on the given channel, using the channel’s response pipeline.- Parameters:
channel
- the channel to fire events on
-
-
Method Details
-
sendInputEvents
- Returns:
- the stream for easy chaining
-
suppressClose
Suppresses sending of a close event when the stream is closed.- Returns:
- the stream for easy chaining
-
suppressEndOfRecord
Suppresses setting the end of record flag when the stream is flushed or closed.- Returns:
- the stream for easy chaining
- See Also:
-
write
- Specified by:
write
in classOutputStream
-
write
- Overrides:
write
in classOutputStream
-
write
- Overrides:
write
in classOutputStream
-
flush
Creates and fires aOutput
event with the buffer being filled if it contains any data.By default, the
Output
event is created with the end of record flag set (seeIOEvent.isEndOfRecord()
) in order to forward the flush as event. This implies that anOutput
event with no data (but the end of record flag set) may be fired. This behavior can be disabled withsuppressEndOfRecord()
.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
-
close
Flushes any remaining data with the end of record flag set (unlesssuppressEndOfRecord()
has been called) and fires aClose
event (unlesssuppressClose()
has been called).- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
-