Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Commit

Permalink
added stream source input
Browse files Browse the repository at this point in the history
some minor tweaks
  • Loading branch information
Joel Håkansson committed Dec 19, 2013
1 parent 6ed7507 commit 57e4217
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions braille/src/org/daisy/braille/pef/PEFFileCompare.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ public PEFFileCompare(String path) {
public PEFFileCompare(URL nr) {
this(new URLNormalizationResource(nr));
}

public boolean compare(File f1, File f2) throws PEFFileCompareException {
return compare(new StreamSource(f1), new StreamSource(f2));
}

public boolean compare(StreamSource xml1, StreamSource xml2) throws PEFFileCompareException {
pos = -1;
FileCompare fc = new FileCompare();

TransformerFactory factory = TransformerFactory.newInstance();
try {
Expand All @@ -50,11 +53,12 @@ public boolean compare(File f1, File f2) throws PEFFileCompareException {

try {
File t1 = File.createTempFile("FileCompare", ".tmp");
t1.deleteOnExit();
File t2 = File.createTempFile("FileCompare", ".tmp");
t2.deleteOnExit();

try {
StreamSource xml1 = new StreamSource(f1);
StreamSource xml2 = new StreamSource(f2);

Source xslt;
Transformer transformer;

Expand All @@ -65,6 +69,7 @@ public boolean compare(File f1, File f2) throws PEFFileCompareException {
xslt = new StreamSource(nr.getNormalizationResourceAsStream());
transformer = factory.newTransformer(xslt);
transformer.transform(xml2, new StreamResult(t2));
FileCompare fc = new FileCompare();
boolean ret = fc.compareXML(new FileInputStream(t1), new FileInputStream(t2));
pos = fc.getPos();
return ret;
Expand All @@ -77,11 +82,9 @@ public boolean compare(File f1, File f2) throws PEFFileCompareException {
} finally {
if (!t1.delete()) {
System.err.println("Delete failed");
t1.deleteOnExit();
}
if (!t2.delete()) {
System.err.println("Delete failed");
t2.deleteOnExit();
}
}
} catch (IOException e) {
Expand Down

0 comments on commit 57e4217

Please sign in to comment.