use of org.apache.mina.common.ByteBuffer in project camel by apache.
the class MinaConverterTest method testToString.
public void testToString() throws UnsupportedEncodingException {
String in = "Hello World 你好";
ByteBuffer bb = ByteBuffer.wrap(in.getBytes("UTF-8"));
Exchange exchange = new DefaultExchange(new DefaultCamelContext());
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
String out = MinaConverter.toString(bb, exchange);
assertEquals("Hello World 你好", out);
}
use of org.apache.mina.common.ByteBuffer in project camel by apache.
the class MinaConverterTest method testToByteBuffer.
public void testToByteBuffer() {
byte[] in = "Hello World".getBytes();
ByteBuffer bb = MinaConverter.toByteBuffer(in);
assertNotNull(bb);
// convert back to byte[] and see if the bytes are equal
// must flip to change direction to read
bb.flip();
byte[] out = MinaConverter.toByteArray(bb);
for (int i = 0; i < out.length; i++) {
assertEquals(in[i], out[i]);
}
}
use of org.apache.mina.common.ByteBuffer in project camel by apache.
the class MinaUdpProtocolCodecFactory method getEncoder.
public ProtocolEncoder getEncoder() throws Exception {
return new ProtocolEncoder() {
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
ByteBuffer buf = toByteBuffer(message);
buf.flip();
out.write(buf);
}
public void dispose(IoSession session) throws Exception {
// do nothing
}
};
}
Aggregations