FileDocCategorySizeDatePackage
ReturnDigest3.javaAPI DocExample1619Sun Dec 12 10:51:30 GMT 2004None

ReturnDigest3

public class ReturnDigest3 extends Object implements Runnable

Fields Summary
private File
input
private byte[]
digest
Constructors Summary
public ReturnDigest3(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++) {
      while (true) {
        // Now print the result
        byte[] digest = digests[i].getDigest();
        if (digest != null) {
          StringBuffer result = new StringBuffer(args[i]);
          result.append(": ");
          for (int j = 0; j < digest.length; j++) {
            result.append(digest[j] + " ");
          }  
          System.out.println(result);
          break;
        }
      }      
    }  
    
  
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);
    }