Skip to Content

Extract Zip File With Adler32 Checksum 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.         Extract Zip File With Adler32 Checksum Example
  3.         This Java example shows how to extract zip file with Adler32 Checksum
  4.         using CheckedInputStream and CRC32 classes.
  5. */
  6.  
  7. import java.io.FileInputStream;
  8. import java.io.FileOutputStream;
  9. import java.io.IOException;
  10. import java.io.OutputStream;
  11. import java.util.zip.Adler32;
  12. import java.util.zip.CheckedInputStream;
  13. import java.util.zip.ZipEntry;
  14. import java.util.zip.ZipInputStream;
  15.  
  16. public class ExtractZipWithAdler32Checksum {
  17.  
  18.         public static void main(String args[])
  19.         {
  20.                
  21.                 String sourceZipFile = "C:/FileIO/sourceFile.zip";
  22.                
  23.                 try
  24.                 {
  25.                         //create FileInputStream from the source zip file
  26.                         FileInputStream fin = new FileInputStream(sourceZipFile);
  27.                        
  28.                         /*
  29.                          * To extract zip file with Adler32 checksum, use
  30.                          *
  31.                          * CheckedInputStream(InputStream in, Checksum checksum)
  32.                          *
  33.                          * Constructor.
  34.                          */
  35.                          
  36.                          //create CheckedInputStream object.
  37.                          CheckedInputStream checksum = new CheckedInputStream(fin,new Adler32());
  38.                          
  39.                         //create ZipInputStream from CheckedInputStream object
  40.                         ZipInputStream zin = new ZipInputStream(checksum);
  41.                        
  42.                         //get the first entry from the source zip file
  43.                         ZipEntry entry = zin.getNextEntry();
  44.                        
  45.                         //crate OutputStream to extract the entry from zip file
  46.                         OutputStream os = new FileOutputStream("c:/extractedFile.css");
  47.                        
  48.                        
  49.                         byte[] buffer = new byte[1024];
  50.                         int length;
  51.                        
  52.                         //read the entry from zip file and extract it to disk
  53.                         while( (length = zin.read(buffer)) > 0)
  54.                         {
  55.                                 os.write(buffer, 0, length);
  56.                         }
  57.                        
  58.                         //close the streams
  59.                         os.close();
  60.                        
  61.                         //close the zip file
  62.                         zin.close();
  63.                        
  64.                         System.out.println("File Extracted from zip file");
  65.                        
  66.                         /*
  67.                          * To get the CRC32 checksum of the extracted file, use
  68.                          *
  69.                          * Checksum getChecksum()
  70.                          *
  71.                          * Method of CheckedInputStream class.
  72.                          */
  73.                          
  74.                          System.out.println("Adler32 checksum is: " + checksum.getChecksum().getValue());
  75.                          
  76.                 }
  77.                 catch(IOException e)
  78.                 {
  79.                         System.out.println("IOException :" + e);
  80.                 }
  81.                
  82.         }
  83.  
  84. }
  85.  
  86. /*
  87. Output of this example would be
  88. File Extracted from zip file
  89. Adler32 checksum is: 3726768657
  90. */