Skip to Content

Get Uncompressed Size of Zip Entry Example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.         Get Uncompressed Size of Zip Entry Example
  3.         This Java example shows how to get uncompressed size of particular entry
  4.         (i.e. file or directory) using getSize method of
  5.         Java ZipEntry class.
  6. */
  7.  
  8. import java.io.File;
  9. import java.io.IOException;
  10. import java.util.Enumeration;
  11. import java.util.zip.ZipEntry;
  12. import java.util.zip.ZipFile;
  13.  
  14. public class GetUncompressedSize {
  15.        
  16.         public static void main(String args[])
  17.         {                
  18.                 try
  19.                 {
  20.                    /*
  21.                         * To Open a zip file, use
  22.                         *
  23.                         * ZipFile(String fileName)
  24.                         * constructor of the ZipFile class.
  25.                         *
  26.                         * This constructor throws IOException for any I/O error.
  27.                         */
  28.                    ZipFile zipFile = new ZipFile("c:/FileIO/WebFiles.zip");
  29.                    
  30.                    /*
  31.                         * Get list of zip entries using entries method of
  32.                         * ZipFile class.
  33.                         */
  34.                    
  35.                         Enumeration e = zipFile.entries();
  36.                        
  37.                         System.out.print("File Name");
  38.                         System.out.print("\t\tUncompressed Size");
  39.                         System.out.println("\t\tCompressed Size");
  40.                        
  41.                         System.out.println("---------------------------------");
  42.                        
  43.                         while(e.hasMoreElements())
  44.                         {
  45.                                 ZipEntry entry = (ZipEntry)e.nextElement();
  46.                                
  47.                                 /*
  48.                                  * To get uncompressed size of zip entry, use
  49.                                  *
  50.                                  * long getSize()
  51.                                  * method of ZipEntry class.
  52.                                  *
  53.                                  * This method returns the size of uncompressed entry or -1
  54.                                  * if the size is not known.
  55.                                  *
  56.                                  * PLEASE NOTE that uncompressed size and compressed size
  57.                                  * of the zip entries created using ZipEntry.STORED method
  58.                                  * will be same.
  59.                                  *
  60.                                  * However, It differes for zip entries created using
  61.                                  * ZipEntry.DEFLATED entries.
  62.                                  */
  63.                                  String entryName = entry.getName();
  64.                                  long originalSize = entry.getSize();
  65.                                  long compressedSize = entry.getCompressedSize();
  66.                                  
  67.                                  System.out.print(entryName);
  68.                                  System.out.print("\t\t" + originalSize);
  69.                                  System.out.print("\t\t" + compressedSize);
  70.                                  System.out.print("\n");
  71.  
  72.                                  
  73.                                                                
  74.                         }
  75.                  
  76.                          /*
  77.                           * close the opened zip file using,
  78.                           * void close()
  79.                           * method.
  80.                           */
  81.                          
  82.                           zipFile.close();
  83.                        
  84.                  }
  85.                  catch(IOException ioe)
  86.                  {
  87.                         System.out.println("Error opening zip file" + ioe);
  88.                  }
  89.         }
  90.  
  91. }
  92.  
  93. /*
  94. Output of this program would be
  95. File Name               Uncompressed Size               Compressed Size
  96. ---------------------------------
  97. css/datagrid.css                26939           3255
  98. css/graph.css                   2412            416
  99. jsps/Masthead.jspf              1200            536
  100. jsps/Welcome.jsp                3062            1248
  101. */