reset ( )源码实例Demo

java.util.zip.Adler32#reset ( )源码实例Demo

下面列出了java.util.zip.Adler32#reset ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: j2objc   文件: Adler32Test.java
/**
 * 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());
}
 
源代码2 项目: j2objc   文件: Adler32Test.java
/**
 * 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());

}
 
源代码3 项目: j2objc   文件: Adler32Test.java
/**
 * 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());

}
 
源代码4 项目: jtransc   文件: MiscTest.java
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());
}
 
源代码5 项目: j2objc   文件: Adler32Test.java
/**
 * 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());
}
 
源代码6 项目: j2objc   文件: OldAndroidChecksumTest.java
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);
}
 
源代码7 项目: j2objc   文件: OldAndroidChecksumTest.java
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());
}
 
源代码8 项目: openjdk-jdk9   文件: TestAdler32.java
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("-------------------------------------------------------");
}
 
源代码评论
动弹
沙发等你来抢
 方法所在类