Skip to Content

Get Compression Method 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 Compression Method of Zip Entry Example
  3.         This Java example shows how to get compression method used to
  4.         compress the entry using getMethod method of Java ZipEntry class.
  5. */
  6.  
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.util.Enumeration;
  10. import java.util.zip.ZipEntry;
  11. import java.util.zip.ZipFile;
  12.  
  13.  
  14. public class GetCompressionMethod {
  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.println("File Name\t\t\t\tCompression Method");
  38.                         System.out.println("---------------------------------");
  39.                        
  40.                         while(e.hasMoreElements())
  41.                         {
  42.                                 ZipEntry entry = (ZipEntry)e.nextElement();
  43.                                
  44.                                 /*
  45.                                  * To get compression method used to compress entry, use
  46.                                  *
  47.                                  * int getMethod()
  48.                                  * method of ZipEntry class.
  49.                                  *
  50.                                  * This method returns the method of compression, or -1
  51.                                  * if not specified.
  52.                                  *
  53.                                  * Compression method can be either STORED or DEFLATED for
  54.                                  * any zip entry.
  55.                                  */                              
  56.                                  
  57.                                  int method = entry.getMethod();
  58.                                  
  59.                                  if(method == ZipEntry.DEFLATED)
  60.                                         System.out.println(entry.getName() + "\t\t\t\tDeflated");
  61.                                  else if(method == ZipEntry.STORED)
  62.                                         System.out.println(entry.getName() + "\t\t\t\tStored");
  63.                                  else if(method == -1)
  64.                                         System.out.println(entry.getName() + "\t\t\t\tNot Specified");
  65.                                                                
  66.                         }
  67.                  
  68.                          /*
  69.                           * close the opened zip file using,
  70.                           * void close()
  71.                           * method.
  72.                           */
  73.                          
  74.                           zipFile.close();
  75.                        
  76.                  }
  77.                  catch(IOException ioe)
  78.                  {
  79.                         System.out.println("Error opening zip file" + ioe);
  80.                  }
  81.         }
  82.  
  83. }
  84.  
  85. /*
  86. Output of this program would be
  87. File Name                               Compression Method
  88. ---------------------------------
  89. css/datagrid.css                                Deflated
  90. css/graph.css                                   Deflated
  91. jsps/Masthead.jspf                              Deflated
  92. jsps/Welcome.jsp                                Deflated
  93. */