To write back a binary file to the client use the StreamWriterFilter.
You must add it to the session's filter chain after your codec filter:
private static IoFilter CODEC_FILTER = new ProtocolCodecFilter(new
TextLineCodecFactory());
private static IoFilter STREAM_WRITE_FILTER = new StreamWriteFilter();
...
session.getFilterChain().addLast("codec", CODEC_FILTER);
session.getFilterChain().addLast("streamWriter", STREAM_WRITE_FILTER);
With the StreamWriteFilter in place you can write InputStreams directly
to the session. StreamWriteFilter will read the bytes from the stream
and pass those bytes along down the filter chain as MINA ByteBuffers. As
long as you write text or other messages which aren't InputStream
objects the StreamWriteFilter won't do anything. It's important that you
add StreamWriteFilter after your codec. ProtocolCodecFilter will not try
to encode anything written to the session which already is in byte form
(ByteBuffer).
Using the StreamWriteFilter like this all you have to do to write a file
to the client is:
session.write(new FileInputStream("c:\foo.txt"));
MINA will take care of the rest for you. If you need to do any
processing of the file data (like sending in it TEXT) mode you could
create a wrapper InputStream which wraps the FileInputStream and does
the processing in the read() method.
HTH
Niklas
Mark wrote:
> Great info. What I am looking for is a way to read in text (FTP
> Commands),
> and send text (responses) and binary (requested files). What I currently
> have is a protocol handler that extends IoHandlerAdapter. This class
> sets
> up a session filter using the following command:
>
> private static IoFilter CODEC_FILTER = new ProtocolCodecFilter(new
> TextLineCodecFactory());
> ...
> session.getFilterChain().addLast("codec", CODEC_FILTER);
>
> The problem is, how can I get my protocol handler to write a file back to
> the client? The only thing that I have found is to use a
> StreamIoHandler,
> but then I cannot figure out how to read the FTP commands.
>
> Thanks.
>
>
> On 8/20/06, peter royal <[EMAIL PROTECTED]> wrote:
>>
>> On Aug 17, 2006, at 11:47 PM, Mark wrote:
>> > Basically, by the time the FTP Server is done, I will have to
>> > support text
>> > and binary over the same connection, and support sessions. Trying
>> > to figure
>> > out what is the best I/O class for this.
>> >
>> > ideas??
>>
>> Sessions are the MINA IoSession.
>>
>> For text and binary.. There's probably some sort of state-machine on
>> the server side? Both are just bytes to MINA, really.
>>
>> -pete
>>
>>
>> --
>> [EMAIL PROTECTED] - http://fotap.org/~osi
>>
>>
>>
>>
>>
>>
>
--
Niklas Therning
www.spamdrain.net