com.cloudbees.diff
Class Diff

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Difference>
              extended by com.cloudbees.diff.Diff
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Difference>, Collection<Difference>, List<Difference>, RandomAccess

public class Diff
extends ArrayList<Difference>
implements Serializable

Represents a diff between two files. Entry point of the library.

Author:
Kohsuke Kawaguchi
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Diff()
           
 
Method Summary
 Reader apply(Reader source)
          Apply the difference to the specified source.
static Diff diff(File f1, File f2, boolean ignoreWhitespace)
          Computes a diff between two files.
static Diff diff(List<String> lines1, List<String> lines2, boolean ignoreWhitespace)
          Compares two "files" that are passed in as a list of lines.
static Diff diff(Reader r1, Reader r2, boolean ignoreWhitespace)
          Create the differences of the content two streams.
 String toUnifiedDiff(String name1, String name2, Reader r1, Reader r2, int numContextLines)
          Prints the difference in the unified diff format.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

Diff

public Diff()
Method Detail

diff

public static Diff diff(File f1,
                        File f2,
                        boolean ignoreWhitespace)
                 throws IOException
Computes a diff between two files.

Throws:
IOException

diff

public static Diff diff(Reader r1,
                        Reader r2,
                        boolean ignoreWhitespace)
                 throws IOException
Create the differences of the content two streams.

Parameters:
r1 - the first source
r2 - the second source to be compared with the first one.
Throws:
IOException

diff

public static Diff diff(List<String> lines1,
                        List<String> lines2,
                        boolean ignoreWhitespace)
Compares two "files" that are passed in as a list of lines.


toUnifiedDiff

public String toUnifiedDiff(String name1,
                            String name2,
                            Reader r1,
                            Reader r2,
                            int numContextLines)
                     throws IOException
Prints the difference in the unified diff format.

Parameters:
numContextLines - Number of context lines to generate around the diff.
Throws:
IOException

apply

public Reader apply(Reader source)
Apply the difference to the specified source.

Parameters:
source - The source stream
Returns:
The patched stream
Throws:
IOException - When reading from the source stream fails
ParseException - When the source does not match the patch to be applied


Copyright © 2011-2012. All Rights Reserved.