1 19 20 package org.netbeans.modules.diff.builtin.provider; 21 22 import java.io.BufferedReader ; 23 import java.io.IOException ; 24 import java.io.Reader ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 import org.openide.util.NbBundle; 29 30 import org.netbeans.api.diff.Difference; 31 import org.netbeans.spi.diff.DiffProvider; 32 33 37 public class BuiltInDiffProvider extends DiffProvider implements java.io.Serializable { 38 39 42 private boolean trimLines = true; 43 44 static final long serialVersionUID = 1L; 45 46 47 public BuiltInDiffProvider() { 48 } 49 50 53 public String getDisplayName() { 54 return NbBundle.getMessage(BuiltInDiffProvider.class, "BuiltInDiffProvider.displayName"); 55 } 56 57 60 public String getShortDescription() { 61 return NbBundle.getMessage(BuiltInDiffProvider.class, "BuiltInDiffProvider.shortDescription"); 62 } 63 64 71 public Difference[] computeDiff(Reader r1, Reader r2) throws IOException { 72 return HuntDiff.diff(getLines(r1), getLines(r2), trimLines); 73 } 74 75 private String [] getLines(Reader r) throws IOException { 76 BufferedReader br = new BufferedReader (r); 77 String line; 78 List <String > lines = new ArrayList <String >(); 79 while ((line = br.readLine()) != null) { 80 lines.add(line); 81 } 82 return lines.toArray(new String [0]); 83 } 84 85 86 87 public boolean isTrimLines() { 88 return this.trimLines; 89 } 90 91 95 public void setTrimLines(boolean trimLines) { 96 this.trimLines = trimLines; 97 } 98 99 100 101 } 102 | Popular Tags |