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