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 writeInputStreamobjects directly usingIoSession.write(Object). When anInputStreamis written to a session this filter will read the bytes from the stream intoByteBufferobjects 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 originalInputStreamwritten to the session and notifiesWriteFutureon the originalIoFilter.WriteRequest. This filter will ignore written messages which aren'tInputStreaminstances. 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. TheIoHandlershould 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.StringCURRENT_STREAMThe attribute name used when binding theInputStreamto the session.static intDEFAULT_STREAM_BUFFER_SIZEThe default buffer size this filter uses for writing.protected static java.lang.StringINITIAL_WRITE_FUTUREprotected static java.lang.StringWRITE_REQUEST_QUEUE
-
Constructor Summary
Constructors Constructor Description StreamWriteFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfilterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest)FiltersIoSession.write(Object)method invocation.intgetWriteBufferSize()Returns the size of the write buffer in bytes.voidmessageSent(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Object message)FiltersIoHandler.messageSent(IoSession,Object)event.voidsetWriteBufferSize(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 theInputStreamto 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:IoFilterFiltersIoSession.write(Object)method invocation.- Specified by:
filterWritein interfaceIoFilter- Overrides:
filterWritein 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:IoFilterFiltersIoHandler.messageSent(IoSession,Object)event.- Specified by:
messageSentin interfaceIoFilter- Overrides:
messageSentin 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.
-
-