zipdiff
Class DifferenceCalculator

java.lang.Object
  extended byzipdiff.DifferenceCalculator

public class DifferenceCalculator
extends java.lang.Object

Checks and compiles differences between two zip files. It also has the ability to exclude entries from the comparison based on a regular expression.

Author:
Sean C. Sullivan

Constructor Summary
DifferenceCalculator(java.io.File f1, java.io.File f2)
          Constructor taking 2 Files to compare
DifferenceCalculator(java.lang.String filename1, java.lang.String filename2)
          Constructor taking 2 filenames to compare
DifferenceCalculator(java.util.zip.ZipFile zf1, java.util.zip.ZipFile zf2)
          Constructor taking 2 ZipFiles to compare
 
Method Summary
protected  java.util.Map buildZipEntryMap(java.util.zip.ZipFile zf)
          Opens the ZipFile and builds up a map of all the entries.
protected  Differences calculateDifferences(java.util.Map m1, java.util.Map m2)
          Given two Maps of ZipEntries it will generate a Differences of all the differences found between the two maps.
protected  Differences calculateDifferences(java.util.zip.ZipFile zf1, java.util.zip.ZipFile zf2)
          Calculates all the differences between two zip files.
protected  void debug(java.lang.Object msg)
           
protected  boolean entriesMatch(java.util.zip.ZipEntry entry1, java.util.zip.ZipEntry entry2)
          returns true if the two entries are equivalent in type, name, size, compressed size and time or CRC.
 boolean getCompareCRCValues()
           
 Differences getDifferences()
           
 boolean ignoreCVSFiles()
           
protected  boolean ignoreThisFile(java.lang.String filepath, java.lang.String entryName)
          returns true if fileToIgnorePattern matches the filename given.
protected  boolean isCVSFile(java.lang.String filepath, java.lang.String entryName)
           
 boolean isIgnoringTimestamps()
           
protected  boolean isVerboseEnabled()
           
static boolean isZipFile(java.lang.String filename)
          Returns true if the filename has a valid zip extension.
protected  void processEmbeddedZipFile(java.lang.String prefix, java.io.InputStream is, java.util.Map m)
           
protected  void processZipEntry(java.lang.String prefix, java.util.zip.ZipEntry zipEntry, java.io.InputStream is, java.util.Map zipEntryMap)
          Will place ZipEntries for a given ZipEntry into the given Map.
 void setCompareCRCValues(boolean b)
          Ensure that the comparison checks against the CRCs of the entries.
 void setFilenameRegexToIgnore(java.util.Set patterns)
           
 void setIgnoreCVSFiles(boolean b)
           
 void setIgnoreTimestamps(boolean b)
           
 void setVerbose(boolean b)
          Set the verboseness of the debug output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DifferenceCalculator

public DifferenceCalculator(java.lang.String filename1,
                            java.lang.String filename2)
                     throws java.io.IOException
Constructor taking 2 filenames to compare

Throws:
java.io.IOException

DifferenceCalculator

public DifferenceCalculator(java.io.File f1,
                            java.io.File f2)
                     throws java.io.IOException
Constructor taking 2 Files to compare

Throws:
java.io.IOException

DifferenceCalculator

public DifferenceCalculator(java.util.zip.ZipFile zf1,
                            java.util.zip.ZipFile zf2)
Constructor taking 2 ZipFiles to compare

Method Detail

debug

protected void debug(java.lang.Object msg)

setVerbose

public void setVerbose(boolean b)
Set the verboseness of the debug output.

Parameters:
b - true to make verbose

isVerboseEnabled

protected boolean isVerboseEnabled()

setFilenameRegexToIgnore

public void setFilenameRegexToIgnore(java.util.Set patterns)
See Also:
java.util.regex

ignoreThisFile

protected boolean ignoreThisFile(java.lang.String filepath,
                                 java.lang.String entryName)
returns true if fileToIgnorePattern matches the filename given.

Parameters:
filepath -
Returns:
true if the file should be ignored.

isCVSFile

protected boolean isCVSFile(java.lang.String filepath,
                            java.lang.String entryName)

setCompareCRCValues

public void setCompareCRCValues(boolean b)
Ensure that the comparison checks against the CRCs of the entries.

Parameters:
b - true ensures that CRCs will be checked

getCompareCRCValues

public boolean getCompareCRCValues()
Returns:
true if this instance will check the CRCs of each ZipEntry

buildZipEntryMap

protected java.util.Map buildZipEntryMap(java.util.zip.ZipFile zf)
                                  throws java.io.IOException
Opens the ZipFile and builds up a map of all the entries. The key is the name of the entry and the value is the ZipEntry itself.

Parameters:
zf - The ZipFile for which to build up the map of ZipEntries
Returns:
The map containing all the ZipEntries. The key being the name of the ZipEntry.
Throws:
java.io.IOException

processZipEntry

protected void processZipEntry(java.lang.String prefix,
                               java.util.zip.ZipEntry zipEntry,
                               java.io.InputStream is,
                               java.util.Map zipEntryMap)
                        throws java.io.IOException
Will place ZipEntries for a given ZipEntry into the given Map. More ZipEntries will result if zipEntry is itself a ZipFile. All embedded ZipFiles will be processed with their names prefixed onto the names of their ZipEntries.

Parameters:
prefix - The prefix of the ZipEntry that should be added to the key. Typically used when processing embedded ZipFiles. The name of the embedded ZipFile would be the prefix of all the embedded ZipEntries.
zipEntry - The ZipEntry to place into the Map. If it is a ZipFile then all its ZipEntries will also be placed in the Map.
is - The InputStream of the corresponding ZipEntry.
zipEntryMap - The Map in which to place all the ZipEntries into. The key will be the name of the ZipEntry.
Throws:
java.io.IOException

processEmbeddedZipFile

protected void processEmbeddedZipFile(java.lang.String prefix,
                                      java.io.InputStream is,
                                      java.util.Map m)
                               throws java.io.IOException
Throws:
java.io.IOException

isZipFile

public static boolean isZipFile(java.lang.String filename)
Returns true if the filename has a valid zip extension. i.e. jar, war, ear, zip etc.

Parameters:
filename - The name of the file to check.
Returns:
true if it has a valid extension.

calculateDifferences

protected Differences calculateDifferences(java.util.zip.ZipFile zf1,
                                           java.util.zip.ZipFile zf2)
                                    throws java.io.IOException
Calculates all the differences between two zip files. It builds up the 2 maps of ZipEntries for the two files and then compares them.

Parameters:
zf1 - The first ZipFile to compare
zf2 - The second ZipFile to compare
Returns:
All the differences between the two files.
Throws:
java.io.IOException

calculateDifferences

protected Differences calculateDifferences(java.util.Map m1,
                                           java.util.Map m2)
Given two Maps of ZipEntries it will generate a Differences of all the differences found between the two maps.

Returns:
All the differences found between the two maps

entriesMatch

protected boolean entriesMatch(java.util.zip.ZipEntry entry1,
                               java.util.zip.ZipEntry entry2)
returns true if the two entries are equivalent in type, name, size, compressed size and time or CRC.

Parameters:
entry1 - The first ZipEntry to compare
entry2 - The second ZipEntry to compare
Returns:
true if the entries are equivalent.

setIgnoreTimestamps

public void setIgnoreTimestamps(boolean b)

isIgnoringTimestamps

public boolean isIgnoringTimestamps()

ignoreCVSFiles

public boolean ignoreCVSFiles()

setIgnoreCVSFiles

public void setIgnoreCVSFiles(boolean b)

getDifferences

public Differences getDifferences()
                           throws java.io.IOException
Returns:
all the differences found between the two zip files.
Throws:
java.io.IOException


Copyright © 2004 zipdiff.sourceforge.net. All Rights Reserved.