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 StringThe attribute name used when binding theInputStreamto the session.static final intThe default buffer size this filter uses for writing.protected static final Stringprotected static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfilterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest) FiltersIoSession.write(Object)method invocation.intReturns the size of the write buffer in bytes.voidmessageSent(IoFilter.NextFilter nextFilter, IoSession session, 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 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 theInputStreamto 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:IoFilterFiltersIoSession.write(Object)method invocation.- Specified by:
filterWritein interfaceIoFilter- Overrides:
filterWritein classIoFilterAdapter- Throws:
Exception
-
messageSent
public void messageSent(IoFilter.NextFilter nextFilter, IoSession session, Object message) throws Exception Description copied from interface:IoFilterFiltersIoHandler.messageSent(IoSession,Object)event.- Specified by:
messageSentin interfaceIoFilter- Overrides:
messageSentin 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.
-