Example usage for io.netty.buffer ByteBufUtil hexDump

List of usage examples for io.netty.buffer ByteBufUtil hexDump

Introduction

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

Prototype

public static String hexDump(byte[] array, int fromIndex, int length) 

Source Link

Document

Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a> of the specified byte array's sub-region.

Usage

From source file:io.reactivesocket.FrameTest.java

License:Apache License

@Test
@Theory//from ww  w.ja va 2s.  c o m
public void shouldFormCorrectlyWithoutDataNorMetadataForSetup(final int offset) {
    final int flags = SetupFrameFlyweight.FLAGS_WILL_HONOR_LEASE
            | SetupFrameFlyweight.FLAGS_STRICT_INTERPRETATION;
    final int version = SetupFrameFlyweight.CURRENT_VERSION;
    final int keepaliveInterval = 1001;
    final int maxLifetime = keepaliveInterval * 5;
    final String metadataMimeType = "application/json";
    final String dataMimeType = "application/cbor";

    Frame encodedFrame = Frame.Setup.from(flags, keepaliveInterval, maxLifetime, metadataMimeType, dataMimeType,
            new Payload() {
                public ByteBuffer getData() {
                    return Frame.NULL_BYTEBUFFER;
                }

                public ByteBuffer getMetadata() {
                    return Frame.NULL_BYTEBUFFER;
                }
            });
    TestUtil.copyFrame(reusableMutableDirectBuffer, offset, encodedFrame);
    reusableFrame.wrap(reusableMutableDirectBuffer, offset);

    assertEquals(FrameType.SETUP, reusableFrame.getType());
    assertEquals(flags, Frame.Setup.getFlags(reusableFrame));
    assertEquals(version, Frame.Setup.version(reusableFrame));
    assertEquals(keepaliveInterval, Frame.Setup.keepaliveInterval(reusableFrame));
    assertEquals(maxLifetime, Frame.Setup.maxLifetime(reusableFrame));
    assertEquals(metadataMimeType, Frame.Setup.metadataMimeType(reusableFrame));
    assertEquals(dataMimeType, Frame.Setup.dataMimeType(reusableFrame));
    assertEquals(Frame.NULL_BYTEBUFFER, reusableFrame.getData());
    assertEquals(Frame.NULL_BYTEBUFFER, reusableFrame.getMetadata());

    assertEquals("0000003a000130000000000000000000000003e90000138d",
            ByteBufUtil.hexDump(encodedFrame.getByteBuffer().array(), 0, 24));
}

From source file:io.reactivesocket.FrameTest.java

License:Apache License

@Test
@Theory/*from   w w w.  jav  a  2 s.  c om*/
public void shouldReturnCorrectDataPlusMetadataForError(final int offset) {
    final int streamId = 24;
    final Throwable exception = new RejectedException("test");
    final String data = "error data";
    final String metadata = "error metadata";
    final ByteBuffer dataByteBuffer = ByteBuffer.wrap(data.getBytes(UTF_8));
    final ByteBuffer metadataByteBuffer = ByteBuffer.wrap(metadata.getBytes(UTF_8));

    Frame encodedFrame = Frame.Error.from(streamId, exception, metadataByteBuffer, dataByteBuffer);
    TestUtil.copyFrame(reusableMutableDirectBuffer, offset, encodedFrame);
    reusableFrame.wrap(reusableMutableDirectBuffer, offset);

    assertEquals(FrameType.ERROR, reusableFrame.getType());
    assertEquals(REJECTED, Frame.Error.errorCode(reusableFrame));
    assertEquals(data, TestUtil.byteToString(reusableFrame.getData()));
    assertEquals(metadata, TestUtil.byteToString(reusableFrame.getMetadata()));

    assertEquals("0000002c000c40000000001800000202",
            ByteBufUtil.hexDump(encodedFrame.getByteBuffer().array(), 0, 16));
}

From source file:io.reactivesocket.FrameTest.java

License:Apache License

@Test
@Theory//from  w  w w .j  av a 2 s.c o m
public void shouldFormCorrectlyForRequestN(final int offset) {
    final int n = 128;
    final Frame encodedFrame = Frame.RequestN.from(1, n);
    TestUtil.copyFrame(reusableMutableDirectBuffer, offset, encodedFrame);
    reusableFrame.wrap(reusableMutableDirectBuffer, offset);

    assertEquals(FrameType.REQUEST_N, reusableFrame.getType());
    assertEquals(n, Frame.RequestN.requestN(reusableFrame));
    assertEquals(Frame.NULL_BYTEBUFFER, reusableFrame.getData());
    assertEquals(Frame.NULL_BYTEBUFFER, reusableFrame.getMetadata());

    assertEquals("00000010000900000000000100000080",
            ByteBufUtil.hexDump(encodedFrame.getByteBuffer().array(), 0, 16));
}

From source file:io.reactivesocket.FrameTest.java

License:Apache License

@Test
@Theory/*from  w w w. j  a va 2 s  .  co m*/
public void shouldFormCorrectlyWithoutMetadataForLease(final int offset) {
    final int ttl = (int) TimeUnit.SECONDS.toMillis(8);
    final int numberOfRequests = 16;
    final Frame encodedFrame = Frame.Lease.from(ttl, numberOfRequests, Frame.NULL_BYTEBUFFER);
    TestUtil.copyFrame(reusableMutableDirectBuffer, offset, encodedFrame);
    reusableFrame.wrap(reusableMutableDirectBuffer, offset);

    assertEquals(0, reusableFrame.getStreamId());
    assertEquals(FrameType.LEASE, reusableFrame.getType());
    assertEquals(ttl, Frame.Lease.ttl(reusableFrame));
    assertEquals(numberOfRequests, Frame.Lease.numberOfRequests(reusableFrame));
    assertEquals(Frame.NULL_BYTEBUFFER, reusableFrame.getData());
    assertEquals(Frame.NULL_BYTEBUFFER, reusableFrame.getMetadata());

    assertEquals("00000014000200000000000000001f4000000010",
            ByteBufUtil.hexDump(encodedFrame.getByteBuffer().array(), 0, 20));
}

From source file:org.eclipse.scada.protocol.relp.FrameCodec.java

License:Open Source License

private void processTRAILER(final ChannelHandlerContext ctx, final byte b, final ByteBuf msg) {
    if (b != Constants.LF) {
        throw new CodecException(
                String.format("Expected trailer byte (LF) but found 0x%02X: Remaining buffer: %s", b,
                        ByteBufUtil.hexDump(msg, msg.readerIndex(), msg.readableBytes())));
    }//from w  w w .  j  a  va 2  s  . c  om

    final int length = ctx.attr(ATTR_EXPECTED_LENGTH).get();
    final long txnr = Long.parseLong(ctx.attr(ATTR_TXNR_BUFFER).get().toString(TXNR_CHARSET));
    final String command = ctx.attr(ATTR_COMMAND_BUFFER).get().toString(COMMAND_CHARSET);
    final ByteBuf data = ctx.attr(ATTR_DATA_BUFFER).get().readSlice(length);

    final Frame frame = new Frame(txnr, command, data);

    ctx.fireChannelRead(frame);

    ctx.attr(ATTR_STATE).set(State.TXNR);
    ctx.attr(ATTR_TXNR_BUFFER).get().clear();
    ctx.attr(ATTR_COMMAND_BUFFER).get().clear();
    ctx.attr(ATTR_LENGTH_BUFFER).get().clear();
    ctx.attr(ATTR_DATA_BUFFER).get().clear();
}

From source file:org.graylog2.inputs.codecs.gelf.GELFMessageChunk.java

License:Open Source License

private void extractId() {
    if (this.id == null) {
        this.id = ByteBufUtil.hexDump(payload, HEADER_PART_HASH_START, HEADER_PART_HASH_LENGTH);
    }//from www .  ja v a2  s.com
}

From source file:org.traccar.protocol.AplicomProtocolDecoder.java

License:Apache License

private void decodeEventData(Position position, ByteBuf buf, int event) {
    switch (event) {
    case 2:/*  ww w . j  ava 2s .  c om*/
    case 40:
        buf.readUnsignedByte();
        break;
    case 9:
        buf.readUnsignedMedium();
        break;
    case 31:
    case 32:
        buf.readUnsignedShort();
        break;
    case 38:
        buf.skipBytes(4 * 9);
        break;
    case 113:
        buf.readUnsignedInt();
        buf.readUnsignedByte();
        break;
    case 119:
        position.set("eventData",
                ByteBufUtil.hexDump(buf, buf.readerIndex(), Math.min(buf.readableBytes(), 1024)));
        break;
    case 121:
    case 142:
        buf.readLong();
        break;
    case 130:
        buf.readUnsignedInt(); // incorrect
        break;
    case 188:
        decodeEB(position, buf);
        break;
    default:
        break;
    }
}