String expectedChecksum = null;
String checksum = null;
String newChecksum = null;
SVNChecksumInputStream baseChecksummedIS = null;
InputStream sourceIS = null;
InputStream targetIS = null;
OutputStream tmpBaseStream = null;
File baseFile = dir.getBaseFile(name, false);
SVNErrorMessage error = null;
boolean useChecksummedStream = false;
boolean openSrcStream = false;
if (!item.isAdded()) {
openSrcStream = true;
expectedChecksum = entry.getChecksum();
if (expectedChecksum != null) {
useChecksummedStream = true;
} else {
expectedChecksum = SVNFileUtil.computeChecksum(baseFile);
}
} else {
sourceIS = SVNFileUtil.DUMMY_IN;
}
editor.applyTextDelta(path, expectedChecksum);
if (myDeltaGenerator == null) {
myDeltaGenerator = new SVNDeltaGenerator();
}
try {
sourceIS = openSrcStream ? SVNFileUtil.openFileForReading(baseFile, SVNLogType.WC) : sourceIS;
if (useChecksummedStream) {
baseChecksummedIS = new SVNChecksumInputStream(sourceIS, SVNChecksumInputStream.MD5_ALGORITHM);
sourceIS = baseChecksummedIS;
}
targetIS = SVNTranslator.getTranslatedStream(dir, name, true, false);
tmpBaseStream = SVNFileUtil.openFileForWriting(tmpFile);
CopyingStream localStream = new CopyingStream(tmpBaseStream, targetIS);
newChecksum = myDeltaGenerator.sendDelta(path, sourceIS, 0, localStream, editor, true);
} catch (SVNException svne) {
error = svne.getErrorMessage().wrap("While preparing ''{0}'' for commit", dir.getFile(name));
} finally {
SVNFileUtil.closeFile(sourceIS);
SVNFileUtil.closeFile(targetIS);
SVNFileUtil.closeFile(tmpBaseStream);
}
if (baseChecksummedIS != null) {
checksum = baseChecksummedIS.getDigest();
}
if (expectedChecksum != null && checksum != null && !expectedChecksum.equals(checksum)) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_CORRUPT_TEXT_BASE,
"Checksum mismatch for ''{0}''; expected: ''{1}'', actual: ''{2}''",