Java Code Examples for org.apache.commons.codec.digest.DigestUtils#getDigest()

The following examples show how to use org.apache.commons.codec.digest.DigestUtils#getDigest() . 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: Digest.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
private void run() throws IOException {
    if (algorithm.equalsIgnoreCase("ALL") || algorithm.equals("*")) {
        run(MessageDigestAlgorithms.values());
        return;
    }
    final MessageDigest messageDigest = DigestUtils.getDigest(algorithm, null);
    if (messageDigest != null) {
        run("", messageDigest);
    } else {
        run("", DigestUtils.getDigest(algorithm.toUpperCase(Locale.ROOT)));
    }
}
 
Example 2
Source File: Digest.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
private void run() throws IOException {
    if (algorithm.equalsIgnoreCase("ALL") || algorithm.equals("*")) {
        run(MessageDigestAlgorithms.values());
        return;
    }
    final MessageDigest messageDigest = DigestUtils.getDigest(algorithm, null);
    if (messageDigest != null) {
        run("", messageDigest);
    } else {
        run("", DigestUtils.getDigest(algorithm.toUpperCase(Locale.ROOT)));
    }
}
 
Example 3
Source File: RandomKeyGenerator.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Override
public Void call() throws Exception {
  if (ozoneConfiguration != null) {
    if (!ozoneConfiguration.getBoolean(
        HddsConfigKeys.HDDS_CONTAINER_PERSISTDATA,
        HddsConfigKeys.HDDS_CONTAINER_PERSISTDATA_DEFAULT)) {
      LOG.info("Override validateWrites to false, because "
          + HddsConfigKeys.HDDS_CONTAINER_PERSISTDATA + " is set to false.");
      validateWrites = false;
    }
    init(ozoneConfiguration);
  } else {
    init(freon.createOzoneConfiguration());
  }

  keyValueBuffer = StringUtils.string2Bytes(
      RandomStringUtils.randomAscii(bufferSize));

  // Compute the common initial digest for all keys without their UUID
  if (validateWrites) {
    commonInitialMD = DigestUtils.getDigest(DIGEST_ALGORITHM);
    for (long nrRemaining = keySize; nrRemaining > 0;
        nrRemaining -= bufferSize) {
      int curSize = (int)Math.min(bufferSize, nrRemaining);
      commonInitialMD.update(keyValueBuffer, 0, curSize);
    }
  }

  totalBucketCount = numOfVolumes * numOfBuckets;
  totalKeyCount = totalBucketCount * numOfKeys;

  LOG.info("Number of Threads: {}", numOfThreads);
  threadPoolSize = numOfThreads;
  executor = Executors.newFixedThreadPool(threadPoolSize);
  addShutdownHook();

  LOG.info("Number of Volumes: {}.", numOfVolumes);
  LOG.info("Number of Buckets per Volume: {}.", numOfBuckets);
  LOG.info("Number of Keys per Bucket: {}.", numOfKeys);
  LOG.info("Key size: {} bytes", keySize);
  LOG.info("Buffer size: {} bytes", bufferSize);
  LOG.info("validateWrites : {}", validateWrites);
  for (int i = 0; i < numOfThreads; i++) {
    executor.execute(new ObjectCreator());
  }

  Thread validator = null;
  if (validateWrites) {
    totalWritesValidated = 0L;
    writeValidationSuccessCount = 0L;
    writeValidationFailureCount = 0L;

    validationQueue = new LinkedBlockingQueue<>();
    validator = new Thread(new Validator());
    validator.start();
    LOG.info("Data validation is enabled.");
  }

  LongSupplier currentValue = numberOfKeysAdded::get;
  progressbar = new ProgressBar(System.out, totalKeyCount, currentValue);

  LOG.info("Starting progress bar Thread.");

  progressbar.start();

  // wait until all keys are added or exception occurred.
  while ((numberOfKeysAdded.get() != totalKeyCount)
         && exception == null) {
    try {
      Thread.sleep(CHECK_INTERVAL_MILLIS);
    } catch (InterruptedException e) {
      throw e;
    }
  }
  executor.shutdown();
  executor.awaitTermination(Integer.MAX_VALUE, TimeUnit.MILLISECONDS);
  completed = true;

  if (exception != null) {
    progressbar.terminate();
  } else {
    progressbar.shutdown();
  }

  if (validator != null) {
    validator.join();
  }
  ozoneClient.close();
  if (exception != null) {
    throw new RuntimeException(exception);
  }
  return null;
}
 
Example 4
Source File: HashService.java    From nifi with Apache License 2.0 4 votes vote down vote up
private static byte[] traditionalHashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException {
    MessageDigest digest = DigestUtils.getDigest(algorithm.getName());
    // DigestInputStream digestInputStream = new DigestInputStream(value, digest);
    return DigestUtils.digest(digest, value);
}