private void copyFile(File oldFile, File newFile) throws MoveProjectException { try { FileUtils.copyFile(oldFile, newFile); long oldSum = FileUtils.computeChecksum(oldFile, new Adler32()); long newSum = FileUtils.computeChecksum(newFile, new Adler32()); if (oldSum == newSum) return; } catch (IOException e) { } throw new MoveProjectException(MoveProjectWizard.NEWDIR_URI, "cannotCreateFile") .append("oldPath", oldFile.getPath()) .append("path", newFile.getPath()); }
public Long getChecksum() { while (true) { // Check the last modification time. If it has changed // since we last computed the checksum, this will invalidate // our checksum data. long lastMod = getLastModified(); // Now look to see if the lastMod time is zero. That's an // indication that the file doesn't exist. if (lastMod < 1) return null; // The file exists. If we have a valid checksum, return it. Long cksum = this.checksum; if (cksum != null) return cksum; try { // We don't have an up-to-date checksum. Calculate one. Long newSum = FileUtils.computeChecksum(f, new Adler32()); // Save the new checksum. But don't return it yet! Start // back at the top of the loop and make certain the last // modified time hasn't changed since we calculated the // checksum. synchronized (this) { checksum = newSum; lastChecked = -1; } } catch (IOException e) { // encountered an error while computing the checksum? // return null to indicate the error. return null; } } }