FileDocCategorySizeDatePackage
DigestThread.javaAPI DocExample1063Sat Sep 09 19:52:32 BST 2000None

DigestThread

public class DigestThread extends Thread

Fields Summary
private File
input
Constructors Summary
public DigestThread(File input)

   this.input = input;
  
Methods Summary
public static voidmain(java.lang.String[] args)

  
    for (int i = 0; i < args.length; i++) {
      File f = new File(args[i]);
      Thread t = new DigestThread(f);
      t.start();
    }
  
  
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();
      byte[] digest = sha.digest();
      StringBuffer result = new StringBuffer(input.toString());
      result.append(": ");
      for (int i = 0; i < digest.length; i++) {
        result.append(digest[i] + " ");
      }
      System.out.println(result);
    }
    catch (IOException e) {
      System.err.println(e);
    }
    catch (NoSuchAlgorithmException e) {
      System.err.println(e);
    }