Created
July 22, 2013 13:26
-
-
Save chatman/6053783 to your computer and use it in GitHub Desktop.
Test for ZipEntry's getMethod. (http://www.roseindia.net/tutorial/java/corejava/zip/ZipGetMethod.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.zip.*; | |
import java.io.*; | |
import java.util.Enumeration; | |
import java.util.zip.ZipFile; | |
import java.util.zip.ZipEntry; | |
public class ZipGetMethod { | |
public static void main(String[] args) { | |
String file = "moby.zip"; | |
try { | |
ZipFile zipfile = new ZipFile(file); | |
Enumeration e = zipfile.entries(); | |
while (e.hasMoreElements()) { | |
ZipEntry zipentry = (ZipEntry) e.nextElement(); | |
String entryName = zipentry.getName(); | |
Date lastModify = new Date(zipentry.getTime()); | |
long uncomSize = zipentry.getSize(); | |
long comSize = zipentry.getCompressedSize(); | |
if ((zipentry.getMethod()) == ZipEntry.STORED) { | |
System.out.println("The entry Nmae " + entryName | |
+ " was stored at " + lastModify); | |
System.out.println("with a size of " + uncomSize | |
+ " bytes"); | |
System.out.println(" "); | |
} else if ((zipentry.getMethod()) == ZipEntry.DEFLATED) { | |
System.out.println("The entry Nmae " + entryName | |
+ " was deflated at " + lastModify); | |
System.out.println("Uncompressed size of entry : " | |
+ uncomSize + " bytes"); | |
System.out.println("Compressed size of entry : " + comSize | |
+ " bytes"); | |
System.out.println(" "); | |
} else { | |
System.out.println("The entry Nmae " + entryName | |
+ " was compressed, but method name not specified " | |
+ lastModify); | |
System.out.println("Uncompressed size of entry : " | |
+ uncomSize + " bytes"); | |
System.out.println("Compressed size of entry : " + comSize | |
+ " bytes"); | |
} | |
} | |
} catch (IOException ex) { | |
System.out.println("IOException is : " + ex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Produces the following output on FOCUS-4685's moby.zip.
IOException is : java.util.zip.ZipException: invalid CEN header (bad compression method)