Java Code Examples for java.util.zip.Adler32#reset()
The following examples show how to use
java.util.zip.Adler32#reset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Adler32Test.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.util.zip.Adler32#getValue() */ public void test_getValue() { // test methods of java.util.zip.getValue() Adler32 adl = new Adler32(); assertEquals("GetValue should return a zero as a result of construction an object of Adler32", 1, adl.getValue()); adl.reset(); adl.update(1); // System.out.print("value of adl"+adl.getValue()); // The value of the adl should be 131074 assertEquals("update(int) failed to update the checksum to the correct value ", 131074, adl.getValue()); adl.reset(); assertEquals("reset failed to reset the checksum value to zero", 1, adl .getValue()); adl.reset(); adl.update(Integer.MIN_VALUE); // System.out.print("value of adl " + adl.getValue()); // The value of the adl should be 65537 assertEquals("update(min) failed to update the checksum to the correct value ", 65537L, adl.getValue()); }
Example 2
Source File: Adler32Test.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.util.zip.Adler32#update(int) */ public void test_updateI() { // test methods of java.util.zip.update(int) Adler32 adl = new Adler32(); adl.update(1); // The value of the adl should be 131074 assertEquals("update(int) failed to update the checksum to the correct value ", 131074, adl.getValue()); adl.reset(); adl.update(Integer.MAX_VALUE); // System.out.print("value of adl " + adl.getValue()); // The value of the adl should be 16777472 assertEquals("update(max) failed to update the checksum to the correct value ", 16777472L, adl.getValue()); adl.reset(); adl.update(Integer.MIN_VALUE); // System.out.print("value of adl " + adl.getValue()); // The value of the adl should be 65537 assertEquals("update(min) failed to update the checksum to the correct value ", 65537L, adl.getValue()); }
Example 3
Source File: Adler32Test.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.util.zip.Adler32#update(byte[]) */ public void test_update$B() { // test method of java.util.zip.update(byte[]) byte byteArray[] = { 1, 2 }; Adler32 adl = new Adler32(); adl.update(byteArray); // System.out.print("value of adl"+adl.getValue()); // The value of the adl should be 393220 assertEquals("update(byte[]) failed to update the checksum to the correct value ", 393220, adl.getValue()); adl.reset(); byte byteEmpty[] = new byte[10000]; adl.update(byteEmpty); // System.out.print("value of adl"+adl.getValue()); // The value of the adl should be 655360001 assertEquals("update(byte[]) failed to update the checksum to the correct value ", 655360001L, adl.getValue()); }
Example 4
Source File: MiscTest.java From jtransc with Apache License 2.0 | 5 votes |
private void testAdler32() { Adler32 ad = new Adler32(); byte[] data = new byte[10000]; for (int n = 0; n < data.length; n++) data[n] = (byte) (n * n); ad.reset(); ad.update(data, 0, 10000); System.out.println(ad.getValue()); ad.update(data, 5000, 5000); System.out.println(ad.getValue()); }
Example 5
Source File: Adler32Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * java.util.zip.Adler32#reset() */ public void test_reset() { // test methods of java.util.zip.reset() Adler32 adl = new Adler32(); adl.update(1); // System.out.print("value of adl"+adl.getValue()); // The value of the adl should be 131074 assertEquals("update(int) failed to update the checksum to the correct value ", 131074, adl.getValue()); adl.reset(); assertEquals("reset failed to reset the checksum value to zero", 1, adl .getValue()); }
Example 6
Source File: OldAndroidChecksumTest.java From j2objc with Apache License 2.0 | 5 votes |
private void adler32Test(byte[] values, long expected) { Adler32 adler = new Adler32(); // try it all at once adler.update(values); assertEquals(adler.getValue(), expected); // try resetting and computing one byte at a time adler.reset(); for (int i = 0; i < values.length; i++) { adler.update(values[i]); } assertEquals(adler.getValue(), expected); }
Example 7
Source File: OldAndroidChecksumTest.java From j2objc with Apache License 2.0 | 5 votes |
private void wrongChecksumWithAdler32Test() { byte[] bytes = {1, 0, 5, 0, 15, 0, 1, 11, 0, 1}; Adler32 adler = new Adler32(); adler.update(bytes); long arrayChecksum = adler.getValue(); adler.reset(); for (int i = 0; i < bytes.length; i++) { adler.update(bytes[i]); } assertEquals("Checksums not equal: expected: " + arrayChecksum + " actual: " + adler.getValue(), arrayChecksum, adler.getValue()); }
Example 8
Source File: TestAdler32.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { int offset = Integer.getInteger("offset", 0); int msgSize = Integer.getInteger("msgSize", 512); boolean multi = false; int iters = 20000; int warmupIters = 20000; if (args.length > 0) { if (args[0].equals("-m")) { multi = true; } else { iters = Integer.valueOf(args[0]); } if (args.length > 1) { warmupIters = Integer.valueOf(args[1]); } } if (multi) { test_multi(warmupIters); return; } System.out.println(" offset = " + offset); System.out.println("msgSize = " + msgSize + " bytes"); System.out.println(" iters = " + iters); byte[] b = initializedBytes(msgSize, offset); Adler32 adler0 = new Adler32(); Adler32 adler1 = new Adler32(); Adler32 adler2 = new Adler32(); adler0.update(b, offset, msgSize); System.out.println("-------------------------------------------------------"); /* warm up */ for (int i = 0; i < warmupIters; i++) { adler1.reset(); adler1.update(b, offset, msgSize); } /* measure performance */ long start = System.nanoTime(); for (int i = 0; i < iters; i++) { adler1.reset(); adler1.update(b, offset, msgSize); } long end = System.nanoTime(); double total = (double)(end - start)/1e9; // in seconds double thruput = (double)msgSize*iters/1e6/total; // in MB/s System.out.println("Adler32.update(byte[]) runtime = " + total + " seconds"); System.out.println("Adler32.update(byte[]) throughput = " + thruput + " MB/s"); /* check correctness */ for (int i = 0; i < iters; i++) { adler1.reset(); adler1.update(b, offset, msgSize); if (!check(adler0, adler1)) break; } report("Adlers", adler0, adler1); System.out.println("-------------------------------------------------------"); ByteBuffer buf = ByteBuffer.allocateDirect(msgSize); buf.put(b, offset, msgSize); buf.flip(); /* warm up */ for (int i = 0; i < warmupIters; i++) { adler2.reset(); adler2.update(buf); buf.rewind(); } /* measure performance */ start = System.nanoTime(); for (int i = 0; i < iters; i++) { adler2.reset(); adler2.update(buf); buf.rewind(); } end = System.nanoTime(); total = (double)(end - start)/1e9; // in seconds thruput = (double)msgSize*iters/1e6/total; // in MB/s System.out.println("Adler32.update(ByteBuffer) runtime = " + total + " seconds"); System.out.println("Adler32.update(ByteBuffer) throughput = " + thruput + " MB/s"); /* check correctness */ for (int i = 0; i < iters; i++) { adler2.reset(); adler2.update(buf); buf.rewind(); if (!check(adler0, adler2)) break; } report("Adlers", adler0, adler1); System.out.println("-------------------------------------------------------"); }