コード例 #1
0
 /**
  * Returns an instance of a specific checksum algorithm for caching.
  *
  * @param instance of the algorithm
  */
 public void returnAlgorithm(ChecksumAlgorithm algorithm) {
   ConcurrentLinkedQueue<ChecksumAlgorithm> cache = pool.get(algorithm.getName());
   if (cache.size() < MAX_CACHE_SIZE) {
     algorithm.reset();
     cache.add(algorithm);
   }
 }
コード例 #2
0
ファイル: Checksum.java プロジェクト: Odger/archiva
 public Checksum(ChecksumAlgorithm checksumAlgorithm) {
   this.checksumAlgorithm = checksumAlgorithm;
   try {
     md = MessageDigest.getInstance(checksumAlgorithm.getAlgorithm());
   } catch (NoSuchAlgorithmException e) {
     // Not really possible, but here none-the-less
     throw new IllegalStateException(
         "Unable to initialize MessageDigest algorithm "
             + checksumAlgorithm.getAlgorithm()
             + " : "
             + e.getMessage(),
         e);
   }
 }
コード例 #3
0
ファイル: GridFTPClient.java プロジェクト: kofemann/dcache
  /**
   * Sets the checksum values ahead of the transfer
   *
   * @param algorithm the checksume algorithm
   * @param value the checksum value as hexadecimal number
   * @return nothing
   * @throws ServerException if an error occured.
   */
  public void setChecksum(ChecksumAlgorithm algorithm, String value)
      throws IOException, ServerException {
    String arguments = algorithm.toFtpCmdArgument() + " " + value;

    Command cmd = new Command("SCKS", arguments);
    try {
      controlChannel.execute(cmd);
    } catch (UnexpectedReplyCodeException urce) {
      throw ServerException.embedUnexpectedReplyCodeException(urce);
    } catch (FTPReplyParseException rpe) {
      throw ServerException.embedFTPReplyParseException(rpe);
    }
  }
コード例 #4
0
ファイル: GridFTPClient.java プロジェクト: kofemann/dcache
  /**
   * Computes and returns a checksum of a file. transferred.
   *
   * @param algorithm the checksume algorithm
   * @param offset the offset
   * @param length the length
   * @param file file to compute checksum of
   * @return the computed checksum
   * @throws ServerException if an error occured.
   */
  public String checksum(ChecksumAlgorithm algorithm, long offset, long length, String file)
      throws IOException, ServerException {
    String arguments =
        algorithm.toFtpCmdArgument()
            + " "
            + String.valueOf(offset)
            + " "
            + String.valueOf(length)
            + " "
            + file;

    Command cmd = new Command("CKSM", arguments);
    Reply reply = null;
    try {
      reply = controlChannel.execute(cmd);
      return reply.getMessage();
    } catch (UnexpectedReplyCodeException urce) {
      throw ServerException.embedUnexpectedReplyCodeException(urce);
    } catch (FTPReplyParseException rpe) {
      throw ServerException.embedFTPReplyParseException(rpe);
    }
  }
コード例 #5
0
 /**
  * Adds a new Algorithm to factory. NOTE: The same existing algorithm will be overridden.
  *
  * @param algorithm
  */
 public void addAlgorithm(ChecksumAlgorithm algorithm) {
   algorithms.put(algorithm.getName(), algorithm);
   pool.put(algorithm.getName(), new ConcurrentLinkedQueue<ChecksumAlgorithm>());
 }
コード例 #6
0
 public RunningChecksum(ChecksumAlgorithm algorithm) throws NoSuchAlgorithmException {
   this.algorithm = algorithm;
   this.offset = 0;
   this.digest = MessageDigest.getInstance(algorithm.getDigestName());
 }