Example usage for java.nio ByteBuffer equals

List of usage examples for java.nio ByteBuffer equals

Introduction

In this page you can find the example usage for java.nio ByteBuffer equals.

Prototype

public boolean equals(Object other) 

Source Link

Document

Checks whether this byte buffer is equal to another object.

Usage

From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.TestContainerManager.java

private void assertSecurityMaterial(File materialFile, ByteBuffer expected, boolean assertEquals)
        throws IOException {
    ByteBuffer fromFile = readFileToByteBuffer(materialFile);
    if (assertEquals) {
        assertTrue(expected.equals(fromFile));
    } else {//from   w w w  .  ja v a 2  s.c om
        assertFalse(expected.equals(fromFile));
    }
}

From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.TestContainerManager.java

private void assertUpdatedCryptoMaterial(File[] cryptoMaterialFiles, ByteBuffer oldKeyStore,
        ByteBuffer newKeyStore, ByteBuffer oldTrustStore, ByteBuffer newTrustStore, String oldPassword,
        String newPassword) throws IOException {
    ByteBuffer newKeyStoreBB = readFileToByteBuffer(cryptoMaterialFiles[0]);
    assertFalse(oldKeyStore.equals(newKeyStoreBB));
    assertTrue(newKeyStore.equals(newKeyStoreBB));

    ByteBuffer newTrustStoreBB = readFileToByteBuffer(cryptoMaterialFiles[1]);
    assertFalse(oldTrustStore.equals(newTrustStoreBB));
    assertTrue(newTrustStore.equals(newTrustStoreBB));

    String newPasswordU = FileUtils.readFileToString(cryptoMaterialFiles[2]);
    assertNotEquals(oldPassword, newPasswordU);
    assertEquals(newPassword, newPasswordU);
}

From source file:org.apache.usergrid.security.tokens.cassandra.TokenServiceImpl.java

private UUID getUUIDForToken(String token) throws ExpiredTokenException, BadTokenException {
    TokenCategory tokenCategory = TokenCategory.getFromBase64String(token);
    byte[] bytes = decodeBase64(token.substring(TokenCategory.BASE64_PREFIX_LENGTH));
    UUID uuid = uuid(bytes);/*w  w w.  j a  v a  2  s . c o  m*/
    int i = 16;
    long expires = Long.MAX_VALUE;
    if (tokenCategory.getExpires()) {
        expires = ByteBuffer.wrap(bytes, i, 8).getLong();
        i = 24;
    }
    ByteBuffer expected = ByteBuffer.allocate(20);
    expected.put(sha(tokenCategory.getPrefix() + uuid + tokenSecretSalt + expires));
    expected.rewind();
    ByteBuffer signature = ByteBuffer.wrap(bytes, i, 20);

    if (!signature.equals(expected)) {
        throw new BadTokenException("Invalid token signature");
    }

    long expirationDelta = System.currentTimeMillis() - expires;

    if (expires != Long.MAX_VALUE && expirationDelta > 0) {
        throw new ExpiredTokenException(String.format("Token expired %d millisecons ago.", expirationDelta));
    }
    return uuid;
}

From source file:org.bytesoft.bytetcc.work.CleanupWork.java

private int invokeCompress() throws RuntimeException {
    ByteBuffer current = ByteBuffer.allocate(CONSTANTS_RECORD_SIZE + 1);
    ByteBuffer previou = ByteBuffer.allocate(CONSTANTS_RECORD_SIZE + 1);
    int position = CONSTANTS_START_INDEX;
    for (int index = CONSTANTS_START_INDEX; index < this.endIndex; index += CONSTANTS_RECORD_SIZE + 1) {
        try {/* w  w w. j av a 2 s . c  o  m*/
            this.lock.lock();

            this.channel.position(index);
            this.channel.read(current);
            current.flip();
            boolean enabled = 0x1 == current.get();
            if (enabled) {
                if (index != position) {
                    if (previou.equals(current) == false) {
                        previou.put((byte) 0x1);
                        previou.put(current);

                        previou.flip();
                        current.flip();

                        this.channel.position(position);
                        this.channel.write(current);

                        previou.flip();
                        current.clear();
                    }

                    this.channel.position(index);
                    ByteBuffer buffer = ByteBuffer.allocate(1);
                    buffer.put((byte) 0x0);
                    this.channel.write(buffer);
                }
                position = index + CONSTANTS_RECORD_SIZE + 1;
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } finally {
            this.lock.unlock();

            previou.flip();
            current.clear();
        }
    }

    return position;
}

From source file:org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart.java

public boolean isContentEqual(Part other) throws Docx4JException {

    if (!(other instanceof BinaryPart))
        return false;

    ByteBuffer thisBB = getBuffer();
    ByteBuffer thatBB = ((BinaryPart) other).getBuffer();

    return thisBB.equals(thatBB);

    //        if (m_ContentType != arg.m_ContentType)
    //            return false;

    //        if (m_Image.GetLongLength(0) != arg.m_Image.GetLongLength(0))
    //            return false;
    //        /*w  ww .ja  v a 2  s .c  o  m*/
    //        // Compare the arrays byte by byte
    //        long length = m_Image.GetLongLength(0);
    //        for (long n = 0; n < length; n++)
    //            if (m_Image[n] != arg.m_Image[n])
    //                return false;
    //        return true;

}

From source file:org.lealone.cluster.utils.ByteBufferUtil.java

public static boolean isPrefix(ByteBuffer prefix, ByteBuffer value) {
    if (prefix.remaining() > value.remaining())
        return false;

    int diff = value.remaining() - prefix.remaining();
    return prefix.equals(value.duplicate().limit(value.remaining() - diff));
}

From source file:org.openspaces.persistency.cassandra.HectorCassandraClient.java

private ColumnDefinition getColumnDefinition(ByteBuffer serializedColumnName, ThriftCfDef thriftCfDef) {
    for (ColumnDefinition columnDef : thriftCfDef.getColumnMetadata()) {
        if (serializedColumnName.equals(columnDef.getName())) {
            return columnDef;
        }// w ww  .j a v  a 2  s.c  o m
    }
    return null;
}