org.apache.mina.filter

Class StreamWriteFilter

Implemented Interfaces:
IoFilter

public class StreamWriteFilter
extends IoFilterAdapter

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 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.

Field Summary

static 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 String
INITIAL_WRITE_FUTURE
protected static String
WRITE_REQUEST_QUEUE

Method Summary

int
getWriteBufferSize()
Returns the size of the write buffer in bytes.
void
setWriteBufferSize(int writeBufferSize)
Sets the size of the write buffer in bytes.
@Override
void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
@Override
void messageSent(NextFilter nextFilter, IoSession session, Object message)

Methods inherited from class org.apache.mina.common.IoFilterAdapter

destroy, exceptionCaught, filterClose, filterWrite, init, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionClosed, sessionCreated, sessionIdle, sessionOpened

Field Details

CURRENT_STREAM

public static final String CURRENT_STREAM
The attribute name used when binding the InputStream to the session.

DEFAULT_STREAM_BUFFER_SIZE

public static final int DEFAULT_STREAM_BUFFER_SIZE
The default buffer size this filter uses for writing.
Field Value:
4096

INITIAL_WRITE_FUTURE

protected static final String INITIAL_WRITE_FUTURE

WRITE_REQUEST_QUEUE

protected static final String WRITE_REQUEST_QUEUE

Method Details

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.

void filterWrite

public @Override void filterWrite(NextFilter nextFilter,
                                  IoSession session,
                                  WriteRequest writeRequest)
            throws Exception

void messageSent

public @Override void messageSent(NextFilter nextFilter,
                                  IoSession session,
                                  Object message)
            throws Exception