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