com.ccg.io
Class Compare

java.lang.Object
  extended by com.ccg.io.Compare

public class Compare
extends Object

Some static methods to aid in the comparison of files.

This class provides some helper methods related to comparison of files (or streams of information).

Since:
1.0
Version:
$Revision: 1.1.1.1 $
Author:
$Author: pkb $

Constructor Summary
Compare()
           
 
Method Summary
static long fileToFile(File from, File to)
          Compares the contents of one File to another File.
static long fileToStream(File from, InputStream to)
          Compares the contents of a File to a InputStream.
static long streamToFile(InputStream from, File to)
          Compares the contents of a InputStream to a File.
static long streamToStream(InputStream from, InputStream to)
          Compares contents of a InputStream to anoterh InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Compare

public Compare()
Method Detail

streamToStream

public static long streamToStream(InputStream from,
                                  InputStream to)
                           throws IOException
Compares contents of a InputStream to anoterh InputStream.

This method uses buffered stream wrappers around the streams passed to compare data from one stream to the other. After it finishes the compare (even it an exception occurs) an attempt will be made to close BOTH streams.

Parameters:
from - The InputStream to compare data from (must not be null).
to - The InputStream to compare data to (must not be null).
Returns:
The position in the two streams where a difference was first encountered (or -1 if streams were identical).
Throws:
IOException - If there is a problem compareing the data or closing one of the files (both files will be closed prior to throwing the exception).
Since:
1.0
See Also:
streamToFile(java.io.InputStream, java.io.File), fileToStream(java.io.File, java.io.InputStream), fileToFile(java.io.File, java.io.File)

streamToFile

public static long streamToFile(InputStream from,
                                File to)
                         throws IOException
Compares the contents of a InputStream to a File. This method converts the File object passed into a InputStream and then invokes streamToStream(java.io.InputStream, java.io.InputStream) to compare the data from the stream to the file.

Parameters:
from - The InputStream to compare data from (must not be null).
to - The File to compare data to (must not be null).
Returns:
The position in the two streams where a difference was first encountered (or -1 if streams were identical).
Throws:
IOException - If there is a problem compareing the data or closing one of the files (both files will be closed prior to throwing the exception).
Since:
1.0
See Also:
streamToStream(java.io.InputStream, java.io.InputStream)

fileToStream

public static long fileToStream(File from,
                                InputStream to)
                         throws IOException
Compares the contents of a File to a InputStream. This method converts the File object passed into a InputStream and then invokes streamToStream(java.io.InputStream, java.io.InputStream) to compare the data from the file to the stream.

Parameters:
from - The File to compare the data from (must not be null).
to - The InputStream to compare data fo (must not be null).
Returns:
The position in the two streams where a difference was first encountered (or -1 if streams were identical).
Throws:
IOException - If there is a problem compareing the data or closing one of the files (both files will be closed prior to throwing the exception).
Since:
1.0
See Also:
streamToStream(java.io.InputStream, java.io.InputStream)

fileToFile

public static long fileToFile(File from,
                              File to)
                       throws IOException
Compares the contents of one File to another File.

This method determines the position within two files. Before comparing the contents of the two files, this method checks to see if the two File objects are equal (refer to the same file). If the two file objects are the same, then no comparision is done (returns -1 immediately).

Parameters:
from - The File to compare the data from (must not be null).
to - The File to compare data to (must not be null).
Returns:
The position in the two streams where a difference was first encountered (or -1 if streams were identical).
Throws:
IOException - If there is a problem compareing the data or closing one of the files (both files will be closed prior to throwing the exception).
Since:
1.0
See Also:
streamToStream(java.io.InputStream, java.io.InputStream)


Copyright 1998-1998-2006 null. All Rights Reserved.