當前位置: 首頁>>代碼示例>>Java>>正文


Java Adler32類代碼示例

本文整理匯總了Java中java.util.zip.Adler32的典型用法代碼示例。如果您正苦於以下問題:Java Adler32類的具體用法?Java Adler32怎麽用?Java Adler32使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Adler32類屬於java.util.zip包,在下文中一共展示了Adler32類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: serialize

import java.util.zip.Adler32; //導入依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:24,代碼來源:FileSnap.java

示例2: getCheckSum

import java.util.zip.Adler32; //導入依賴的package包/類
/** 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);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:27,代碼來源:CRCTest.java

示例3: toZip

import java.util.zip.Adler32; //導入依賴的package包/類
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();
    }
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:26,代碼來源:FileUtils.java

示例4: a

import java.util.zip.Adler32; //導入依賴的package包/類
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;
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:20,代碼來源:m.java

示例5: serialize

import java.util.zip.Adler32; //導入依賴的package包/類
/**
 * 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();
        }
    }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:26,代碼來源:FileSnap.java

示例6: updateChecksum

import java.util.zip.Adler32; //導入依賴的package包/類
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();
}
 
開發者ID:CvvT,項目名稱:andbg,代碼行數:17,代碼來源:DexWriter.java

示例7: GiveMeACookie

import java.util.zip.Adler32; //導入依賴的package包/類
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;
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:17,代碼來源:CookieSecurity.java

示例8: CheckCookieValue

import java.util.zip.Adler32; //導入依賴的package包/類
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;
    }
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:17,代碼來源:CookieSecurity.java

示例9: LZ4BlockOutputStream

import java.util.zip.Adler32; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:goldmansachs,項目名稱:reladomo,代碼行數:26,代碼來源:LZ4BlockOutputStream.java

示例10: fixCheckSumHeader

import java.util.zip.Adler32; //導入依賴的package包/類
/**
 * �޸�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();
}
 
開發者ID:tangsilian,項目名稱:SecurityPage,代碼行數:21,代碼來源:mymain.java

示例11: createPackageChecksum

import java.util.zip.Adler32; //導入依賴的package包/類
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());
    }
}
 
開發者ID:PlayPen,項目名稱:playpen-core,代碼行數:18,代碼來源:AuthUtils.java

示例12: main

import java.util.zip.Adler32; //導入依賴的package包/類
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);
}
 
開發者ID:keeyanajones,項目名稱:Samples,代碼行數:20,代碼來源:CalculateAdler32ForByteArray.java

示例13: fixCheckSumHeader

import java.util.zip.Adler32; //導入依賴的package包/類
/**
 * 修改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();
}
 
開發者ID:DIY-green,項目名稱:AndroidStudyDemo,代碼行數:21,代碼來源:PackerUtil.java

示例14: updateChecksum

import java.util.zip.Adler32; //導入依賴的package包/類
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();
}
 
開發者ID:AndreJCL,項目名稱:JCL,代碼行數:17,代碼來源:DexWriter.java

示例15: hashCode

import java.util.zip.Adler32; //導入依賴的package包/類
/**
 * 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;
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:22,代碼來源:gnuAny.java


注:本文中的java.util.zip.Adler32類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。