List of usage examples for java.util.zip ZipEntry getCompressedSize
public long getCompressedSize()
From source file:Main.java
public static void main(String[] args) throws Exception { String zipname = "data.zip"; ZipFile zipFile = new ZipFile(zipname); Enumeration enumeration = zipFile.entries(); while (enumeration.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) enumeration.nextElement(); System.out.println(zipEntry.getCompressedSize()); }//from w w w.java 2 s . c om }
From source file:Main.java
public static void main(String[] args) throws Exception { ZipFile zip = new ZipFile(new File("sample.zip")); for (Enumeration e = zip.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); System.out.println("File name: " + entry.getName() + "; size: " + entry.getSize() + "; compressed size: " + entry.getCompressedSize()); InputStream is = zip.getInputStream(entry); InputStreamReader isr = new InputStreamReader(is); char[] buffer = new char[1024]; while (isr.read(buffer, 0, buffer.length) != -1) { String s = new String(buffer); System.out.println(s.trim()); }/* w ww . j a v a 2 s . c o m*/ } }
From source file:Main.java
public static void main(String[] args) throws Exception { ZipFile zf = new ZipFile("a.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); String name = ze.getName(); long uncompressedSize = ze.getSize(); long compressedSize = ze.getCompressedSize(); long crc = ze.getCrc(); int method = ze.getMethod(); String comment = ze.getComment(); System.out.println(name + " was stored at " + new Date(ze.getTime())); if (method == ZipEntry.STORED) { System.out.println("with a size of " + uncompressedSize + " bytes"); } else if (method == ZipEntry.DEFLATED) { System.out.println("from " + uncompressedSize + " bytes to " + compressedSize); } else {/* w w w .j a v a 2 s . co m*/ System.out.println("from " + uncompressedSize + " bytes to " + compressedSize); } System.out.println("Its CRC is " + crc); if (comment != null && !comment.equals("")) { System.out.println(comment); } if (ze.isDirectory()) { System.out.println(name + " is a directory"); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { ZipFile zf = new ZipFile("a.zip"); Enumeration<? extends ZipEntry> files = zf.entries(); while (files.hasMoreElements()) { ZipEntry ze = files.nextElement(); System.out.println("Decompressing " + ze.getName()); System.out.println(/*from ww w . ja v a 2 s .com*/ " Compressed Size: " + ze.getCompressedSize() + " Expanded Size: " + ze.getSize() + "\n"); BufferedInputStream fin = new BufferedInputStream(zf.getInputStream(ze)); BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(ze.getName())); int i; do { i = fin.read(); if (i != -1) fout.write(i); } while (i != -1); fout.close(); fin.close(); } zf.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ZipFile zf = new ZipFile("your.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); String name = ze.getName(); Date lastModified = new Date(ze.getTime()); long uncompressedSize = ze.getSize(); long compressedSize = ze.getCompressedSize(); int method = ze.getMethod(); if (method == ZipEntry.STORED) { System.out.println(name + " was stored at " + lastModified); System.out.println("with a size of " + uncompressedSize + " bytes"); } else if (method == ZipEntry.DEFLATED) { System.out.println(name + " was deflated at " + lastModified); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%"); } else {//w w w .j a va 2s .c om System.out.println(name + " was compressed at " + lastModified); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%"); } } }
From source file:MainClass.java
public static void main(String[] args) { try {//from w ww .j a v a2s .c om ZipFile zf = new ZipFile("your.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); String name = ze.getName(); Date lastModified = new Date(ze.getTime()); long uncompressedSize = ze.getSize(); long compressedSize = ze.getCompressedSize(); System.out.println(name); System.out.println(lastModified); System.out.println(uncompressedSize); System.out.println(compressedSize); } } catch (IOException ex) { System.err.println(ex); } }
From source file:MainClass.java
public static void main(String[] args) { try {/*w w w .ja va 2s .co m*/ ZipFile zf = new ZipFile("your.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); String name = ze.getName(); Date lastModified = new Date(ze.getTime()); long uncompressedSize = ze.getSize(); long compressedSize = ze.getCompressedSize(); int method = ze.getMethod(); if (method == ZipEntry.STORED) { System.out.println(name + " was stored at " + lastModified); System.out.println("with a size of " + uncompressedSize + " bytes"); } else if (method == ZipEntry.DEFLATED) { System.out.println(name + " was deflated at " + lastModified); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%"); } else { System.out.println(name + " was compressed using an unrecognized method at " + lastModified); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%"); } } } catch (IOException ex) { System.err.println(ex); } }
From source file:Main.java
public static void main(String args[]) throws Exception { ZipOutputStream fout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(args[0]))); for (int n = 1; n < args.length; n++) { BufferedInputStream fin = new BufferedInputStream(new FileInputStream(args[n])); ZipEntry ze = new ZipEntry(rmPath(args[n])); fout.putNextEntry(ze);// w w w . j a va 2 s. co m int i; do { i = fin.read(); if (i != -1) fout.write(i); } while (i != -1); fout.closeEntry(); fin.close(); System.out.println("Compressing " + args[n]); System.out.println( " Original Size: " + ze.getSize() + " Compressed Size: " + ze.getCompressedSize() + "\n"); } fout.close(); }
From source file:org.mycontroller.standalone.backup.Restore.java
private static void extractZipFile(String zipFileName, String destination) throws FileNotFoundException, IOException { ZipFile zipFile = new ZipFile(zipFileName); Enumeration<?> enu = zipFile.entries(); //create destination if not exists FileUtils.forceMkdir(FileUtils.getFile(destination)); while (enu.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) enu.nextElement(); String name = zipEntry.getName(); long size = zipEntry.getSize(); long compressedSize = zipEntry.getCompressedSize(); _logger.debug("name:{} | size:{} | compressed size:{}", name, size, compressedSize); File file = FileUtils.getFile(destination + File.separator + name); //Create destination if it's not available if (name.endsWith(File.separator)) { file.mkdirs();//from www. j a va 2 s .com continue; } File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } InputStream is = zipFile.getInputStream(zipEntry); FileOutputStream fos = new FileOutputStream(file); byte[] bytes = new byte[1024]; int length; while ((length = is.read(bytes)) >= 0) { fos.write(bytes, 0, length); } is.close(); fos.close(); } zipFile.close(); }
From source file:org.mycontroller.standalone.BackupRestore.java
private static void extractZipFile(String zipFileName, String destination) throws FileNotFoundException, IOException { ZipFile zipFile = new ZipFile(zipFileName); Enumeration<?> enu = zipFile.entries(); //create destination if not exists FileUtils.forceMkdir(FileUtils.getFile(destination)); while (enu.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) enu.nextElement(); String name = zipEntry.getName(); long size = zipEntry.getSize(); long compressedSize = zipEntry.getCompressedSize(); _logger.debug("name:{} | size:{} | compressed size:{}", name, size, compressedSize); File file = FileUtils.getFile(destination + "/" + name); //Create destination if it's not available if (name.endsWith("/")) { file.mkdirs();/*from w ww. j a v a 2 s .co m*/ continue; } File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } InputStream is = zipFile.getInputStream(zipEntry); FileOutputStream fos = new FileOutputStream(file); byte[] bytes = new byte[1024]; int length; while ((length = is.read(bytes)) >= 0) { fos.write(bytes, 0, length); } is.close(); fos.close(); } zipFile.close(); }