Example usage for io.netty.buffer ByteBufUtil equals

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

Introduction

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

Prototype

public static boolean equals(ByteBuf bufferA, ByteBuf bufferB) 

Source Link

Document

Returns true if and only if the two specified buffers are identical to each other as described in ByteBuf#equals(Object) .

Usage

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

License:Open Source License

@Test
public void testNegativeByteContent() throws UnsupportedEncodingException, MalformedMessageException {
    Suback actual = (Suback) MQParser.decode(MQParser.encode(expected));
    actual.setPacketID(1000);//from  ww w.jav a  2s.  c o  m
    assertFalse("Invalid binary content",
            ByteBufUtil.equals(MQParser.encode(expected), MQParser.encode(actual)));
}

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

License:Open Source License

@Test
public void testPositiveByteContent() throws UnsupportedEncodingException, MalformedMessageException {
    Unsuback actual = (Unsuback) MQParser.decode(MQParser.encode(expected));
    assertTrue("Invalid binary content",
            ByteBufUtil.equals(MQParser.encode(expected), MQParser.encode(actual)));
}

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

License:Open Source License

@Test
public void testNegativeByteContent() throws UnsupportedEncodingException, MalformedMessageException {
    Unsuback actual = (Unsuback) MQParser.decode(MQParser.encode(expected));
    actual.setPacketID(1000); // mismatch
    assertFalse("Invalid binary content",
            ByteBufUtil.equals(MQParser.encode(expected), MQParser.encode(actual)));
}

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

License:Open Source License

@Test
public void testPositiveByteContent() throws UnsupportedEncodingException, MalformedMessageException {
    Unsubscribe actual = (Unsubscribe) MQParser.decode(MQParser.encode(expected));
    assertTrue("Invalid binary content",
            ByteBufUtil.equals(MQParser.encode(expected), MQParser.encode(actual)));
}

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

License:Open Source License

@Test
public void testNegativeByteContent() throws UnsupportedEncodingException, MalformedMessageException {
    Unsubscribe actual = (Unsubscribe) MQParser.decode(MQParser.encode(expected));
    actual.setPacketID(1000);//www. java2 s.c  o  m
    assertFalse("Invalid binary content",
            ByteBufUtil.equals(MQParser.encode(expected), MQParser.encode(actual)));
}

From source file:net.tomp2p.storage.AlternativeCompositeByteBuf.java

License:Apache License

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//w  ww .j  a  v  a  2  s. c  om
    if (o instanceof ByteBuf) {
        return ByteBufUtil.equals(this, (ByteBuf) o);
    }
    return false;
}

From source file:org.apache.tajo.rpc.MonitorClientHandler.java

License:Apache License

private boolean isPing(Object msg) {
    if (msg instanceof ByteBuf) {
        return ByteBufUtil.equals(ping.duplicate(), ((ByteBuf) msg).duplicate());
    }//from ww w .  j  ava  2 s  .c  o  m
    return false;
}

From source file:org.apache.tajo.rpc.MonitorServerHandler.java

License:Apache License

private boolean isPing(Object msg) {
    if (msg instanceof ByteBuf) {
        return ByteBufUtil.equals(ping.duplicate(), ((ByteBuf) msg).duplicate());
    }//w  w  w.  ja  v  a  2  s. c o m

    return false;
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private ByteBuf deserialize(ImmutableList<Cookie> sessionCookies) throws Exception {
    if (sessionCookies.isEmpty()) {
        return Unpooled.EMPTY_BUFFER;
    }/*w w w  .j  av a 2 s .c o m*/

    StringBuilder sessionCookie = new StringBuilder();
    for (Cookie cookie : sessionCookies) {
        sessionCookie.append(cookie.value());
    }
    String[] parts = sessionCookie.toString().split(SESSION_SEPARATOR);
    if (parts.length != 2) {
        return Unpooled.buffer(0, 0);
    }
    ByteBuf payload = null;
    ByteBuf digest = null;
    ByteBuf expectedDigest = null;
    ByteBuf decryptedPayload = null;
    try {
        payload = fromBase64(bufferAllocator, parts[0]);
        digest = fromBase64(bufferAllocator, parts[1]);
        expectedDigest = signer.sign(payload, bufferAllocator);
        if (ByteBufUtil.equals(digest, expectedDigest)) {
            decryptedPayload = crypto.decrypt(payload.resetReaderIndex(), bufferAllocator);
        } else {
            decryptedPayload = Unpooled.buffer(0, 0);
        }
    } finally {
        if (payload != null) {
            payload.touch().release();
        }
        if (digest != null) {
            digest.release();
        }
        if (expectedDigest != null) {
            expectedDigest.release();
        }
    }
    return decryptedPayload.touch();
}