Example usage for io.netty.buffer ByteBufUtil compare

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

Introduction

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

Prototype

public static int compare(ByteBuf bufferA, ByteBuf bufferB) 

Source Link

Document

Compares the two specified buffers as described in ByteBuf#compareTo(ByteBuf) .

Usage

From source file:com.addthis.basis.chars.ReadOnlyUtfBuf.java

License:Apache License

@Override
public int compareTo(ReadableCharBuf o) {
    if (o instanceof ReadOnlyUtfBuf) {
        return ByteBufUtil.compare(((ReadOnlyUtfBuf) o).content(), content());
    } else {//from w  ww  . j  a  v a 2s  .  c o m
        return super.compareTo(o);
    }
}

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

License:Apache License

@Override
public int compareTo(ByteBuf that) {
    return ByteBufUtil.compare(this, that);
}

From source file:org.apache.bookkeeper.bookie.IndexPersistenceMgrTest.java

License:Apache License

void validateFileInfo(IndexPersistenceMgr indexPersistenceMgr, long ledgerId, int headerVersion)
        throws IOException, GeneralSecurityException {
    BookKeeper.DigestType digestType = BookKeeper.DigestType.CRC32;
    boolean getUseV2WireProtocol = true;

    preCreateFileInfoForLedger(ledgerId, headerVersion);
    DigestManager digestManager = DigestManager.instantiate(ledgerId, masterKey,
            BookKeeper.DigestType.toProtoDigestType(digestType), UnpooledByteBufAllocator.DEFAULT,
            getUseV2WireProtocol);/* w w  w .  j  a  v a 2  s. co  m*/

    CachedFileInfo fileInfo = indexPersistenceMgr.getFileInfo(ledgerId, masterKey);
    fileInfo.readHeader();
    assertEquals("ExplicitLac should be null", null, fileInfo.getExplicitLac());
    assertEquals("Header Version should match with precreated fileinfos headerversion", headerVersion,
            fileInfo.headerVersion);
    assertTrue("Masterkey should match with precreated fileinfos masterkey",
            Arrays.equals(masterKey, fileInfo.masterKey));
    long explicitLac = 22;
    ByteBuf explicitLacByteBuf = digestManager.computeDigestAndPackageForSendingLac(explicitLac).getBuffer(0);
    explicitLacByteBuf.markReaderIndex();
    indexPersistenceMgr.setExplicitLac(ledgerId, explicitLacByteBuf);
    explicitLacByteBuf.resetReaderIndex();
    assertEquals("explicitLac ByteBuf contents should match", 0,
            ByteBufUtil.compare(explicitLacByteBuf, indexPersistenceMgr.getExplicitLac(ledgerId)));
    /*
     * release fileInfo untill it is marked dead and closed, so that
     * contents of it are persisted.
     */
    while (fileInfo.refCount.get() != FileInfoBackingCache.DEAD_REF) {
        fileInfo.release();
    }
    /*
     * reopen the fileinfo and readHeader, so that whatever was persisted
     * would be read.
     */
    fileInfo = indexPersistenceMgr.getFileInfo(ledgerId, masterKey);
    fileInfo.readHeader();
    assertEquals("Header Version should match with precreated fileinfos headerversion even after reopening",
            headerVersion, fileInfo.headerVersion);
    assertTrue("Masterkey should match with precreated fileinfos masterkey",
            Arrays.equals(masterKey, fileInfo.masterKey));
    if (headerVersion == FileInfo.V0) {
        assertEquals(
                "Since it is V0 Header, explicitLac will not be persisted and should be null after reopening",
                null, indexPersistenceMgr.getExplicitLac(ledgerId));
    } else {
        explicitLacByteBuf.resetReaderIndex();
        assertEquals(
                "Since it is V1 Header, explicitLac will be persisted and should not be null after reopening",
                0, ByteBufUtil.compare(explicitLacByteBuf, indexPersistenceMgr.getExplicitLac(ledgerId)));
    }
}