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 ByteBuffers 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
ConstructorsConstructorDescriptionByteBufferOutputStream(IOSubchannel channel) Creates a new instance that usesOutputevents to dispatch buffers on the given channel, using the channel’s response pipeline.ByteBufferOutputStream(IOSubchannel channel, EventPipeline eventPipeline) Creates a new instance that usesOutputevents to dispatch buffers on the given channel, using the given event pipeline. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Flushes any remaining data with the end of record flag set (unlesssuppressEndOfRecord()has been called) and fires aCloseevent (unlesssuppressClose()has been called).voidflush()Creates and fires aOutputevent 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.voidwrite(byte[] data) voidwrite(byte[] data, int offset, int length) voidwrite(int data) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
ByteBufferOutputStream
Creates a new instance that usesOutputevents 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 usesOutputevents 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:
writein classOutputStream
-
write
- Overrides:
writein classOutputStream
-
write
- Overrides:
writein classOutputStream
-
flush
Creates and fires aOutputevent with the buffer being filled if it contains any data.By default, the
Outputevent is created with the end of record flag set (seeIOEvent.isEndOfRecord()) in order to forward the flush as event. This implies that anOutputevent with no data (but the end of record flag set) may be fired. This behavior can be disabled withsuppressEndOfRecord().- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream
-
close
Flushes any remaining data with the end of record flag set (unlesssuppressEndOfRecord()has been called) and fires aCloseevent (unlesssuppressClose()has been called).- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream
-