Example usage for io.netty.buffer Unpooled buffer

List of usage examples for io.netty.buffer Unpooled buffer

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled buffer.

Prototype

public static ByteBuf buffer(int initialCapacity) 

Source Link

Document

Creates a new big-endian Java heap buffer with the specified capacity , which expands its capacity boundlessly on demand.

Usage

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testConackCodeNull() throws UnsupportedEncodingException, MalformedMessageException {
    expectedEx.expect(MalformedMessageException.class);
    ByteBuf buf = Unpooled.buffer(3);
    buf.writeByte(0x20);//from ww  w  . jav  a2s .c o m
    buf.writeByte(2);
    buf.writeByte(0);
    buf.writeByte(6);
    MQParser.decode(buf);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testSubackCodeNull() throws UnsupportedEncodingException, MalformedMessageException {
    expectedEx.expect(MalformedMessageException.class);
    ByteBuf buf = Unpooled.buffer(3);
    buf.writeByte(0x90);// ww w  .  ja  v  a2 s. co m
    buf.writeByte(3);
    buf.writeShort(10);
    buf.writeByte(3);
    MQParser.decode(buf);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testDecodeLengthOne() {
    ByteBuf buf = Unpooled.buffer(114);
    buf.writeByte(0x82);/* ww  w .ja  v  a  2  s. co  m*/
    buf.writeByte(0x66);
    buf.writeShort(10);
    buf.writeShort(97);
    buf.writeBytes(new byte[96]);
    buf.writeByte(1);
    buf.writeByte(0);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testDecodeLengthTwo() {
    ByteBuf buf = Unpooled.buffer(205);
    buf.writeByte(0x82);/*w w  w.  j  a v a  2 s.  c  o m*/
    buf.writeByte(0xCA);
    buf.writeByte(0x01);
    buf.writeShort(10);
    buf.writeShort(197);
    buf.writeBytes(new byte[196]);
    buf.writeByte(1);
    buf.writeByte(0);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testDecodeLengthThree() {
    ByteBuf buf = Unpooled.buffer(20206);
    buf.writeByte(0x82);//from   ww  w  . j  a v  a2  s  .co m
    buf.writeByte(0xEA);
    buf.writeByte(0x9D);
    buf.writeByte(0x01);
    buf.writeShort(10);
    buf.writeShort(20197);
    buf.writeBytes(new byte[20196]);
    buf.writeByte(1);
    buf.writeByte(0);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testDecodeLengthFour() {
    ByteBuf buf = Unpooled.buffer(2097159);
    buf.writeByte(0x82);/*from w  ww .j av a2s  . c  o  m*/
    buf.writeByte(0x82);
    buf.writeByte(0x80);
    buf.writeByte(0x80);
    buf.writeByte(0x01);
    buf.writeShort(10);
    for (int i = 0; i < 32; i++) {
        buf.writeShort(65533);
        buf.writeBytes(new byte[65532]);
        buf.writeByte(1);
        buf.writeByte(0);
    }
}

From source file:com.mobius.software.mqtt.parser.test.TestPublish.java

License:Open Source License

@Before
public void setUp() {
    byte[] data = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64 };
    ByteBuf content = Unpooled.buffer(data.length).writeBytes(data);
    expected = new Publish(100, new Topic(new Text("new_topic"), QoS.EXACTLY_ONCE), content, true, true);
}

From source file:com.mobius.software.mqtt.parser.test.TestPublish.java

License:Open Source License

@Test
public void testEncodeLength() {
    Publish actual = new Publish(expected.getPacketID(),
            new Topic(new Text("name"), expected.getTopic().getQos()),
            Unpooled.buffer(121).writeBytes(new byte[121]), expected.isRetain(), expected.isDup());
    assertEquals("invalid header length", 129, actual.getLength());
    actual = new Publish(expected.getPacketID(), new Topic(new Text("name"), expected.getTopic().getQos()),
            Unpooled.buffer(122).writeBytes(new byte[122]), expected.isRetain(), expected.isDup());
    assertEquals("invalid header length", actual.getLength(), 130);
    actual = new Publish(expected.getPacketID(), new Topic(new Text("name"), expected.getTopic().getQos()),
            Unpooled.buffer(16378).writeBytes(new byte[16378]), expected.isRetain(), expected.isDup());
    assertEquals("invalid header length", actual.getLength(), 16386);
    actual = new Publish(expected.getPacketID(), new Topic(new Text("name"), expected.getTopic().getQos()),
            Unpooled.buffer(2097146).writeBytes(new byte[2097146]), expected.isRetain(), expected.isDup());
    assertEquals("invalid header length", actual.getLength(), 2097154);
}

From source file:com.mobius.software.mqtt.performance.commons.util.MessageGenerator.java

License:Open Source License

public static ByteBuf generateContent(int messageSize) {
    char[] text = new char[messageSize];
    for (int i = 0; i < messageSize; i++)
        text[i] = CHARACTERS.charAt(random.nextInt(CHARACTERS.length()));
    return Unpooled.buffer(text.length).writeBytes(new String(text).getBytes());
}

From source file:com.mpush.api.protocol.Packet.java

License:Apache License

public byte calcLrc() {
    byte[] data = Unpooled.buffer(HEADER_LEN - 1).writeInt(getBodyLength()).writeByte(cmd).writeShort(cc)
            .writeByte(flags).writeInt(sessionId).array();
    byte lrc = 0;
    for (int i = 0; i < data.length; i++) {
        lrc ^= data[i];/*  w  ww .ja  va2s  . c o m*/
    }
    return lrc;
}