Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * ====================================================================
   * Copyright (c) 2004-2006 TMate Software Ltd.  All rights reserved.
   *
   * This software is licensed as described in the file COPYING, which
   * you should have received as part of this distribution.  The terms
   * are also available at http://svnkit.com/license.html
   * If newer versions of this license are posted there, you may use a
   * newer version instead, at your option.
  * ====================================================================
  */
 package org.tmatesoft.svn.core.io.diff;
 
 import java.io.File;
 
The SVNDeltaProcessor is used to get a full text of a file in series applying diff windows being passed to a processor.

Author(s):
TMate Software Ltd.
Version:
1.1.0
 
 public class SVNDeltaProcessor {
     
     private SVNDiffWindowApplyBaton myApplyBaton;
    
    
Creates a processor.
 
     public SVNDeltaProcessor() {
     }
    
    
Starts processing deltas given a base file stream and an output stream to write resultant target bytes to.

If a target full text is a newly added file (text deltas would be vs. empty), then source bytes are not needed and base may be passed as null.

If computeChecksum is true, then an MD5 checksum will be calculated for target bytes. The calculated checksum is returned by textDeltaEnd().

Parameters:
base an input stream to take base file contents from
target an output stream to write the resultant target contents to
computeCheksum true to calculate checksum
 
     public void applyTextDelta(InputStream baseOutputStream targetboolean computeCheksum) {
         reset();
         MessageDigest digest = null;
         try {
             digest = computeCheksum ? MessageDigest.getInstance("MD5") : null;
         } catch (NoSuchAlgorithmException e1) {
         }
         base = base == null ? . : base;
          = SVNDiffWindowApplyBaton.create(basetargetdigest);
     }
    
    
Starts processing deltas given a base file and a one to write resultant target bytes to.

If a target full text is a newly added file (text deltas would be vs. empty), then source bytes are not needed and baseFile may be passed as null.

If a file represented by targetFile does not exist yet, first tries to create an empty file.

If computeChecksum is true, then an MD5 checksum will be calculated for target bytes. The calculated checksum is returned by textDeltaEnd().

Parameters:
baseFile a base file to read base file contents from
targetFile a destination file where resultant target bytes will be written
computeCheksum true to calculate checksum
Throws:
org.tmatesoft.svn.core.SVNException
 
     public void applyTextDelta(File baseFileFile targetFileboolean computeCheksumthrows SVNException {
        if (!targetFile.exists()) {
            SVNFileUtil.createEmptyFile(targetFile);
        }
        InputStream base = baseFile != null && baseFile.exists() ? SVNFileUtil.openFileForReading(baseFile) : .;
        applyTextDelta(base, SVNFileUtil.openFileForWriting(targetFile), computeCheksum);
    }
    
    
Receives a next diff window to be applied. The return value is a dummy stream (left for backward compatibility) since new data should come within a diff window.

Parameters:
window a diff window
Returns:
a dummy output stream
Throws:
org.tmatesoft.svn.core.SVNException
    public OutputStream textDeltaChunk(SVNDiffWindow windowthrows SVNException {
        window.apply();
        return .;
    }
    
    private void reset() {
        if ( != null) {
            .close();
             = null;
        }
    }
    
    
Performs delta processing finalizing steps. Applies the last window left (if any) and finalizes checksum calculation (if a checksum was required).

Returns:
a string representing a hex form of the calculated MD5 checksum or null if checksum calculation was not required
    public String textDeltaEnd() {
        try {
            return .close();
        } finally { 
            reset();
        }
    }
New to GrepCode? Check out our FAQ X