Le 5/13/13 9:27 PM, Jose María Zaragoza a écrit :
> Hello:
>
> I'm using Apache Mina 2.0.7
> I need to send a string to a peer
> This string can be encoded in any chatset ( by configuration ) and I need
> to send it in a buffered way ( I mean, store it in a buffer and flush it )
>
>
> I've got to implement it with BufferedWriterFilter and works fine , but I
> don't like to use an IoBuffer.
> Id like to manage String objects ( not IoBuffers , bytes , arrays , etc )
> But if I use BufferedWriterFilter , I need to pass it a IoBuffer
> And I need to execute flush()  in the filter when I write the string to the
> session
> IMHO, it's a mess for writing a simple string
>
> I can extend my own  BufferedWriterFilter and hide all these stuffs. And it
> could be fine ,
>  but I guess this case must be very usual , what is the best way to do it ?

You must use a codec to transform your String to a byte[]. You can use
the TextLinde codec in you chain :

        chain.addLast("codec", new ProtocolCodecFilter(
                new TextLineCodecFactory()));

This will allow you to do

session.write( "My String" )


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 

Reply via email to