Package org.jgrapes.io.util
Class AbstractBufferWriter<B extends Buffer>
java.lang.Object
java.io.Writer
org.jgrapes.io.util.AbstractBufferWriter<B>
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
- Direct Known Subclasses:
ByteBufferWriter
,CharBufferWriter
A base class for
CharBufferWriter
and ByteBufferWriter
.-
Field Summary
-
Constructor Summary
ConstructorDescriptionAbstractBufferWriter
(IOSubchannel channel) Creates a new instance that usesOutput
events to dispatch buffers on the given channel, using the channel’s response pipeline.AbstractBufferWriter
(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).protected abstract void
Ensure that a buffer for output data is available.void
flush()
Creates and fires aOutput
event with the buffer being filled if it contains any data.protected void
flush
(boolean endOfRecord) Creates and fires anOutput
event with the buffer being filled.protected AbstractBufferWriter
<B> setEventAssociations
(Map<Object, Object> associations) Configure associations that are applied to the generated Output events, seeEvent.setAssociated(java.lang.Object, java.lang.Object)
.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
(char[] cbuf) abstract void
write
(char[] data, int offset, int length) void
write
(int ch) void
abstract void
Methods inherited from class java.io.Writer
append, append, append, nullWriter
-
Field Details
-
channel
-
buffer
-
-
Constructor Details
-
AbstractBufferWriter
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
-
AbstractBufferWriter
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:
- this object for easy chaining
-
suppressClose
Suppresses sending of a close event when the stream is closed.- Returns:
- this object for easy chaining
-
suppressEndOfRecord
Suppresses setting the end of record flag when the stream is flushed or closed.- Returns:
- this object for easy chaining
- See Also:
-
setEventAssociations
Configure associations that are applied to the generated Output events, seeEvent.setAssociated(java.lang.Object, java.lang.Object)
.- Parameters:
associations
- the associations to apply- Returns:
- this object for easy chaining
-
ensureBufferAvailable
Ensure that a buffer for output data is available.- Throws:
InterruptedException
- the interrupted exception
-
write
-
write
-
write
-
write
-
write
-
flush
Creates and fires anOutput
event with the buffer being filled.The end of record flag of the event is set according to the parameter. Frees any allocated buffer.
-
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()
. -
close
Flushes any remaining data with the end of record flag set (unlesssuppressEndOfRecord()
has been called) and fires aClose
event (unlesssuppressClose()
has been called).
-