Search in sources :

Example 11 with Adler32

use of java.util.zip.Adler32 in project tinker by Tencent.

the class Dex method computeChecksum.

/**
     * 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];
    // positioned ByteBuffers aren't thread safe
    ByteBuffer data = this.data.duplicate();
    data.limit(data.capacity());
    data.position(CHECKSUM_OFFSET + SizeOf.CHECKSUM);
    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();
}
Also used : ByteBuffer(java.nio.ByteBuffer) Adler32(java.util.zip.Adler32)

Example 12 with Adler32

use of java.util.zip.Adler32 in project atlas by alibaba.

the class Dex method computeChecksum.

/**
     * 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];
    // positioned ByteBuffers aren't thread safe
    ByteBuffer data = this.data.duplicate();
    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();
}
Also used : ByteBuffer(java.nio.ByteBuffer) Adler32(java.util.zip.Adler32)

Example 13 with Adler32

use of java.util.zip.Adler32 in project atlas by alibaba.

the class DexFile method calcChecksum.

/**
     * 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);
}
Also used : Adler32(java.util.zip.Adler32)

Example 14 with Adler32

use of java.util.zip.Adler32 in project atlas by alibaba.

the class Dex method computeChecksum.

/**
     * 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];
    // positioned ByteBuffers aren't thread safe
    ByteBuffer data = this.data.duplicate();
    data.limit(data.capacity());
    data.position(CHECKSUM_OFFSET + SizeOf.CHECKSUM);
    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();
}
Also used : ByteBuffer(java.nio.ByteBuffer) Adler32(java.util.zip.Adler32)

Example 15 with Adler32

use of java.util.zip.Adler32 in project voltdb by VoltDB.

the class FileSnap method serialize.

/**
     * serialize the datatree and session into the file snapshot
     * @param dt the datatree to be serialized
     * @param sessions the sessions to be serialized
     * @param snapShot the file to store snapshot into
     */
@Override
public synchronized void serialize(DataTree dt, Map<Long, Long> sessions, File snapShot) throws IOException {
    if (!close) {
        OutputStream sessOS = new BufferedOutputStream(new FileOutputStream(snapShot));
        CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32());
        //CheckedOutputStream cout = new CheckedOutputStream()
        OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
        FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
        serialize(dt, sessions, oa, header);
        long val = crcOut.getChecksum().getValue();
        oa.writeLong(val, "val");
        oa.writeString("/", "path");
        sessOS.flush();
        crcOut.close();
        sessOS.close();
    }
}
Also used : BinaryOutputArchive(org.apache.jute_voltpatches.BinaryOutputArchive) OutputArchive(org.apache.jute_voltpatches.OutputArchive) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) FileOutputStream(java.io.FileOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileHeader(org.apache.zookeeper_voltpatches.server.persistence.FileHeader) Adler32(java.util.zip.Adler32)

Aggregations

Adler32 (java.util.zip.Adler32)45 IOException (java.io.IOException)11 ByteBuffer (java.nio.ByteBuffer)9 Checksum (java.util.zip.Checksum)9 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)6 CheckedInputStream (java.util.zip.CheckedInputStream)6 BufferedInputStream (java.io.BufferedInputStream)5 File (java.io.File)5 BinaryInputArchive (org.apache.jute.BinaryInputArchive)5 CheckedOutputStream (java.util.zip.CheckedOutputStream)4 InputArchive (org.apache.jute.InputArchive)4 BufferedOutputStream (java.io.BufferedOutputStream)3 EOFException (java.io.EOFException)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 ArrayList (java.util.ArrayList)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Date (java.util.Date)2