Search in sources :

Example 1 with Adler32

use of java.util.zip.Adler32 in project zookeeper by apache.

the class SnapshotFormatter method run.

public void run(String snapshotFileName) throws IOException {
    InputStream is = new CheckedInputStream(new BufferedInputStream(new FileInputStream(snapshotFileName)), new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(is);
    FileSnap fileSnap = new FileSnap(null);
    DataTree dataTree = new DataTree();
    Map<Long, Integer> sessions = new HashMap<Long, Integer>();
    fileSnap.deserialize(dataTree, sessions, ia);
    printDetails(dataTree, sessions);
}
Also used : FileSnap(org.apache.zookeeper.server.persistence.FileSnap) BufferedInputStream(java.io.BufferedInputStream) HashMap(java.util.HashMap) CheckedInputStream(java.util.zip.CheckedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InputArchive(org.apache.jute.InputArchive) BinaryInputArchive(org.apache.jute.BinaryInputArchive) CheckedInputStream(java.util.zip.CheckedInputStream) FileInputStream(java.io.FileInputStream) Adler32(java.util.zip.Adler32)

Example 2 with Adler32

use of java.util.zip.Adler32 in project zookeeper by apache.

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
     */
public synchronized void serialize(DataTree dt, Map<Long, Integer> 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.BinaryOutputArchive) OutputArchive(org.apache.jute.OutputArchive) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) FileOutputStream(java.io.FileOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) Adler32(java.util.zip.Adler32)

Example 3 with Adler32

use of java.util.zip.Adler32 in project che by eclipse.

the class ZendDbgConnectionUtils method getContentCheckSum.

/**
     * Computes check-sum for Zend debugger content comparison.
     *
     * @param content
     * @return check-sum
     */
public static final int getContentCheckSum(byte[] content) {
    Adler32 checksumCalculator = new Adler32();
    checksumCalculator.update(content);
    return (int) checksumCalculator.getValue();
}
Also used : Adler32(java.util.zip.Adler32)

Example 4 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 5 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)

Aggregations

Adler32 (java.util.zip.Adler32)41 IOException (java.io.IOException)11 Checksum (java.util.zip.Checksum)9 ByteBuffer (java.nio.ByteBuffer)8 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 InputArchive (org.apache.jute.InputArchive)4 EOFException (java.io.EOFException)3 OutputStream (java.io.OutputStream)3 CheckedOutputStream (java.util.zip.CheckedOutputStream)3 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileOutputStream (java.io.FileOutputStream)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2