Class Diff


  • public class Diff
    extends java.lang.Object
    The Diff class compares two files. It compares also two BufferedReaders or two strings. after the comparison the vector will represents a list of hunk corresponding with blocks of difference.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DELETE  
      static int INSERT  
      static int MAXLINES  
      static int ORIGIN  
    • Constructor Summary

      Constructors 
      Constructor Description
      Diff()
      Allocates a new diff containing no Hunks.
      Diff​(java.lang.String s1, java.lang.String s2)
      Allocates a new diff which contains Hunks corresponding to the difference between the two files passed in arguments.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void diffBuffer​(java.io.BufferedReader in, java.io.BufferedReader inn)
      Compares two BufferedReaders and updates the vector of Hunks.
      void diffFile​(java.lang.String s1, java.lang.String s2)
      Compares two files and updates the vector of Hunks.
      void diffString​(java.lang.String s1, java.lang.String s2)
      Compares two strings and updates the vector of Hunks.
      java.util.List getHunk()
      Returns a vector containing Hunks.
      java.lang.String iterateHunkBuffer​(java.io.BufferedReader reader, java.lang.String stuffBeforeDelete, java.lang.String stuffAfterDelete, java.lang.String stuffBeforeAdd, java.lang.String stuffAfterAdd, java.lang.String stuffBefore, java.lang.String stuffAfter, boolean printline, boolean escapeHTML, boolean hunkString)
      Iterate over a the hunks to print a readable representation.
      java.lang.String iterateHunkString​(java.lang.String str, java.lang.String stuffBeforeDelete, java.lang.String stuffAfterDelete, java.lang.String stuffBeforeAdd, java.lang.String stuffAfterAdd, boolean escapeHTML)
      Iterate over a the hunks to print a readable representation.
      static void main​(java.lang.String[] args)  
      void print()
      Print Hunks with normal format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Diff

        public Diff()
        Allocates a new diff containing no Hunks.
      • Diff

        public Diff​(java.lang.String s1,
                    java.lang.String s2)
             throws java.io.IOException
        Allocates a new diff which contains Hunks corresponding to the difference between the two files passed in arguments.
        Parameters:
        s1 - first file to compare.
        s2 - second file to compare.
        Throws:
        java.io.IOException
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • iterateHunkString

        public java.lang.String iterateHunkString​(java.lang.String str,
                                                  java.lang.String stuffBeforeDelete,
                                                  java.lang.String stuffAfterDelete,
                                                  java.lang.String stuffBeforeAdd,
                                                  java.lang.String stuffAfterAdd,
                                                  boolean escapeHTML)
                                           throws java.lang.Exception
        Iterate over a the hunks to print a readable representation.
        Parameters:
        str - The original string to print
        stuffBeforeDelete - String to add before deleted hunk.
        stuffAfterDelete - String to add after deleted hunk.
        stuffBeforeAdd - String to add before added hunk.
        stuffAfterAdd - String to add after added hunk.
        escapeHTML - should escape html ?
        Returns:
        The result string
        Throws:
        java.lang.Exception
      • iterateHunkBuffer

        public java.lang.String iterateHunkBuffer​(java.io.BufferedReader reader,
                                                  java.lang.String stuffBeforeDelete,
                                                  java.lang.String stuffAfterDelete,
                                                  java.lang.String stuffBeforeAdd,
                                                  java.lang.String stuffAfterAdd,
                                                  java.lang.String stuffBefore,
                                                  java.lang.String stuffAfter,
                                                  boolean printline,
                                                  boolean escapeHTML,
                                                  boolean hunkString)
                                           throws java.lang.Exception
        Iterate over a the hunks to print a readable representation.
        Parameters:
        reader - The original buffer to print
        stuffBeforeDelete - String to add before deleted hunk.
        stuffAfterDelete - String to add after deleted hunk.
        stuffBeforeAdd - String to add before added hunk.
        stuffAfterAdd - String to add after added hunk.
        stuffBefore - String to add before line.
        stuffAfter - String to add after line.
        printline - should print the line number ?
        escapeHTML - should escape html ?
        hunkString - should diff each line of hunks ?
        Returns:
        The result string
        Throws:
        java.lang.Exception
      • getHunk

        public java.util.List getHunk()
        Returns a vector containing Hunks.
      • diffFile

        public void diffFile​(java.lang.String s1,
                             java.lang.String s2)
                      throws java.io.IOException
        Compares two files and updates the vector of Hunks.
        Parameters:
        s1 - first file to compare.
        s2 - second file to compare.
        Throws:
        java.io.IOException
      • diffBuffer

        public void diffBuffer​(java.io.BufferedReader in,
                               java.io.BufferedReader inn)
                        throws java.io.IOException
        Compares two BufferedReaders and updates the vector of Hunks.
        Parameters:
        in - first BufferedReader to compare.
        inn - second BufferedReader to compare.
        Throws:
        java.io.IOException
      • diffString

        public void diffString​(java.lang.String s1,
                               java.lang.String s2)
                        throws java.io.IOException
        Compares two strings and updates the vector of Hunks.
        Parameters:
        s1 - first string to compare.
        s2 - second string to compare.
        Throws:
        java.io.IOException
      • print

        public void print()
        Print Hunks with normal format.