public class StreamWriteFilter extends IoFilterAdapter
InputStream
objects directly using IoSession.write(Object)
. When an
InputStream
is written to a session this filter will read the bytes
from the stream into ByteBuffer
objects and write those buffers
to the next filter. When end of stream has been reached this filter will
call NextFilter#messageSent(IoSession, Object)
using the original
InputStream
written to the session and notifies
WriteFuture
on the
original IoFilter.WriteRequest
.
This filter will ignore written messages which aren't InputStream
instances. Such messages will be passed to the next filter directly.
NOTE: this filter does not close the stream after all data from stream
has been written. The IoHandler
should take
care of that in its
IoHandler.messageSent(IoSession, Object)
callback.
IoFilter.NextFilter, IoFilter.WriteRequest
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CURRENT_STREAM
The attribute name used when binding the
InputStream to the session. |
static int |
DEFAULT_STREAM_BUFFER_SIZE
The default buffer size this filter uses for writing.
|
protected static java.lang.String |
INITIAL_WRITE_FUTURE |
protected static java.lang.String |
WRITE_REQUEST_QUEUE |
Constructor and Description |
---|
StreamWriteFilter() |
Modifier and Type | Method and Description |
---|---|
void |
filterWrite(IoFilter.NextFilter nextFilter,
IoSession session,
IoFilter.WriteRequest writeRequest)
Filters
IoSession.write(Object) method invocation. |
int |
getWriteBufferSize()
Returns the size of the write buffer in bytes.
|
void |
messageSent(IoFilter.NextFilter nextFilter,
IoSession session,
java.lang.Object message)
Filters
IoHandler.messageSent(IoSession,Object)
event. |
void |
setWriteBufferSize(int writeBufferSize)
Sets the size of the write buffer in bytes.
|
destroy, exceptionCaught, filterClose, init, messageReceived, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionClosed, sessionCreated, sessionIdle, sessionOpened
public static final int DEFAULT_STREAM_BUFFER_SIZE
public static final java.lang.String CURRENT_STREAM
InputStream
to the session.protected static final java.lang.String WRITE_REQUEST_QUEUE
protected static final java.lang.String INITIAL_WRITE_FUTURE
public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest) throws java.lang.Exception
IoFilter
IoSession.write(Object)
method invocation.filterWrite
in interface IoFilter
filterWrite
in class IoFilterAdapter
java.lang.Exception
public void messageSent(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Object message) throws java.lang.Exception
IoFilter
IoHandler.messageSent(IoSession,Object)
event.messageSent
in interface IoFilter
messageSent
in class IoFilterAdapter
java.lang.Exception
public int getWriteBufferSize()
public void setWriteBufferSize(int writeBufferSize)
java.lang.IllegalArgumentException
- if the specified size is < 1.Copyright © 2004-2019 Apache MINA Project. All Rights Reserved.