Skip to Content

Generate CRC32 Checksum For Byte Array 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.         Generate CRC32 Checksum For Byte Array Example
  3.         This Java example shows how to get the CRC32 checksum value for
  4.         array of bytes using CRC32 Java class.
  5. */
  6.  
  7. import java.util.zip.CRC32;
  8. import java.util.zip.Checksum;
  9.  
  10. public class CalculateCRC32ForByteArray {
  11.        
  12.         public static void main(String args[]){
  13.                
  14.                 String str = "Generate CRC32 Checksum For Byte Array Example";
  15.                
  16.                 //Convert string to bytes
  17.                 byte bytes[] = str.getBytes();
  18.                
  19.                 Checksum checksum = new CRC32();
  20.                
  21.                 /*
  22.                  * To compute the CRC32 checksum for byte array, use
  23.                  *
  24.                  * void update(bytes[] b, int start, int length)
  25.                  * method of CRC32 class.
  26.                  */
  27.                  
  28.                 checksum.update(bytes,0,bytes.length);
  29.                
  30.                 /*
  31.                  * Get the generated checksum using
  32.                  * getValue method of CRC32 class.
  33.                  */
  34.                 long lngChecksum = checksum.getValue();
  35.                
  36.                 System.out.println("CRC32 checksum for byte array is :" + lngChecksum);
  37.         }
  38.  
  39. }
  40.  
  41. /*
  42. Output of this program would be
  43. CRC32 checksum for byte array is :3510043186
  44. */