Package org.jgrapes.io.util
Class CharBufferWriter
java.lang.Object
java.io.Writer
org.jgrapes.io.util.CharBufferWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
An
Writer
that is backed by CharBuffer
s obtained from a
queue.When a byte buffer is full, an Output
event (default) is
generated and a new buffer is fetched from the queue.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCharBufferWriter
(IOSubchannel channel) Creates a new instance that usesOutput
events to dispatch buffers on the given channel, using the channel’s response pipeline.CharBufferWriter
(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
(char[] data, int offset, int length)
-
Constructor Details
-
CharBufferWriter
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
-
CharBufferWriter
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 classWriter
- Throws:
IOException
-
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
- Specified by:
flush
in classWriter
- Throws:
IOException
-
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
- Specified by:
close
in classWriter
- Throws:
IOException
-