This repository was archived by the owner on Nov 12, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ package diffutils ;
2+
3+ import java .io .BufferedReader ;
4+ import java .io .File ;
5+ import java .io .FileReader ;
6+ import java .io .IOException ;
7+ import java .util .LinkedList ;
8+ import java .util .List ;
9+
10+ import difflib .Delta ;
11+ import difflib .DiffUtils ;
12+ import difflib .Patch ;
13+
14+ public class ComputeDifference {
15+ static final String FS = File .separator ;
16+ static final String originalFilename = "test" + FS + "mocks" + FS + "original.txt" ;
17+ static final String revisedFilename = "test" + FS + "mocks" + FS + "revised.txt" ;
18+
19+ private static List <String > fileToLines (String filename ) {
20+ List <String > lines = new LinkedList <String >();
21+ String line = "" ;
22+ try {
23+ BufferedReader in = new BufferedReader (new FileReader (filename ));
24+ while ((line = in .readLine ()) != null ) {
25+ lines .add (line );
26+ }
27+ } catch (IOException e ) {
28+ e .printStackTrace ();
29+ }
30+ return lines ;
31+ }
32+
33+ public static void main (String [] args ) {
34+ List <String > original = fileToLines (originalFilename );
35+ List <String > revised = fileToLines (revisedFilename );
36+
37+ // Compute diff. Get the Patch object. Patch is the container for computed deltas.
38+ Patch patch = DiffUtils .diff (original , revised );
39+
40+ for (Delta delta : patch .getDeltas ()) {
41+ System .out .println (delta );
42+ }
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments