net.sf.zig_project.gpl.simulation
Class IoCompare

java.lang.Object
  extended bynet.sf.zig_project.gpl.simulation.IoCompare

public abstract class IoCompare
extends Object

Library of functions designed to do simple (true / false) comparison operations on files and streams.

Version:
March 20, 2005
Author:
Frank Ziglar

Constructor Summary
IoCompare()
           
 
Method Summary
static boolean fileCompare(File f1, File f2)
          This method checks two files to determine if their contents are equal.
static boolean readerCompare(Reader r1, Reader r2)
          Checks two readers for equality.
static InputStream stream(File f)
          Convenience method to open a stream to a File.
static boolean streamCompare(InputStream i1, InputStream i2)
          Checks two streams for equality.
static boolean subStreamCompare(InputStream i1, InputStream i2, long len)
          Checks a fragment of two streams for equality.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IoCompare

public IoCompare()
Method Detail

fileCompare

public static boolean fileCompare(File f1,
                                  File f2)
                           throws IOException
This method checks two files to determine if their contents are equal. Equal, is determined as:
  1. Both files must either be existing or non-existing
  2. Both files must either represent a data file or a directory
  3. If the files are directories, they must share all the same contents, which are each checked recursively with the same definition for equality.
  4. Otherwise, (if the files are data files) they must be mirrors of each other.
While this method does not check the names of the file arguments, the names of contents within a directory are expected to be equal. Further, this algorithm does not yet take into consideration file systems that consider file names written in different cases as the same file. (More directly, this routine checks directory contents by file name, and is case sensative.)

Returns:
true only if the files are equal
Throws:
IOException

streamCompare

public static boolean streamCompare(InputStream i1,
                                    InputStream i2)
                             throws IOException
Checks two streams for equality. In order to be equal they should
  1. return the same data
  2. terminate in the same position (have the same length)
Once a stream has been exhausted, an attempt is made to automatically close both streams. It is recommended that both streams be buffered.

Throws:
IOException

subStreamCompare

public static boolean subStreamCompare(InputStream i1,
                                       InputStream i2,
                                       long len)
                                throws IOException
Checks a fragment of two streams for equality. The substreams are defined as equal if they
  1. return the same sequence data
  2. terminate in the same place (have the same length), or both have a minimum length of len bytes.
Unlike streamCompare(InputStream, InputStream), this method will not attempt to automatically close the streams, even if they have been exhausted. It is recommended that both streams be buffered.

Throws:
IOException

readerCompare

public static boolean readerCompare(Reader r1,
                                    Reader r2)
                             throws IOException
Checks two readers for equality. In order to be equal they should
  1. return the same data
  2. terminate in the same position (have the same length)
Once a reader has been exhausted, an attempt is made to automatically close both streams. It is recommended that both readers be buffered.

Throws:
IOException

stream

public static InputStream stream(File f)
                          throws IOException
Convenience method to open a stream to a File. This method does little more than open a FileInputStream, and wrap it in a BufferedInputStream, but using this method makes the process look a little cleaner.

Throws:
IOException