long[] range = parseRange();
if (range != null) {
mode = DAV_MODE_WRITE_SEEKABLE;
}
SVNDeltaReader deltaReader = null;
DAVException error = null;
try {
deltaReader = openStream(resource, mode);
} catch (DAVException dave) {
error = new DAVException("Unable to PUT new contents for {0}.", new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) },
HttpServletResponse.SC_FORBIDDEN, dave, 0);
}
if (error == null && range != null) {
error = new DAVException("Resource body read/write cannot use ranges (at this time)", HttpServletResponse.SC_NOT_IMPLEMENTED, 0);
}
DAVException error2 = null;
if (error == null) {
String path = resource.getResourceURI().getPath();
FSRoot root = resource.getRoot();
FSFS fsfs = resource.getFSFS();
FSTransactionInfo txn = resource.getTxnInfo();
Collection lockTokens = resource.getLockTokens();
String userName = resource.getUserName();
FSCommitter committer = getCommitter(fsfs, root, txn, lockTokens, userName);
ISVNDeltaConsumer deltaConsumer = getDeltaConsumer(root, committer, fsfs, userName, lockTokens);
SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
InputStream inputStream = null;
try {
inputStream = getRequestInputStream();
byte[] buffer = new byte[2048];
int readCount = -1;
while ((readCount = inputStream.read(buffer)) != -1) {
if (readCount == 0) {
continue;
}
if (deltaReader != null) {
deltaReader.nextWindow(buffer, 0, readCount, path, deltaConsumer);
} else {
deltaGenerator.sendDelta(path, buffer, readCount, deltaConsumer);
}
}
} catch (IOException ioe) {
error = new DAVException("An error occurred while reading the request body.", HttpServletResponse.SC_BAD_REQUEST, 0);
} catch (SVNException svne) {
error = DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"could not write the file contents", null);
} finally {
SVNFileUtil.closeFile(inputStream);
if (deltaReader != null) {
try {
deltaReader.reset(path, deltaConsumer);
} catch (SVNException svne) {
error2 = DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"error finalizing applying windows", null);
}