FileDocCategorySizeDatePackage
TrueMirror.javaAPI DocExample1290Sun Mar 28 19:07:50 BST 1999None

TrueMirror

public class TrueMirror extends Object

Fields Summary
Constructors Summary
Methods Summary
public static byte[]getDigestFromURL(java.net.URL u)

    
     MessageDigest sha = MessageDigest.getInstance("MD5");
     InputStream in = u.openStream();
     byte[] data = new byte[128];
     while (true) {
       int bytesRead = in.read(data);
       if (bytesRead < 0) { // end of stream
         break;
       }
       sha.update(data, 0, bytesRead);
     }

     return sha.digest();

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


    if (args.length != 2) {
      System.err.println("Usage: java TrueMirror url1 url2");
      return;
    }

    try {
      URL source = new URL(args[0]);
      URL mirror = new URL(args[1]);
      byte[] sourceDigest = getDigestFromURL(source);
      byte[] mirrorDigest = getDigestFromURL(mirror);
      if (MessageDigest.isEqual(sourceDigest, mirrorDigest)) {
        System.out.println(mirror + " is up to date");
      }
      else {
        System.out.println(mirror + " needs to be updated");
      }

    }
    catch (MalformedURLException e) {
      System.err.println(e);
    }
    catch (Exception e) {
      System.err.println(e);
    }