Search in sources :

Example 1 with IoBuffer

use of org.apache.mina.core.buffer.IoBuffer in project camel by apache.

the class Mina2UdpProtocolCodecFactory method getEncoder.

public ProtocolEncoder getEncoder(IoSession session) throws Exception {
    return new ProtocolEncoder() {

        public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
            IoBuffer buf = toIoBuffer(message);
            buf.flip();
            out.write(buf);
        }

        public void dispose(IoSession session) throws Exception {
        // do nothing
        }
    };
}
Also used : ProtocolEncoder(org.apache.mina.filter.codec.ProtocolEncoder) IoSession(org.apache.mina.core.session.IoSession) ProtocolEncoderOutput(org.apache.mina.filter.codec.ProtocolEncoderOutput) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 2 with IoBuffer

use of org.apache.mina.core.buffer.IoBuffer in project camel by apache.

the class Mina2Converter method toIoBuffer.

@Converter
public static IoBuffer toIoBuffer(byte[] bytes) {
    IoBuffer buf = IoBuffer.allocate(bytes.length);
    buf.put(bytes);
    return buf;
}
Also used : IoBuffer(org.apache.mina.core.buffer.IoBuffer) Converter(org.apache.camel.Converter)

Example 3 with IoBuffer

use of org.apache.mina.core.buffer.IoBuffer in project camel by apache.

the class Mina2ConverterTest method testToStringTwoTimes.

public void testToStringTwoTimes() throws UnsupportedEncodingException {
    String in = "Hello World 你好";
    IoBuffer bb = IoBuffer.wrap(in.getBytes("UTF-8"));
    Exchange exchange = new DefaultExchange(new DefaultCamelContext());
    exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
    String out = Mina2Converter.toString(bb, exchange);
    assertEquals("Hello World 你好", out);
    // should NOT be possible to convert to string without affecting the ByteBuffer
    out = Mina2Converter.toString(bb, exchange);
    assertEquals("", out);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 4 with IoBuffer

use of org.apache.mina.core.buffer.IoBuffer in project camel by apache.

the class Mina2ConverterTest method testToInputStream.

public void testToInputStream() throws Exception {
    byte[] in = "Hello World".getBytes();
    IoBuffer bb = IoBuffer.wrap(in);
    InputStream is = Mina2Converter.toInputStream(bb);
    for (byte b : in) {
        int out = is.read();
        assertEquals(b, out);
    }
}
Also used : InputStream(java.io.InputStream) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 5 with IoBuffer

use of org.apache.mina.core.buffer.IoBuffer in project camel by apache.

the class Mina2ConverterTest method testToByteBuffer.

public void testToByteBuffer() {
    byte[] in = "Hello World".getBytes();
    IoBuffer bb = Mina2Converter.toIoBuffer(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 = Mina2Converter.toByteArray(bb);
    for (int i = 0; i < out.length; i++) {
        assertEquals(in[i], out[i]);
    }
}
Also used : IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Aggregations

IoBuffer (org.apache.mina.core.buffer.IoBuffer)49 Test (org.junit.Test)8 VideoData (org.red5.server.net.rtmp.event.VideoData)4 UnknownHostException (java.net.UnknownHostException)3 HashMap (java.util.HashMap)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 AudioData (org.red5.server.net.rtmp.event.AudioData)3 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 Exchange (org.apache.camel.Exchange)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 Message (ca.uhn.hl7v2.model.Message)1 AddressedEnvelope (io.netty.channel.AddressedEnvelope)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 DatagramPacket (io.netty.channel.socket.DatagramPacket)1