FileDocCategorySizeDatePackage
TrueMirror.javaAPI DocExample1140Mon Feb 13 11:58:38 GMT 2006None

TrueMirror

public class TrueMirror extends Object

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

    
    MessageDigest md5 = 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;
      }
      md5.update(data, 0, bytesRead);
    }
    return md5.digest();
  
public static voidmain(java.lang.String[] args)


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

    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");
    }