Java Code Examples for java.nio.ByteBuffer#equals()

The following examples show how to use java.nio.ByteBuffer#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpAssertions.java    From swim with Apache License 2.0 6 votes vote down vote up
public static void assertEncodes(Encoder<?, ?> part, ByteBuffer expected) {
  final ByteBuffer actual = ByteBuffer.allocate(expected.remaining() + 48);
  final OutputBuffer<?> output = Binary.outputBuffer(actual).isPart(true);
  Encoder<?, ?> encoder = part;
  assertTrue(encoder.isCont());
  assertFalse(encoder.isError());
  assertFalse(encoder.isDone());
  while (encoder.isCont()) {
    encoder = encoder.pull(output);
  }
  if (encoder.isError()) {
    throw new TestException(encoder.trap());
  }
  assertFalse(encoder.isCont());
  assertTrue(encoder.isDone());
  actual.flip();
  if (!actual.equals(expected)) {
    final Output<String> message = Unicode.stringOutput();
    message.write("expected ")
        .debug(new String(expected.array(), expected.arrayOffset(), expected.remaining()))
        .write(" but found ")
        .debug(new String(actual.array(), actual.arrayOffset(), actual.remaining()));
    fail(message.toString());
  }
}
 
Example 2
Source File: ParseFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Takes a compareOperator symbol as a byte array and returns the corresponding CompareOperator
 * @param compareOpAsByteArray the comparatorOperator symbol as a byte array
 * @return the Compare Operator
 */
public static CompareOperator createCompareOperator (byte [] compareOpAsByteArray) {
  ByteBuffer compareOp = ByteBuffer.wrap(compareOpAsByteArray);
  if (compareOp.equals(ParseConstants.LESS_THAN_BUFFER))
    return CompareOperator.LESS;
  else if (compareOp.equals(ParseConstants.LESS_THAN_OR_EQUAL_TO_BUFFER))
    return CompareOperator.LESS_OR_EQUAL;
  else if (compareOp.equals(ParseConstants.GREATER_THAN_BUFFER))
    return CompareOperator.GREATER;
  else if (compareOp.equals(ParseConstants.GREATER_THAN_OR_EQUAL_TO_BUFFER))
    return CompareOperator.GREATER_OR_EQUAL;
  else if (compareOp.equals(ParseConstants.NOT_EQUAL_TO_BUFFER))
    return CompareOperator.NOT_EQUAL;
  else if (compareOp.equals(ParseConstants.EQUAL_TO_BUFFER))
    return CompareOperator.EQUAL;
  else
    throw new IllegalArgumentException("Invalid compare operator");
}
 
Example 3
Source File: Basic.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testUsingCompletionHandlers(AsynchronousFileChannel ch)
    throws IOException
{
    System.out.println("testUsingCompletionHandlers");

    ch.truncate(0L);

    // generate buffer with random elements and write it to file
    ByteBuffer src = genBuffer();
    writeFully(ch, src, 0L);

    // read to EOF or buffer is full
    ByteBuffer dst = (rand.nextBoolean()) ?
        ByteBuffer.allocateDirect(src.capacity()) :
        ByteBuffer.allocate(src.capacity());
    readAll(ch, dst, 0L);

    // check buffers are the same
    src.flip();
    dst.flip();
    if (!src.equals(dst)) {
        throw new RuntimeException("Contents differ");
    }
}
 
Example 4
Source File: CassandraServer.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private List<ColumnOrSuperColumn> thriftifySuperColumns(Collection<Cell> cells, boolean reverseOrder, long now)
{
    ArrayList<ColumnOrSuperColumn> thriftSuperColumns = new ArrayList<ColumnOrSuperColumn>(cells.size());
    SuperColumn current = null;
    for (Cell cell : cells)
    {
        if (!cell.isLive(now))
            continue;

        ByteBuffer scName = SuperColumns.scName(cell.name());
        if (current == null || !scName.equals(current.bufferForName()))
        {
            current = new SuperColumn(scName, new ArrayList<Column>());
            thriftSuperColumns.add(new ColumnOrSuperColumn().setSuper_column(current));
        }
        current.getColumns().add(thriftifySubColumn(cell).setName(SuperColumns.subName(cell.name())));
    }

    if (reverseOrder)
        Collections.reverse(thriftSuperColumns);

    return thriftSuperColumns;
}
 
Example 5
Source File: TestTLS12.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTransfer(ByteBuffer a, ByteBuffer b)
        throws Exception {
    a.flip();
    b.flip();
    if (!a.equals(b)) {
        throw new Exception("Data didn't transfer cleanly");
    }
    a.position(a.limit());
    b.position(b.limit());
    a.limit(a.capacity());
    b.limit(b.capacity());
}
 
Example 6
Source File: SameBuffer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void runGCMWithSameBuffer(int mode, ByteBuffer buffer,
        int txtOffset, int length, AlgorithmParameters params)
        throws Exception {

    // allocate a separate buffer
    Cipher cipher = createCipher(mode, params);
    ByteBuffer outBB = ByteBuffer.allocateDirect(
            cipher.getOutputSize(length));

    // first, generate the cipher text at an allocated buffer
    buffer.flip();
    buffer.limit(AADLength);
    cipher.updateAAD(buffer);
    buffer.limit(AADLength + txtOffset + length);
    buffer.position(AADLength + txtOffset);
    cipher.doFinal(buffer, outBB);
    outBB.flip(); // cipher text in outBB

    // next, generate cipherText again in the same buffer
    Cipher anotherCipher = createCipher(mode, params);
    buffer.flip();
    buffer.limit(AADLength);
    anotherCipher.updateAAD(buffer);
    buffer.limit(AADLength + txtOffset + length);
    buffer.position(AADLength + txtOffset);

    // share textBuf context
    ByteBuffer buf2 = buffer.duplicate();
    buf2.limit(AADLength + txtOffset + anotherCipher.getOutputSize(length));
    int dataProcessed2 = anotherCipher.doFinal(buffer, buf2);
    buf2.position(AADLength + txtOffset);
    buf2.limit(AADLength + txtOffset + dataProcessed2);

    if (!buf2.equals(outBB)) {
        throw new RuntimeException(
                "Two results are not equal, mode:" + mode);
    }
}
 
Example 7
Source File: TestOfflineEditsViewer.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Compare two files, ignore trailing zeros at the end,
 * for edits log the trailing zeros do not make any difference,
 * throw exception is the files are not same
 *
 * @param filenameSmall first file to compare (doesn't have to be smaller)
 * @param filenameLarge second file to compare (doesn't have to be larger)
 */
private boolean filesEqualIgnoreTrailingZeros(String filenameSmall,
  String filenameLarge) throws IOException {

  ByteBuffer small = ByteBuffer.wrap(DFSTestUtil.loadFile(filenameSmall));
  ByteBuffer large = ByteBuffer.wrap(DFSTestUtil.loadFile(filenameLarge));

  // now correct if it's otherwise
  if(small.capacity() > large.capacity()) {
    ByteBuffer tmpByteBuffer = small;
    small = large;
    large = tmpByteBuffer;
    String tmpFilename = filenameSmall;
    filenameSmall = filenameLarge;
    filenameLarge = tmpFilename;
  }

  // compare from 0 to capacity of small
  // the rest of the large should be all zeros
  small.position(0);
  small.limit(small.capacity());
  large.position(0);
  large.limit(small.capacity());

  // compares position to limit
  if(!small.equals(large)) { return false; }

  // everything after limit should be 0xFF
  int i = large.limit();
  large.clear();
  for(; i < large.capacity(); i++) {
    if(large.get(i) != FSEditLogOpCodes.OP_INVALID.getOpCode()) {
      return false;
    }
  }

  return true;
}
 
Example 8
Source File: SameBuffer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void runGCMWithSeparateBuffers(int mode, ByteBuffer buffer,
        ByteBuffer textBB, int txtOffset, int dataLength,
        AlgorithmParameters params) throws Exception {
    // take offset into account
    textBB.position(txtOffset);
    textBB.mark();

    // first, generate the cipher text at an allocated buffer
    Cipher cipher = createCipher(mode, params);
    cipher.updateAAD(buffer);
    buffer.flip();
    ByteBuffer outBB = ByteBuffer.allocateDirect(
            cipher.getOutputSize(dataLength));

    cipher.doFinal(textBB, outBB);// get cipher text in outBB
    outBB.flip();

    // restore positions
    textBB.reset();

    // next, generate cipher text again in a buffer that shares content
    Cipher anotherCipher = createCipher(mode, params);
    anotherCipher.updateAAD(buffer);
    buffer.flip();
    ByteBuffer buf2 = textBB.duplicate(); // buf2 shares textBuf context
    buf2.limit(txtOffset + anotherCipher.getOutputSize(dataLength));
    int dataProcessed2 = anotherCipher.doFinal(textBB, buf2);
    buf2.position(txtOffset);
    buf2.limit(txtOffset + dataProcessed2);

    if (!buf2.equals(outBB)) {
        throw new RuntimeException(
                "Two results are not equal, mode:" + mode);
    }
}
 
Example 9
Source File: SameBuffer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void runGCMWithSeparateBuffers(int mode, ByteBuffer buffer,
        ByteBuffer textBB, int txtOffset, int dataLength,
        AlgorithmParameters params) throws Exception {
    // take offset into account
    textBB.position(txtOffset);
    textBB.mark();

    // first, generate the cipher text at an allocated buffer
    Cipher cipher = createCipher(mode, params);
    cipher.updateAAD(buffer);
    buffer.flip();
    ByteBuffer outBB = ByteBuffer.allocateDirect(
            cipher.getOutputSize(dataLength));

    cipher.doFinal(textBB, outBB);// get cipher text in outBB
    outBB.flip();

    // restore positions
    textBB.reset();

    // next, generate cipher text again in a buffer that shares content
    Cipher anotherCipher = createCipher(mode, params);
    anotherCipher.updateAAD(buffer);
    buffer.flip();
    ByteBuffer buf2 = textBB.duplicate(); // buf2 shares textBuf context
    buf2.limit(txtOffset + anotherCipher.getOutputSize(dataLength));
    int dataProcessed2 = anotherCipher.doFinal(textBB, buf2);
    buf2.position(txtOffset);
    buf2.limit(txtOffset + dataProcessed2);

    if (!buf2.equals(outBB)) {
        throw new RuntimeException(
                "Two results are not equal, mode:" + mode);
    }
}
 
Example 10
Source File: TokenServiceImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
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 );
    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 milliseconds ago.", expirationDelta ) );
    }
    return uuid;
}
 
Example 11
Source File: Dfu.java    From android-stm32-dfu-programmer with Apache License 2.0 5 votes vote down vote up
private boolean isWrittenImageOk() throws Exception {
    byte[] deviceFirmware = new byte[dfuFile.elementLength];
    long startTime = System.currentTimeMillis();
    readImage(deviceFirmware);
    // create byte buffer and compare content
    ByteBuffer fileFw = ByteBuffer.wrap(dfuFile.file, ELEMENT1_OFFSET, dfuFile.elementLength);    // set offset and limit of firmware
    ByteBuffer deviceFw = ByteBuffer.wrap(deviceFirmware);    // wrap whole array
    boolean result = fileFw.equals(deviceFw);
    Log.i(TAG, "Verified completed in " + (System.currentTimeMillis() - startTime) + " ms");
    return result;
}
 
Example 12
Source File: SameBuffer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void runGCMWithSameBuffer(int mode, ByteBuffer buffer,
        int txtOffset, int length, AlgorithmParameters params)
        throws Exception {

    // allocate a separate buffer
    Cipher cipher = createCipher(mode, params);
    ByteBuffer outBB = ByteBuffer.allocateDirect(
            cipher.getOutputSize(length));

    // first, generate the cipher text at an allocated buffer
    buffer.flip();
    buffer.limit(AADLength);
    cipher.updateAAD(buffer);
    buffer.limit(AADLength + txtOffset + length);
    buffer.position(AADLength + txtOffset);
    cipher.doFinal(buffer, outBB);
    outBB.flip(); // cipher text in outBB

    // next, generate cipherText again in the same buffer
    Cipher anotherCipher = createCipher(mode, params);
    buffer.flip();
    buffer.limit(AADLength);
    anotherCipher.updateAAD(buffer);
    buffer.limit(AADLength + txtOffset + length);
    buffer.position(AADLength + txtOffset);

    // share textBuf context
    ByteBuffer buf2 = buffer.duplicate();
    buf2.limit(AADLength + txtOffset + anotherCipher.getOutputSize(length));
    int dataProcessed2 = anotherCipher.doFinal(buffer, buf2);
    buf2.position(AADLength + txtOffset);
    buf2.limit(AADLength + txtOffset + dataProcessed2);

    if (!buf2.equals(outBB)) {
        throw new RuntimeException(
                "Two results are not equal, mode:" + mode);
    }
}
 
Example 13
Source File: CQLSSTableWriter.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new row to the writer given already serialized values.
 * <p>
 * This is a shortcut for {@code rawAddRow(Arrays.asList(values))}.
 *
 * @param values the row values (corresponding to the bind variables of the
 * insertion statement used when creating by this writer) as binary.
 * @return this writer.
 */
public CQLSSTableWriter rawAddRow(List<ByteBuffer> values)
throws InvalidRequestException, IOException
{
    if (values.size() != boundNames.size())
        throw new InvalidRequestException(String.format("Invalid number of arguments, expecting %d values but got %d", boundNames.size(), values.size()));

    QueryOptions options = QueryOptions.forInternalCalls(null, values);
    List<ByteBuffer> keys = insert.buildPartitionKeyNames(options);
    Composite clusteringPrefix = insert.createClusteringPrefix(options);

    long now = System.currentTimeMillis() * 1000;
    UpdateParameters params = new UpdateParameters(insert.cfm,
                                                   options,
                                                   insert.getTimestamp(now, options),
                                                   insert.getTimeToLive(options),
                                                   Collections.<ByteBuffer, CQL3Row>emptyMap());

    try
    {
        for (ByteBuffer key : keys)
        {
            if (writer.shouldStartNewRow() || !key.equals(writer.currentKey().getKey()))
                writer.newRow(key);
            insert.addUpdateForKey(writer.currentColumnFamily(), key, clusteringPrefix, params, false);
        }
        return this;
    }
    catch (BufferedWriter.SyncException e)
    {
        // If we use a BufferedWriter and had a problem writing to disk, the IOException has been
        // wrapped in a SyncException (see BufferedWriter below). We want to extract that IOE.
        throw (IOException)e.getCause();
    }
}
 
Example 14
Source File: SendFailed.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void assertSameContent(ByteBuffer bb1, ByteBuffer bb2) {
    if (!bb1.equals(bb2))
        throw new RuntimeException("Buffers are not equal; bb1: " + bb1 + ", bb2: " + bb2);
}
 
Example 15
Source File: CqlDataWriterDAO.java    From emodb with Apache License 2.0 4 votes vote down vote up
@Override
public void copyDeltasToDestination(Iterator<? extends MigrationScanResult> rows, AstyanaxStorage dest, Runnable progress) {
    if (!rows.hasNext()) {
        return;
    }

    DeltaPlacement placement = (DeltaPlacement) dest.getPlacement();
    Session session = placement.getKeyspace().getCqlSession();

    BatchStatement oldTableBatchStatement = new BatchStatement(BatchStatement.Type.LOGGED);
    BatchStatement newTableBatchStatment = new BatchStatement(BatchStatement.Type.LOGGED);

    ByteBuffer lastRowKey = null;
    int currentStatementSize = 0;

    while (rows.hasNext()) {
        MigrationScanResult result = rows.next();

        ByteBuffer rowKey = dest.getRowKey(AstyanaxStorage.getContentKey(result.getRowKey()));

        ByteBuffer delta = result.getValue();
        int deltaSize = delta.remaining();

        if ((lastRowKey != null && !rowKey.equals(lastRowKey)) || currentStatementSize > MAX_STATEMENT_SIZE) {
            oldTableBatchStatement = executeAndReplaceIfNotEmpty(oldTableBatchStatement, session, progress);
            newTableBatchStatment = executeAndReplaceIfNotEmpty(newTableBatchStatment, session, progress);
        }

        lastRowKey = rowKey;

        ByteBuffer blockedDelta = ByteBuffer.allocate(deltaSize + _deltaPrefixLength);
        blockedDelta.put(_deltaPrefixBytes);
        blockedDelta.put(delta.duplicate());
        blockedDelta.position(0);
        insertBlockedDeltas(newTableBatchStatment, placement.getBlockedDeltaTableDDL(),
                SorConsistencies.toCql(WriteConsistency.STRONG), rowKey, result.getChangeId(), blockedDelta);

        currentStatementSize += deltaSize + ROW_KEY_SIZE + CHANGE_ID_SIZE;
    }

    executeAndReplaceIfNotEmpty(oldTableBatchStatement, session, progress);
    executeAndReplaceIfNotEmpty(newTableBatchStatment, session, progress);
}
 
Example 16
Source File: TestOfflineEditsViewer.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Compare two files, ignore trailing zeros at the end, for edits log the
 * trailing zeros do not make any difference, throw exception is the files are
 * not same
 *
 * @param filenameSmall first file to compare (doesn't have to be smaller)
 * @param filenameLarge second file to compare (doesn't have to be larger)
 */
private boolean filesEqualIgnoreTrailingZeros(String filenameSmall,
  String filenameLarge) throws IOException {

  ByteBuffer small = ByteBuffer.wrap(DFSTestUtil.loadFile(filenameSmall));
  ByteBuffer large = ByteBuffer.wrap(DFSTestUtil.loadFile(filenameLarge));
  // OEV outputs with the latest layout version, so tweak the old file's
  // contents to have latest version so checkedin binary files don't
  // require frequent updates
  small.put(3, (byte)NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION);

  // now correct if it's otherwise
  if (small.capacity() > large.capacity()) {
    ByteBuffer tmpByteBuffer = small;
    small = large;
    large = tmpByteBuffer;
    String tmpFilename = filenameSmall;
    filenameSmall = filenameLarge;
    filenameLarge = tmpFilename;
  }

  // compare from 0 to capacity of small
  // the rest of the large should be all zeros
  small.position(0);
  small.limit(small.capacity());
  large.position(0);
  large.limit(small.capacity());

  // compares position to limit
  if (!small.equals(large)) {
    return false;
  }

  // everything after limit should be 0xFF
  int i = large.limit();
  large.clear();
  for (; i < large.capacity(); i++) {
    if (large.get(i) != FSEditLogOpCodes.OP_INVALID.getOpCode()) {
      return false;
    }
  }

  return true;
}
 
Example 17
Source File: SendFailed.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void assertSameContent(ByteBuffer bb1, ByteBuffer bb2) {
    if (!bb1.equals(bb2))
        throw new RuntimeException("Buffers are not equal; bb1: " + bb1 + ", bb2: " + bb2);
}
 
Example 18
Source File: BatchStatement.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private ResultMessage executeWithConditions(BatchQueryOptions options, QueryState state)
throws RequestExecutionException, RequestValidationException
{
    long now = state.getTimestamp();
    ByteBuffer key = null;
    String ksName = null;
    String cfName = null;
    CQL3CasRequest casRequest = null;
    Set<ColumnDefinition> columnsWithConditions = new LinkedHashSet<>();

    for (int i = 0; i < statements.size(); i++)
    {
        ModificationStatement statement = statements.get(i);
        QueryOptions statementOptions = options.forStatement(i);
        long timestamp = attrs.getTimestamp(now, statementOptions);
        List<ByteBuffer> pks = statement.buildPartitionKeyNames(statementOptions);
        if (pks.size() > 1)
            throw new IllegalArgumentException("Batch with conditions cannot span multiple partitions (you cannot use IN on the partition key)");
        if (key == null)
        {
            key = pks.get(0);
            ksName = statement.cfm.ksName;
            cfName = statement.cfm.cfName;
            casRequest = new CQL3CasRequest(statement.cfm, key, true);
        }
        else if (!key.equals(pks.get(0)))
        {
            throw new InvalidRequestException("Batch with conditions cannot span multiple partitions");
        }

        Composite clusteringPrefix = statement.createClusteringPrefix(statementOptions);
        if (statement.hasConditions())
        {
            statement.addConditions(clusteringPrefix, casRequest, statementOptions);
            // As soon as we have a ifNotExists, we set columnsWithConditions to null so that everything is in the resultSet
            if (statement.hasIfNotExistCondition() || statement.hasIfExistCondition())
                columnsWithConditions = null;
            else if (columnsWithConditions != null)
                Iterables.addAll(columnsWithConditions, statement.getColumnsWithConditions());
        }
        casRequest.addRowUpdate(clusteringPrefix, statement, statementOptions, timestamp);
    }

    ColumnFamily result = StorageProxy.cas(ksName, cfName, key, casRequest, options.getSerialConsistency(), options.getConsistency(), state.getClientState());

    return new ResultMessage.Rows(ModificationStatement.buildCasResultSet(ksName, key, cfName, result, columnsWithConditions, true, options.forStatement(0)));
}
 
Example 19
Source File: SendFailed.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static void assertSameContent(ByteBuffer bb1, ByteBuffer bb2) {
    if (!bb1.equals(bb2))
        throw new RuntimeException("Buffers are not equal; bb1: " + bb1 + ", bb2: " + bb2);
}
 
Example 20
Source File: TestCluster.java    From sofa-jraft with Apache License 2.0 4 votes vote down vote up
/**
 * Ensure all logs is the same in all nodes.
 * @param waitTimes
 * @return
 * @throws InterruptedException
 */
public boolean ensureSame(final int waitTimes) throws InterruptedException {
    this.lock.lock();
    List<MockStateMachine> fsmList = new ArrayList<>(this.fsms.values());
    if (fsmList.size() <= 1) {
        this.lock.unlock();
        return true;
    }
    System.out.println("Start ensureSame, waitTimes=" + waitTimes);
    try {
        int nround = 0;
        final MockStateMachine first = fsmList.get(0);
        CHECK: while (true) {
            first.lock();
            if (first.getLogs().isEmpty()) {
                first.unlock();
                Thread.sleep(10);
                nround++;
                if (waitTimes > 0 && nround > waitTimes) {
                    return false;
                }
                continue CHECK;
            }

            for (int i = 1; i < fsmList.size(); i++) {
                final MockStateMachine fsm = fsmList.get(i);
                fsm.lock();
                if (fsm.getLogs().size() != first.getLogs().size()) {
                    fsm.unlock();
                    first.unlock();
                    Thread.sleep(10);
                    nround++;
                    if (waitTimes > 0 && nround > waitTimes) {
                        return false;
                    }
                    continue CHECK;
                }

                for (int j = 0; j < first.getLogs().size(); j++) {
                    final ByteBuffer firstData = first.getLogs().get(j);
                    final ByteBuffer fsmData = fsm.getLogs().get(j);
                    if (!firstData.equals(fsmData)) {
                        fsm.unlock();
                        first.unlock();
                        Thread.sleep(10);
                        nround++;
                        if (waitTimes > 0 && nround > waitTimes) {
                            return false;
                        }
                        continue CHECK;
                    }
                }
                fsm.unlock();
            }
            first.unlock();
            break;
        }
        return true;
    } finally {
        this.lock.unlock();
        System.out.println("End ensureSame, waitTimes=" + waitTimes);
    }
}