FileDocCategorySizeDatePackage
ReturnDigest2.javaAPI DocExample1500Sun Dec 12 10:51:28 GMT 2004None

ReturnDigest2

public class ReturnDigest2 extends Object implements Runnable

Fields Summary
private File
input
private byte[]
digest
Constructors Summary
public ReturnDigest2(File input)

   this.input = input;
  
Methods Summary
public byte[]getDigest()

    return digest;
  
public static voidmain(java.lang.String[] args)

  
    ReturnDigest1[] digests = new ReturnDigest1[args.length];
  
    for (int i = 0; i < args.length; i++) {
    
      // Calculate the digest
      File f = new File(args[i]);
      digests[i] = new ReturnDigest1(f);
      Thread t = new Thread(digests[i]);
      t.start();
      
    }
    
    for (int i = 0; i < args.length; i++) {
      
      // Now print the result
      StringBuffer result = new StringBuffer(args[i]);
      result.append(": ");
      byte[] digest = digests[i].getDigest();
      for (int j = 0; j < digest.length; j++) {
        result.append(digest[j] + " ");
      }  
      System.out.println(result);
      
    }
  
  
public voidrun()

    try {
      FileInputStream in = new FileInputStream(input);
      MessageDigest sha = MessageDigest.getInstance("SHA");
      DigestInputStream din = new DigestInputStream(in, sha);
      int b;
      while ((b = din.read()) != -1) ;
      din.close();
      digest = sha.digest();
    }
    catch (IOException e) {
      System.err.println(e);
    }
    catch (NoSuchAlgorithmException e) {
      System.err.println(e);
    }