FileDocCategorySizeDatePackage
ListCallbackDigest.javaAPI DocExample1213Sat Sep 09 19:53:00 BST 2000None

ListCallbackDigest

public class ListCallbackDigest extends Object implements Runnable

Fields Summary
private File
input
List
listenerList
Constructors Summary
public ListCallbackDigest(File input)


     
   this.input = input;
  
Methods Summary
public synchronized voidaddDigestListener(DigestListener l)

    listenerList.add(l);
  
public synchronized voidremoveDigestListener(DigestListener l)

    listenerList.remove(l);
  
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();
      this.sendDigest(digest);
    }
    catch (IOException e) {
      System.err.println(e);
    }
    catch (NoSuchAlgorithmException e) {
      System.err.println(e);
    }
    
  
private synchronized voidsendDigest(byte[] digest)

    ListIterator iterator = listenerList.listIterator();
    while (iterator.hasNext()) {
      DigestListener dl = (DigestListener) iterator.next();
      dl.digestCalculated(digest);
    }