Search in sources :

Example 6 with ByteBuffer

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);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) ByteBuffer(org.apache.mina.common.ByteBuffer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 7 with ByteBuffer

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]);
    }
}
Also used : ByteBuffer(org.apache.mina.common.ByteBuffer)

Example 8 with ByteBuffer

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
        }
    };
}
Also used : ProtocolEncoder(org.apache.mina.filter.codec.ProtocolEncoder) ByteBuffer(org.apache.mina.common.ByteBuffer) IoSession(org.apache.mina.common.IoSession) ProtocolEncoderOutput(org.apache.mina.filter.codec.ProtocolEncoderOutput)

Aggregations

ByteBuffer (org.apache.mina.common.ByteBuffer)8 Exchange (org.apache.camel.Exchange)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 InputStream (java.io.InputStream)1 Converter (org.apache.camel.Converter)1 IoSession (org.apache.mina.common.IoSession)1 ProtocolEncoder (org.apache.mina.filter.codec.ProtocolEncoder)1 ProtocolEncoderOutput (org.apache.mina.filter.codec.ProtocolEncoderOutput)1