Search in sources :

Example 26 with Adler32

use of java.util.zip.Adler32 in project bigbluebutton by bigbluebutton.

the class BlockStreamProtocolEncoder method encodeChecksum.

public static byte[] encodeChecksum(byte[] data) {
    Adler32 checksum = new Adler32();
    checksum.reset();
    checksum.update(data);
    return longToBytes(checksum.getValue());
}
Also used : Adler32(java.util.zip.Adler32)

Example 27 with Adler32

use of java.util.zip.Adler32 in project hawtjournal by fusesource.

the class Journal method recoveryCheck.

private Location recoveryCheck() throws IOException {
    Location location = goToFirstLocation(dataFiles.firstEntry().getValue(), Location.BATCH_CONTROL_RECORD_TYPE, false);
    while (true) {
        ByteBuffer buffer = accessor.readLocation(location).toByteBuffer();
        for (int i = 0; i < BATCH_CONTROL_RECORD_MAGIC.length; i++) {
            if (buffer.get() != BATCH_CONTROL_RECORD_MAGIC[i]) {
                throw new IOException("Bad control record magic for location: " + location);
            }
        }
        if (isChecksum()) {
            long expectedChecksum = buffer.getLong();
            byte[] data = new byte[buffer.remaining()];
            Checksum checksum = new Adler32();
            buffer.get(data);
            checksum.update(data, 0, data.length);
            if (expectedChecksum != checksum.getValue()) {
                throw new IOException("Bad checksum for location: " + location);
            }
        }
        Location next = goToNextLocation(location, Location.BATCH_CONTROL_RECORD_TYPE, true);
        if (next != null) {
            location = next;
        } else {
            break;
        }
    }
    return location;
}
Also used : Checksum(java.util.zip.Checksum) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) Adler32(java.util.zip.Adler32)

Example 28 with Adler32

use of java.util.zip.Adler32 in project buck by facebook.

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 29 with Adler32

use of java.util.zip.Adler32 in project j2objc by google.

the class InflaterTest method adler32.

private static int adler32(byte[] bytes) {
    Adler32 adler32 = new Adler32();
    adler32.update(bytes);
    return (int) adler32.getValue();
}
Also used : Adler32(java.util.zip.Adler32)

Example 30 with Adler32

use of java.util.zip.Adler32 in project pinot by linkedin.

the class CrcUtils method computeCrc.

public long computeCrc() {
    CheckedInputStream cis = null;
    InputStream is = null;
    final Checksum checksum = new Adler32();
    final byte[] tempBuf = new byte[BUFFER_SIZE];
    for (final File file : filesToProcess) {
        try {
            is = new BufferedInputStream(new FileInputStream(file));
            cis = new CheckedInputStream(is, checksum);
            while (cis.read(tempBuf) >= 0) {
            }
            cis.close();
            is.close();
        } catch (final Exception e) {
            LOGGER.error("Caught exception while computing CRC", e);
            Utils.rethrowException(e);
            throw new AssertionError("Should not reach this");
        }
    }
    return checksum.getValue();
}
Also used : BufferedInputStream(java.io.BufferedInputStream) CheckedInputStream(java.util.zip.CheckedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Checksum(java.util.zip.Checksum) File(java.io.File) CheckedInputStream(java.util.zip.CheckedInputStream) Adler32(java.util.zip.Adler32) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

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