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());
}
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;
}
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);
}
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();
}
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();
}
Aggregations