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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBufferWriter(IOSubchannel channel) Creates a new instance that usesOutputevents to dispatch buffers on the given channel, using the channel’s response pipeline.AbstractBufferWriter(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).protected abstract voidEnsure that a buffer for output data is available.voidflush()Creates and fires aOutputevent with the buffer being filled if it contains any data.protected voidflush(boolean endOfRecord) Creates and fires anOutputevent 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.voidwrite(char[] cbuf) abstract voidwrite(char[] data, int offset, int length) voidwrite(int ch) voidabstract voidMethods inherited from class java.io.Writer
append, append, append, nullWriter
-
Field Details
-
channel
-
buffer
-
-
Constructor Details
-
AbstractBufferWriter
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
-
AbstractBufferWriter
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:
- 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 anOutputevent 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 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(). -
close
Flushes any remaining data with the end of record flag set (unlesssuppressEndOfRecord()has been called) and fires aCloseevent (unlesssuppressClose()has been called).
-