You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Jose María Zaragoza <de...@gmail.com> on 2013/05/13 21:27:13 UTC
BufferedWriterFilter + string encoded
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 ?
Thanks and regards
Re: BufferedWriterFilter + string encoded
Posted by Jose María Zaragoza <de...@gmail.com>.
Thanks.
Yes, I had to set
this.connector.getFilterChain().addLast("buffer", buffer);
this.connector.getFilterChain().addLast("codec", new
ProtocolCodecFilter(new
TextCodecFactory(Charset.forName(configuration.getEncoding()))));
But , as you can see, I had to create a new TextCodecFactory because I
don't want to send my messages with a delimiter
But, with this filter chain, I already need to flush the buffer object
after writing, with the command
this.buffer.flush(this.session);
All this works fine, I only asked for the best way to do it, because it's
usual to perform
- fill a buffer with String bytes ( and encoded it)
- send them
I could have made a only one filter with this feature, but I asked if it
was made
Regards
2013/5/15 Emmanuel Lécharny <el...@gmail.com>
> 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
>
>
Re: BufferedWriterFilter + string encoded
Posted by Emmanuel Lécharny <el...@gmail.com>.
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