Class FileCompare

java.lang.Object
org.daisy.braille.tools.FileCompare

public class FileCompare extends Object
Provides functionality to check if files are equal. Both binary and a looser XML-file compare are provided.
Author:
Joel HÃ¥kansson
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new FileCompare object
    FileCompare(boolean keepTempFiles)
    Creates a new FileCompare object
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Compares the input streams binary.
    boolean
    Compare the input streams as XML.
    Gets the intermediary file created from the first argument of the latest call to compareXML (as base for the post normalization binary compare).
    Gets the intermediary file created from the second argument of the latest call to compareXML (as base for the post normalization binary compare).
    int
    Gets the byte position where the latest call to compareBinary or compareXML failed, or -1 if compare was successful

    Methods inherited from class java.lang.Object

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

    • FileCompare

      public FileCompare()
      Creates a new FileCompare object
    • FileCompare

      public FileCompare(boolean keepTempFiles)
      Creates a new FileCompare object
      Parameters:
      keepTempFiles -
  • Method Details

    • compareXML

      public boolean compareXML(InputStream f1, InputStream f2) throws IOException, TransformerException
      Compare the input streams as XML. THe files are considered equal if they are binary equal once transformed through the same transparent XSLT (whitespace is normalized on text nodes) using the same transformer implementation.
      Parameters:
      f1 - the first input stream
      f2 - the second input stream
      Returns:
      returns true if the streams are equal, false otherwise
      Throws:
      IOException - if IO fails
      TransformerException - if transformation fails
    • getFileOne

      public File getFileOne()
      Gets the intermediary file created from the first argument of the latest call to compareXML (as base for the post normalization binary compare).
      Returns:
      returns the first file
      Throws:
      IllegalStateException - if temporary files are not kept or if compareXML has not been called.
    • getFileTwo

      public File getFileTwo()
      Gets the intermediary file created from the second argument of the latest call to compareXML (as base for the post normalization binary compare).
      Returns:
      returns the second file
      Throws:
      IllegalStateException - if temporary files are not kept or if compareXML has not been called.
    • getPos

      public int getPos()
      Gets the byte position where the latest call to compareBinary or compareXML failed, or -1 if compare was successful
      Returns:
      returns the byte position
    • compareBinary

      public boolean compareBinary(InputStream f1, InputStream f2) throws IOException
      Compares the input streams binary.
      Parameters:
      f1 - the first input stream
      f2 - the second input stream
      Returns:
      returns true if the streams are equal, false otherwise
      Throws:
      IOException - if IO fails