FileDocCategorySizeDatePackage
URLDigest.javaAPI DocExample1065Sun Mar 28 19:07:50 BST 1999None

URLDigest

public class URLDigest extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


    for (int i = 0; i < args.length; i++) {
      try {
        URL u = new URL(args[i]);
        printDigest(u.openStream());
      }
      catch (MalformedURLException e) {
        System.err.println(args[i] + " is not a URL");
      }
      catch (Exception e) {
        System.err.println(e);
      }

    }

  
public static voidprintDigest(java.io.InputStream in)

    
     MessageDigest sha = MessageDigest.getInstance("SHA");
     byte[] data = new byte[128];
     while (true) {
       int bytesRead = in.read(data);
       if (bytesRead < 0) break;
       sha.update(data, 0, bytesRead);
     }
     byte[] result = sha.digest();
     for (int i = 0; i < result.length; i++) {
       System.out.print(result[i] + " ");
     }
     System.out.println();
     System.out.println(new BigInteger(data));