How to generate hash code of Zip file.


 

How to generate hash code of Zip file.

In this tutorial you will see how to generate hash code of Zip file.

In this tutorial you will see how to generate hash code of Zip file.

How to generate hash code of Zip file.

In this tutorial, we will see how to generate hash code of zip file entries. The ZipFile  
class is used to read entries of zip files. The entries() methods of ZipFile class returns 
enumeration of zip file entries. The hashCode() method of ZipFile class returns hash 
code of associated entry. The hasMoreElements() of Enumeration class check the
 availability of more entries in zip file, and nextElement() method returns next 
element of entry.

About ZipFile API:

The java.util.zip.ZipFile class extends java.io.FilterIntputStream class. It 
provides the following methods:

Return Type Method Description 
int hashCode() The hashCode() method returns hash code of associated method.
enumeration entries() The entries() method returns enumeration of entries of zip file. 

code

import java.io.*;
import java.util.zip.*;
import java.util.zip.ZipFile;
import java.util.zip.ZipEntry;
import java.util.Enumeration;
import java.io.IOException;

public class ZipHashCode {
  public static void main(String args[]) {
    try {
      ZipFile zipName = new ZipFile("test.zip");
      Enumeration enumEntries = zipName.entries();
      while (enumEntries.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntryenumEntries.nextElement();
        String zipEntryName = zipEntry.getName();
        int hCode = zipEntry.hashCode();
System.out.println("\tName of Zip file : " + zipEntryName);
     System.out.print("\tHashCode Of Zip File : " + hCode);
      }
      zipName.close();
    catch (IOException ioe) {
      System.out.println("IOException : " + ioe);
    }
  }
}

Following is the output if you run the application

C:\>java ZipHashCode
Name of Zip file : bharat.txt
HashCode Of Zip File : 1455566828

Download this code

Ads