org.apache.mina.filter
Class StreamWriteFilter

java.lang.Object
  extended by org.apache.mina.common.IoFilterAdapter
      extended by org.apache.mina.filter.StreamWriteFilter
All 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.

Version:
$Rev: 587373 $, $Date: 2007-10-23 04:54:05 +0200 (Tue, 23 Oct 2007) $
Author:
The Apache Directory Project (mina-dev@directory.apache.org)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.mina.common.IoFilter
IoFilter.NextFilter, IoFilter.WriteRequest
 
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
           
 
Constructor Summary
StreamWriteFilter()
           
 
Method Summary
 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, Object message)
          Filters IoHandler.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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 String CURRENT_STREAM
The attribute name used when binding the InputStream to the session.


WRITE_REQUEST_QUEUE

protected static final String WRITE_REQUEST_QUEUE

INITIAL_WRITE_FUTURE

protected static final String INITIAL_WRITE_FUTURE
Constructor Detail

StreamWriteFilter

public StreamWriteFilter()
Method Detail

filterWrite

public void filterWrite(IoFilter.NextFilter nextFilter,
                        IoSession session,
                        IoFilter.WriteRequest writeRequest)
                 throws Exception
Description copied from interface: IoFilter
Filters IoSession.write(Object) method invocation.

Specified by:
filterWrite in interface IoFilter
Overrides:
filterWrite in class IoFilterAdapter
Throws:
Exception

messageSent

public void messageSent(IoFilter.NextFilter nextFilter,
                        IoSession session,
                        Object message)
                 throws Exception
Description copied from interface: IoFilter
Filters IoHandler.messageSent(IoSession,Object) event.

Specified by:
messageSent in interface IoFilter
Overrides:
messageSent in class IoFilterAdapter
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.


Copyright © 2004-2009 Apache MINA Project. All Rights Reserved.