Package org.apache.mina.filter
Class StreamWriteFilter
- java.lang.Object
-
- org.apache.mina.common.IoFilterAdapter
-
- org.apache.mina.filter.StreamWriteFilter
-
- All Implemented Interfaces:
IoFilter
public class StreamWriteFilter extends IoFilterAdapter
Filter implementation which makes it possible to writeInputStream
objects directly usingIoSession.write(Object)
. When anInputStream
is written to a session this filter will read the bytes from the stream intoByteBuffer
objects and write those buffers to the next filter. When end of stream has been reached this filter will callIoFilter.NextFilter.messageSent(IoSession, Object)
using the originalInputStream
written to the session and notifiesWriteFuture
on the originalIoFilter.WriteRequest
. This filter will ignore written messages which aren'tInputStream
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. TheIoHandler
should take care of that in itsIoHandler.messageSent(IoSession, Object)
callback.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.mina.common.IoFilter
IoFilter.NextFilter, IoFilter.WriteRequest
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CURRENT_STREAM
The attribute name used when binding theInputStream
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 Summary
Constructors Constructor Description StreamWriteFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
filterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest)
FiltersIoSession.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)
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 Detail
-
DEFAULT_STREAM_BUFFER_SIZE
public static final int DEFAULT_STREAM_BUFFER_SIZE
The default buffer size this filter uses for writing.- See Also:
- Constant Field Values
-
CURRENT_STREAM
public static final java.lang.String CURRENT_STREAM
The attribute name used when binding theInputStream
to the session.
-
WRITE_REQUEST_QUEUE
protected static final java.lang.String WRITE_REQUEST_QUEUE
-
INITIAL_WRITE_FUTURE
protected static final java.lang.String INITIAL_WRITE_FUTURE
-
-
Method Detail
-
filterWrite
public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest) throws java.lang.Exception
Description copied from interface:IoFilter
FiltersIoSession.write(Object)
method invocation.- Specified by:
filterWrite
in interfaceIoFilter
- Overrides:
filterWrite
in classIoFilterAdapter
- Throws:
java.lang.Exception
-
messageSent
public void messageSent(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Object message) throws java.lang.Exception
Description copied from interface:IoFilter
FiltersIoHandler.messageSent(IoSession,Object)
event.- Specified by:
messageSent
in interfaceIoFilter
- Overrides:
messageSent
in classIoFilterAdapter
- Throws:
java.lang.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:
java.lang.IllegalArgumentException
- if the specified size is < 1.
-
-