//-*-java-*- FileCheck { (@ private static Hashtable checksums; private Checksum ck; private File output, old; private PrintWriter out; @) /** Read in the checksum list from the file. */ static void readChecksums(File file) (@ try { checksums = (Hashtable) (new ObjectInputStream(new FileInputStream(file))).readObject(); } catch (IOException e) { checksums = new Hashtable(); } catch (ClassNotFoundException e) { throw new RuntimeException(e.toString()); } @) /** Write the current checksum list to the file. */ static void writeChecksums(File file) (@ try { (new ObjectOutputStream(new FileOutputStream(file))).writeObject(checksums); } catch (IOException e) { throw new RuntimeException(e.toString()); } @) /** Open the file */ PrintWriter openOutputFile(File file) (@ output = file; old = new File(output + "~"); if (output.exists()) output.renameTo(old); try { ck = new Adler32(); out = new PrintWriter (new CheckedOutputStream(new FileOutputStream(output), ck)); } catch (IOException e) { throw new RuntimeException(e.toString()); } return out; @) /** Close and flush the current output file. If the file hasn't changed, move the old one back so the timestamp doesn't change. */ void closeOutputFile() (@ out.flush(); out.close(); Long oldck = (Long) checksums.get(output); //System.err.println(output + ": " + ck.getValue() + " " + // old + ": " + oldck); if (oldck != null && oldck.longValue() == ck.getValue() && old.exists()) { output.delete(); // not needed on Unix, but it is on Windows... old.renameTo(output); } else { checksums.put(output, new Long(ck.getValue())); old.delete(); } @) }