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

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

源代码1 项目: ZjDroid   文件: DexWriter.java
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException {
    Adler32 a32 = new Adler32();

    byte[] buffer = new byte[4 * 1024];
    InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
    int bytesRead = input.read(buffer);
    while (bytesRead >= 0) {
        a32.update(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
    }

    // write checksum, utilizing logic in DexWriter to write the integer value properly
    OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
    DexDataWriter.writeInt(output, (int)a32.getValue());
    output.close();
}
 
源代码2 项目: database   文件: TestChecksumUtility.java
public void test_checksum04_direct() {
    
    byte[] data = new byte[100];
    r.nextBytes(data);

    Adler32 adler32 = new Adler32();
    adler32.update(data);
    final int expectedChecksum = (int) adler32.getValue();

    assertEquals(expectedChecksum, chk.checksum(ByteBuffer.wrap(data), 0,
            data.length));
    
    ByteBuffer direct = ByteBuffer.allocateDirect(data.length);
    direct.put(data);
    assertEquals(expectedChecksum, chk.checksum(direct, 0,
            data.length));
    
}
 
源代码3 项目: zjdroid   文件: DexWriter.java
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException {
    Adler32 a32 = new Adler32();

    byte[] buffer = new byte[4 * 1024];
    InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
    int bytesRead = input.read(buffer);
    while (bytesRead >= 0) {
        a32.update(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
    }

    // write checksum, utilizing logic in DexWriter to write the integer value properly
    OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
    DexDataWriter.writeInt(output, (int)a32.getValue());
    output.close();
}
 
源代码4 项目: AndroidStudyDemo   文件: PackerUtil.java
/**
 * 修改dex头,CheckSum 校验码
 * @param dexBytes
 */
private static void fixCheckSumHeader(byte[] dexBytes) {
    Adler32 adler = new Adler32();
    adler.update(dexBytes, 12, dexBytes.length - 12);//从12到文件末尾计算校验码
    long value = adler.getValue();
    int va = (int) value;
    byte[] newcs = intToByte(va);
    //高位在前,低位在前掉个个
    byte[] recs = new byte[4];
    for (int i = 0; i < 4; i++) {
        recs[i] = newcs[newcs.length - 1 - i];
        System.out.println(Integer.toHexString(newcs[i]));
    }
    System.arraycopy(recs, 0, dexBytes, 8, 4);//效验码赋值(8-11)
    System.out.println(Long.toHexString(value));
    System.out.println();
}
 
源代码5 项目: 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());

}
 
源代码6 项目: nullpomino   文件: NetDummyMode.java
/**
 * NET: Send replay data<br>
 * Game modes should implement this. However, some basic codes are already implemented in NetDummyMode.
 * @param engine GameEngine
 */
protected void netSendReplay(GameEngine engine) {
	if(netIsNetRankingSendOK(engine)) {
		NetSPRecord record = new NetSPRecord();
		record.setReplayProp(owner.replayProp);
		record.stats = new Statistics(engine.statistics);
		record.gameType = netGetGoalType();

		String strData = NetUtil.compressString(record.exportString());

		Adler32 checksumObj = new Adler32();
		checksumObj.update(NetUtil.stringToBytes(strData));
		long sChecksum = checksumObj.getValue();

		netLobby.netPlayerClient.send("spsend\t" + sChecksum + "\t" + strData + "\n");
	} else {
		netReplaySendStatus = 2;
	}
}
 
源代码7 项目: J2ME-Loader   文件: Dex.java
/**
 * Returns the checksum of all but the first 12 bytes of {@code dex}.
 */
public int computeChecksum() throws IOException {
    Adler32 adler32 = new Adler32();
    byte[] buffer = new byte[8192];
    ByteBuffer data = this.data.duplicate(); // positioned ByteBuffers aren't thread safe
    data.limit(data.capacity());
    data.position(CHECKSUM_OFFSET + CHECKSUM_SIZE);
    while (data.hasRemaining()) {
        int count = Math.min(buffer.length, data.remaining());
        data.get(buffer, 0, count);
        adler32.update(buffer, 0, count);
    }
    return (int) adler32.getValue();
}
 
源代码8 项目: buck   文件: DexFile.java
/**
 * Calculates the checksum for the {@code .dex} file in the
 * given array, and modify the array to contain it.
 *
 * @param bytes {@code non-null;} the bytes of the file
 */
private static void calcChecksum(byte[] bytes) {
    Adler32 a32 = new Adler32();

    a32.update(bytes, 12, bytes.length - 12);

    int sum = (int) a32.getValue();

    bytes[8]  = (byte) sum;
    bytes[9]  = (byte) (sum >> 8);
    bytes[10] = (byte) (sum >> 16);
    bytes[11] = (byte) (sum >> 24);
}
 
源代码9 项目: 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());
}
 
源代码10 项目: Box   文件: Dex.java
/**
 * Returns the checksum of all but the first 12 bytes of {@code dex}.
 */
public int computeChecksum() throws IOException {
    Adler32 adler32 = new Adler32();
    byte[] buffer = new byte[8192];
    ByteBuffer data = this.data.duplicate(); // positioned ByteBuffers aren't thread safe
    data.limit(data.capacity());
    data.position(CHECKSUM_OFFSET + CHECKSUM_SIZE);
    while (data.hasRemaining()) {
        int count = Math.min(buffer.length, data.remaining());
        data.get(buffer, 0, count);
        adler32.update(buffer, 0, count);
    }
    return (int) adler32.getValue();
}
 
源代码11 项目: database   文件: TestChecksumUtility.java
/**
 * Test verifies that the checksum of the buffer is being computed
 * correctly.
 */
public void test_checksum01() {
    
    byte[] data = new byte[100];
    r.nextBytes(data);

    Adler32 adler32 = new Adler32();
    adler32.update(data);
    final int expectedChecksum = (int) adler32.getValue();

    assertEquals(expectedChecksum, chk.checksum(ByteBuffer.wrap(data), 0,
            data.length));

}
 
源代码12 项目: aapt   文件: Dex.java
/**
 * Returns the checksum of all but the first 12 bytes of {@code dex}.
 */
public int computeChecksum() throws IOException {
    Adler32 adler32 = new Adler32();
    byte[] buffer = new byte[8192];
    ByteBuffer data = this.data.duplicate(); // positioned ByteBuffers aren't thread safe
    data.limit(data.capacity());
    data.position(CHECKSUM_OFFSET + CHECKSUM_SIZE);
    while (data.hasRemaining()) {
        int count = Math.min(buffer.length, data.remaining());
        data.get(buffer, 0, count);
        adler32.update(buffer, 0, count);
    }
    return (int) adler32.getValue();
}
 
源代码13 项目: update4j   文件: FileUtils.java
public static long getChecksum(Path path) throws IOException {
    try (InputStream input = Files.newInputStream(path)) {
        Adler32 checksum = new Adler32();
        byte[] buf = new byte[1024 * 8];

        int read;
        while ((read = input.read(buf, 0, buf.length)) > -1)
            checksum.update(buf, 0, read);

        return checksum.getValue();
    }
}
 
源代码14 项目: 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());
}
 
源代码15 项目: atlas   文件: Dex.java
/**
 * Returns the checksum of all but the first 12 bytes of {@code dex}.
 */
public int computeChecksum() throws IOException {
    Adler32 adler32 = new Adler32();
    byte[] buffer = new byte[8192];
    ByteBuffer data = this.data.duplicate(); // positioned ByteBuffers aren't thread safe
    data.limit(data.capacity());
    data.position(CHECKSUM_OFFSET + CHECKSUM_SIZE);
    while (data.hasRemaining()) {
        int count = Math.min(buffer.length, data.remaining());
        data.get(buffer, 0, count);
        adler32.update(buffer, 0, count);
    }
    return (int) adler32.getValue();
}
 
源代码16 项目: buck   文件: Dex.java
/**
 * Returns the checksum of all but the first 12 bytes of {@code dex}.
 */
public int computeChecksum() throws IOException {
    Adler32 adler32 = new Adler32();
    byte[] buffer = new byte[8192];
    ByteBuffer data = this.data.duplicate(); // positioned ByteBuffers aren't thread safe
    data.limit(data.capacity());
    data.position(CHECKSUM_OFFSET + CHECKSUM_SIZE);
    while (data.hasRemaining()) {
        int count = Math.min(buffer.length, data.remaining());
        data.get(buffer, 0, count);
        adler32.update(buffer, 0, count);
    }
    return (int) adler32.getValue();
}
 
源代码17 项目: database   文件: TestChecksumUtility.java
/**
 * Test verifies that only the specified region of the buffer is used to
 * compute the checksum.
 */
public void test_checksum02() {

    byte[] data = new byte[100];
    r.nextBytes(data);

    Adler32 adler32 = new Adler32();
    adler32.update(data, 10, 90);
    final int expectedChecksum = (int) adler32.getValue();

    assertEquals(expectedChecksum, chk.checksum(ByteBuffer.wrap(data), 10,
            data.length));
    
}
 
源代码18 项目: pitest   文件: AddlerHash.java
@Override
public long hash(final byte[] value) {
  final Adler32 adler = new Adler32();
  adler.update(value);
  return adler.getValue();
}
 
源代码19 项目: jackson-modules-base   文件: ClassName.java
protected static long adler32(byte[] data)
{
    Adler32 adler = new Adler32();
    adler.update(data);
    return adler.getValue();
}
 
源代码20 项目: mdict-java   文件: BU.java
public static int calcChecksum(byte[] bytes) {
    Adler32 a32 = new Adler32();
    a32.update(bytes);
    int sum = (int) a32.getValue();
    return sum;
}
 
 方法所在类