Java 类java.util.zip.Adler32 实例源码

项目:fuck_zookeeper    文件:FileSnap.java   
/**
 * 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();
    }
}
项目:fuck_zookeeper    文件:CRCTest.java   
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
项目:mcClans    文件:FileUtils.java   
public static void toZip(File file) {
    try {
        File zipFile = new File(file.getParentFile(), stripExtension(file.getName()) + ".zip");

        FileOutputStream dest = new FileOutputStream(zipFile);
        CheckedOutputStream checksum = new CheckedOutputStream(dest, new Adler32());
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(checksum));

        byte data[] = new byte[BUFFER];
        FileInputStream fi = new FileInputStream(file);
        BufferedInputStream origin = new BufferedInputStream(fi, BUFFER);
        ZipEntry entry = new ZipEntry(file.getName());
        out.putNextEntry(entry);
        int count;
        while ((count = origin.read(data, 0, BUFFER)) != -1) {
            out.write(data, 0, count);
        }
        out.closeEntry();
        origin.close();

        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:letv    文件:m.java   
private static int a(String str, int i) {
    if (TextUtils.isEmpty(str)) {
        z.b();
        return 0;
    }
    try {
        return Integer.valueOf(str).intValue();
    } catch (Exception e) {
        z.d();
        Adler32 adler32 = new Adler32();
        adler32.update(str.getBytes());
        int value = (int) adler32.getValue();
        if (value < 0) {
            value = Math.abs(value);
        }
        value += 13889152 * i;
        return value < 0 ? Math.abs(value) : value;
    }
}
项目:https-github.com-apache-zookeeper    文件:FileSnap.java   
/**
 * 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
 * @param fsync sync the file immediately after write
 */
public synchronized void serialize(DataTree dt, Map<Long, Integer> sessions, File snapShot, boolean fsync)
        throws IOException {
    if (!close) {
        try (CheckedOutputStream crcOut =
                     new CheckedOutputStream(new BufferedOutputStream(fsync ? new AtomicFileOutputStream(snapShot) :
                                                                              new FileOutputStream(snapShot)),
                                             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");
            crcOut.flush();
        }
    }
}
项目:https-github.com-apache-zookeeper    文件:CRCTest.java   
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
项目:ZooKeeper    文件:FileSnap.java   
/**
 * 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();
    }
}
项目:ZooKeeper    文件:CRCTest.java   
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
项目:andbg    文件:DexWriter.java   
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException {
    Adler32 a32 = new Adler32();

    byte[] buffer = new byte[4 * 1024];
    InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
    int bytesRead = input.read(buffer);
    while (bytesRead >= 0) {
        a32.update(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
    }

    // write checksum, utilizing logic in DexWriter to write the integer value properly
    OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
    DexDataWriter.writeInt(output, (int)a32.getValue());
    output.close();
}
项目:StreamProcessingInfrastructure    文件:FileSnap.java   
/**
 * 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();
    }
}
项目:StreamProcessingInfrastructure    文件:CRCTest.java   
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
项目:OSCAR-ConCert    文件:CookieSecurity.java   
public Cookie GiveMeACookie(String cookieName) {
    Random rndGenerator = new Random();
    Adler32 adler32 = new Adler32();
    String cookieVal = "";        
    for (int i = 0; i < 32; i++) {
        int j = rndGenerator.nextInt(10);                       
        cookieVal = cookieVal.concat(Integer.toString(j));            
        adler32.update(j);            
    }

    cookieVal = cookieVal.concat(Long.toString(adler32.getValue()));

    Cookie cookie = new Cookie(cookieName, cookieVal);
    cookie.setPath("/");
    return cookie;
}
项目:OSCAR-ConCert    文件:CookieSecurity.java   
private boolean CheckCookieValue(String cookieValue) {
    try {
        Adler32 adler32 = new Adler32();        
        //adler32.update(cookieValue.substring(0, 32).getBytes());
        for (int i=0; i < 32; i++) {
            adler32.update(Integer.parseInt(cookieValue.substring(i, i+1)));                
        }        
        if (Long.parseLong(cookieValue.substring(32, cookieValue.length())) == adler32.getValue()) {            
            return true;
        } else {            
            return false;
        }
    } catch (Exception e) {
        return false;
    }
}
项目:bigstreams    文件:FileSnap.java   
/**
 * 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();
    }
}
项目:bigstreams    文件:CRCTest.java   
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
项目:bigstreams    文件:FileSnap.java   
/**
 * 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();
    }
}
项目:bigstreams    文件:CRCTest.java   
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
项目:reladomo    文件:LZ4BlockOutputStream.java   
/**
 * Create a new {@link java.io.OutputStream} with configurable block size. Large
 * blocks require more memory at compression and decompression time but
 * should improve the compression ratio.
 *
 * @param out        the {@link java.io.OutputStream} to feed
 * @param blockSize  the maximum number of bytes to try to compress at once,
 *                   must be >= 64 and <= 32 M
 * @param syncFlush  true if pending data should also be flushed on {@link #flush()}
 */
public LZ4BlockOutputStream(OutputStream out, int blockSize, boolean syncFlush)
{
    super(out);
    this.blockSize = blockSize;
    this.compressor = new LZ4HCJavaSafeCompressor();
    this.checksum = new Adler32();
    this.compressionLevel = compressionLevel(blockSize);
    this.buffer = new byte[blockSize];
    final int compressedBlockSize = HEADER_LENGTH + compressor.maxCompressedLength(blockSize);
    this.compressedBuffer = new byte[compressedBlockSize];
    this.syncFlush = syncFlush;
    o = 0;
    finished = false;
    System.arraycopy(MAGIC, 0, compressedBuffer, 0, MAGIC_LENGTH);
}
项目:zookeeper-src-learning    文件:FileSnap.java   
/**
 * 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();
    }
}
项目:zjdroid    文件:DexWriter.java   
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException {
    Adler32 a32 = new Adler32();

    byte[] buffer = new byte[4 * 1024];
    InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
    int bytesRead = input.read(buffer);
    while (bytesRead >= 0) {
        a32.update(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
    }

    // write checksum, utilizing logic in DexWriter to write the integer value properly
    OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
    DexDataWriter.writeInt(output, (int)a32.getValue());
    output.close();
}
项目:SecurityPage    文件:mymain.java   
/**
 * �޸�dexͷ��CheckSum У����
 * @param dexBytes
 */
private static void fixCheckSumHeader(byte[] dexBytes) {
    Adler32 adler = new Adler32();
    adler.update(dexBytes, 12, dexBytes.length - 12);//��12���ļ�ĩβ����У����
    long value = adler.getValue();
    int va = (int) value;
    byte[] newcs = intToByte(va);
    //��λ��ǰ����λ��ǰ������
    byte[] recs = new byte[4];
    for (int i = 0; i < 4; i++) {
        recs[i] = newcs[newcs.length - 1 - i];
        System.out.println(Integer.toHexString(newcs[i]));
    }
    System.arraycopy(recs, 0, dexBytes, 8, 4);//Ч���븳ֵ��8-11��
    System.out.println(Long.toHexString(value));
    System.out.println();
}
项目:playpen-core    文件:AuthUtils.java   
public static String createPackageChecksum(String fp) throws IOException {
    Path path = Paths.get(fp);
    try (CheckedInputStream is = new CheckedInputStream(Files.newInputStream(path), new Adler32())) {
        byte[] buf = new byte[1024*1024];
        int total = 0;
        int c = 0;
        while (total < 100*1024*1024 && (c = is.read(buf)) >= 0) {
            total += c;
        }

        ByteBuffer bb = ByteBuffer.allocate(Long.BYTES);
        bb.putLong(path.toFile().length());
        buf = bb.array();
        is.getChecksum().update(buf, 0, buf.length);
        return Long.toHexString(is.getChecksum().getValue());
    }
}
项目:Samples    文件:CalculateAdler32ForByteArray.java   
public static void main(String args[]) {

    String str = "Generate Adler32 Checksum For Byte Array Example";
    // Convert string to bytes
    byte bytes[] = str.getBytes();
    Checksum checksum = new Adler32();

    /**
     * To compute the Adler32 checksum for byte array, use void 
     * update(bytes[] b, int start, int length) method of Adler32 class.
     **/
    checksum.update(bytes,0,bytes.length);

    /**
     * Get the generated checksum using getValue method of Adler32 class.
     **/
    long lngChecksum = checksum.getValue();
    System.out.println("Adler32 checksum for byte array is :" + lngChecksum);
}
项目:zookeeper    文件:FileSnap.java   
/**
 * 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();
    }
}
项目:zookeeper    文件:CRCTest.java   
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
项目:AndroidStudyDemo    文件:PackerUtil.java   
/**
 * 修改dex头,CheckSum 校验码
 * @param dexBytes
 */
private static void fixCheckSumHeader(byte[] dexBytes) {
    Adler32 adler = new Adler32();
    adler.update(dexBytes, 12, dexBytes.length - 12);//从12到文件末尾计算校验码
    long value = adler.getValue();
    int va = (int) value;
    byte[] newcs = intToByte(va);
    //高位在前,低位在前掉个个
    byte[] recs = new byte[4];
    for (int i = 0; i < 4; i++) {
        recs[i] = newcs[newcs.length - 1 - i];
        System.out.println(Integer.toHexString(newcs[i]));
    }
    System.arraycopy(recs, 0, dexBytes, 8, 4);//效验码赋值(8-11)
    System.out.println(Long.toHexString(value));
    System.out.println();
}
项目:JCL    文件:DexWriter.java   
private void updateChecksum( DexDataStore dataStore) throws IOException {
    Adler32 a32 = new Adler32();

    byte[] buffer = new byte[4 * 1024];
    InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
    int bytesRead = input.read(buffer);
    while (bytesRead >= 0) {
        a32.update(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
    }

    // write checksum, utilizing logic in DexWriter to write the integer value properly
    OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
    DexDataWriter.writeInt(output, (int)a32.getValue());
    output.close();
}
项目:SecureKeeper    文件:FileSnap.java   
/**
 * 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();
    }
}
项目:SecureKeeper    文件:CRCTest.java   
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
项目:SecureKeeper    文件:FileSnap.java   
/**
 * 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();
    }
}
项目:SecureKeeper    文件:CRCTest.java   
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
项目:AppTroy    文件:DexWriter.java   
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException {
    Adler32 a32 = new Adler32();

    byte[] buffer = new byte[4 * 1024];
    InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
    int bytesRead = input.read(buffer);
    while (bytesRead >= 0) {
        a32.update(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
    }

    // write checksum, utilizing logic in DexWriter to write the integer value properly
    OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
    DexDataWriter.writeInt(output, (int)a32.getValue());
    output.close();
}
项目:javify    文件:gnuAny.java   
/**
 * Get the content - dependent hashcode.
 */
public int hashCode()
{
  if (has == null)
    return type().kind().value();
  else
    {
      Adler32 adler = new Adler32();

      BufferedCdrOutput a = new BufferedCdrOutput();
      a.setOrb(orb);
      write_value(a);

      adler.update(a.buffer.toByteArray());
      adler.update(type().kind().value());

      return (int) adler.getValue() & Integer.MAX_VALUE;
    }
}
项目:JavaNote    文件:ZipCompress.java   
private static void uncompress() {
    FileInputStream fis;
    try {
        fis = new FileInputStream("./dir/demo.zip");
        CheckedInputStream cis = new CheckedInputStream(fis,new Adler32());
        ZipInputStream zis = new ZipInputStream(cis);
        BufferedInputStream bis = new BufferedInputStream(zis);
        ZipEntry zipENtry ;
        while ((zipENtry = zis.getNextEntry()) != null){
            System.err.println("read file--->" + zipENtry);
            int x;
            while ((x = bis.read()) != -1){
                System.err.println(x);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:dex    文件:DexWriter.java   
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException {
    Adler32 a32 = new Adler32();

    byte[] buffer = new byte[4 * 1024];
    InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
    int bytesRead = input.read(buffer);
    while (bytesRead >= 0) {
        a32.update(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
    }

    // write checksum, utilizing logic in DexWriter to write the integer value properly
    OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
    DexDataWriter.writeInt(output, (int)a32.getValue());
    output.close();
}
项目:dex    文件:DexFileWriter.java   
public static void updateChecksum(ByteBuffer buffer, int size) {
    byte[] data = buffer.array();
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError();
    }

    digest.update(data, 32, size - 32);
    byte[] sha1 = digest.digest();
    System.arraycopy(sha1, 0, data, 12, sha1.length);

    Adler32 adler32 = new Adler32();
    adler32.update(data, 12, size - 12);
    int v = (int) adler32.getValue();
    buffer.position(8);
    buffer.putInt(v);
}
项目:jvm-stm    文件:gnuAny.java   
/**
 * Get the content - dependent hashcode.
 */
public int hashCode()
{
  if (has == null)
    return type().kind().value();
  else
    {
      Adler32 adler = new Adler32();

      BufferedCdrOutput a = new BufferedCdrOutput();
      a.setOrb(orb);
      write_value(a);

      adler.update(a.buffer.toByteArray());
      adler.update(type().kind().value());

      return (int) adler.getValue() & Integer.MAX_VALUE;
    }
}
项目:show-java    文件:DexWriter.java   
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException {
    Adler32 a32 = new Adler32();

    byte[] buffer = new byte[4 * 1024];
    InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
    int bytesRead = input.read(buffer);
    while (bytesRead >= 0) {
        a32.update(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
    }

    // write checksum, utilizing logic in DexWriter to write the integer value properly
    OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
    DexDataWriter.writeInt(output, (int) a32.getValue());
    output.close();
}
项目:ZJDroid    文件:DexWriter.java   
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException {
    Adler32 a32 = new Adler32();

    byte[] buffer = new byte[4 * 1024];
    InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
    int bytesRead = input.read(buffer);
    while (bytesRead >= 0) {
        a32.update(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
    }

    // write checksum, utilizing logic in DexWriter to write the integer value properly
    OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
    DexDataWriter.writeInt(output, (int)a32.getValue());
    output.close();
}
项目:VoltDB    文件:FileSnap.java   
/**
 * 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();
    }
}