
fitnesse.updates.ReplacingFileUpdate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse Show documentation
Show all versions of fitnesse Show documentation
The fully integrated standalone wiki, and acceptance testing framework.
// Copyright (C) 2003-2009 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.updates;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class ReplacingFileUpdate extends FileUpdate {
public ReplacingFileUpdate(String source, File destination) {
super(source, destination);
}
@Override
public void doUpdate() throws IOException {
if (destinationFile().exists())
destinationFile().delete();
super.doUpdate();
}
@Override
public boolean shouldBeApplied() throws IOException {
if (super.shouldBeApplied())
return true;
else {
URL resource = getResource(source);
if (resource != null) {
long sourceSum = checkSum(resource.openStream());
long destinationSum = checkSum(new FileInputStream(destinationFile()));
return sourceSum != destinationSum;
} else
return false;
}
}
private long checkSum(InputStream input) throws IOException {
try {
long sum = 0;
int b;
while ((b = input.read()) != -1)
sum += b;
return sum;
} finally {
input.close();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy