public static OutputStream createStream( FSRevisionNode revNode, FSTransactionRoot txnRoot, OutputStream dstStream, boolean compress) throws SVNException { if (revNode.getType() != SVNNodeKind.FILE) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.FS_NOT_FILE, "Attempted to set textual contents of a *non*-file node"); SVNErrorManager.error(err, SVNLogType.FSFS); } if (!revNode.getId().isTxn()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.FS_NOT_MUTABLE, "Attempted to set textual contents of an immutable node"); SVNErrorManager.error(err, SVNLogType.FSFS); } OutputStream targetOS = null; InputStream sourceStream = null; long offset = -1; long deltaStart = -1; FSWriteLock txnLock = null; try { txnLock = FSWriteLock.getWriteLockForTxn(txnRoot.getTxnID(), txnRoot.getOwner()); txnLock.lock(); File targetFile = txnRoot.getTransactionProtoRevFile(); offset = targetFile.length(); targetOS = SVNFileUtil.openFileForWriting(targetFile, true); CountingOutputStream revWriter = new CountingOutputStream(targetOS, offset); FSRepresentation baseRep = revNode.chooseDeltaBase(txnRoot.getOwner()); sourceStream = FSInputStream.createDeltaStream(new SVNDeltaCombiner(), baseRep, txnRoot.getOwner()); String header; if (baseRep != null) { header = FSRepresentation.REP_DELTA + " " + baseRep.getRevision() + " " + baseRep.getOffset() + " " + baseRep.getSize() + "\n"; } else { header = FSRepresentation.REP_DELTA + "\n"; } revWriter.write(header.getBytes("UTF-8")); deltaStart = revWriter.getPosition(); if (dstStream instanceof FSOutputStream) { FSOutputStream fsOS = (FSOutputStream) dstStream; fsOS.reset( revNode, revWriter, targetFile, sourceStream, deltaStart, 0, offset, txnRoot, txnLock); return dstStream; } return new FSOutputStream( revNode, revWriter, targetFile, sourceStream, deltaStart, 0, offset, txnRoot, compress, txnLock); } catch (IOException ioe) { SVNFileUtil.closeFile(targetOS); SVNFileUtil.closeFile(sourceStream); txnLock.unlock(); FSWriteLock.release(txnLock); SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, ioe.getLocalizedMessage()); SVNErrorManager.error(err, ioe, SVNLogType.FSFS); } catch (SVNException svne) { if (txnLock != null) { txnLock.unlock(); FSWriteLock.release(txnLock); } SVNFileUtil.closeFile(targetOS); SVNFileUtil.closeFile(sourceStream); throw svne; } return null; }