Package org.apache.mina.filter
Class StreamWriteFilter
java.lang.Object
org.apache.mina.common.IoFilterAdapter
org.apache.mina.filter.StreamWriteFilter
- All Implemented Interfaces:
IoFilter
Filter implementation which makes it possible to write
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 IoFilter.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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.mina.common.IoFilter
IoFilter.NextFilter, IoFilter.WriteRequest
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The attribute name used when binding theInputStream
to the session.static final int
The default buffer size this filter uses for writing.protected static final String
protected static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
filterWrite
(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest) FiltersIoSession.write(Object)
method invocation.int
Returns the size of the write buffer in bytes.void
messageSent
(IoFilter.NextFilter nextFilter, IoSession session, Object message) FiltersIoHandler.messageSent(IoSession,Object)
event.void
setWriteBufferSize
(int writeBufferSize) Sets the size of the write buffer in bytes.Methods inherited from class org.apache.mina.common.IoFilterAdapter
destroy, exceptionCaught, filterClose, init, messageReceived, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionClosed, sessionCreated, sessionIdle, sessionOpened
-
Field Details
-
DEFAULT_STREAM_BUFFER_SIZE
public static final int DEFAULT_STREAM_BUFFER_SIZEThe default buffer size this filter uses for writing.- See Also:
-
CURRENT_STREAM
The attribute name used when binding theInputStream
to the session. -
WRITE_REQUEST_QUEUE
-
INITIAL_WRITE_FUTURE
-
-
Constructor Details
-
StreamWriteFilter
public StreamWriteFilter()
-
-
Method Details
-
filterWrite
public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest) throws Exception Description copied from interface:IoFilter
FiltersIoSession.write(Object)
method invocation.- Specified by:
filterWrite
in interfaceIoFilter
- Overrides:
filterWrite
in classIoFilterAdapter
- Throws:
Exception
-
messageSent
public void messageSent(IoFilter.NextFilter nextFilter, IoSession session, Object message) throws Exception Description copied from interface:IoFilter
FiltersIoHandler.messageSent(IoSession,Object)
event.- Specified by:
messageSent
in interfaceIoFilter
- Overrides:
messageSent
in classIoFilterAdapter
- Throws:
Exception
-
getWriteBufferSize
public int getWriteBufferSize()Returns the size of the write buffer in bytes. Data will be read from the stream in chunks of this size and then written to the next filter.- Returns:
- the write buffer size.
-
setWriteBufferSize
public void setWriteBufferSize(int writeBufferSize) Sets the size of the write buffer in bytes. Data will be read from the stream in chunks of this size and then written to the next filter.- Throws:
IllegalArgumentException
- if the specified size is < 1.
-