当前位置: 首页>>代码示例>>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;未经允许,请勿转载。