当前位置: 首页>>代码示例>>Java>>正文


Java CRC32.reset方法代码示例

本文整理汇总了Java中java.util.zip.CRC32.reset方法的典型用法代码示例。如果您正苦于以下问题:Java CRC32.reset方法的具体用法?Java CRC32.reset怎么用?Java CRC32.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.CRC32的用法示例。


在下文中一共展示了CRC32.reset方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: zipEntries

import java.util.zip.CRC32; //导入方法依赖的package包/类
private ByteArrayOutputStream zipEntries(List<Pair<String, byte[]>> entryList) throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream(8192);
    try (ZipOutputStream jar = new ZipOutputStream(buffer)) {
        jar.setMethod(ZipOutputStream.STORED);
        final CRC32 crc = new CRC32();
        for (Pair<String, byte[]> entry : entryList) {
            byte[] bytes = entry.second;
            final ZipEntry newEntry = new ZipEntry(entry.first);
            newEntry.setMethod(ZipEntry.STORED); // chose STORED method
            crc.reset();
            crc.update(entry.second);
            newEntry.setCrc(crc.getValue());
            newEntry.setSize(bytes.length);
            writeEntryToJar(newEntry, bytes, jar);
        }
        jar.flush();
    }
    return buffer;
}
 
开发者ID:yrom,项目名称:shrinker,代码行数:20,代码来源:JarProcessor.java

示例2: zipFolder

import java.util.zip.CRC32; //导入方法依赖的package包/类
/**
 * Zip a given folder
 * 
 * @param dirPath
 *            a given folder: must be all files (not sub-folders)
 * @param filePath
 *            zipped file
 * @throws Exception
 */
public static void zipFolder(String dirPath, String filePath) throws Exception {
	File outFile = new File(filePath);
	ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outFile));
	int bytesRead;
	byte[] buffer = new byte[1024];
	CRC32 crc = new CRC32();
	for (File file : listFiles(dirPath)) {
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
		crc.reset();
		while ((bytesRead = bis.read(buffer)) != -1) {
			crc.update(buffer, 0, bytesRead);
		}
		bis.close();

		// Reset to beginning of input stream
		bis = new BufferedInputStream(new FileInputStream(file));
		ZipEntry entry = new ZipEntry(file.getName());
		entry.setMethod(ZipEntry.STORED);
		entry.setCompressedSize(file.length());
		entry.setSize(file.length());
		entry.setCrc(crc.getValue());
		zos.putNextEntry(entry);
		while ((bytesRead = bis.read(buffer)) != -1) {
			zos.write(buffer, 0, bytesRead);
		}
		bis.close();
	}
	zos.close();

	Logs.debug("A zip-file is created to: {}", outFile.getPath());
}
 
开发者ID:xiaojieliu7,项目名称:MicroServiceProject,代码行数:41,代码来源:FileIO.java

示例3: computeCRC32

import java.util.zip.CRC32; //导入方法依赖的package包/类
/**
 *
 * @param bytes
 */
public static long computeCRC32(byte[] bytes) {
    CRC32 crc = new CRC32();
    crc.reset();
    crc.update(bytes);
    return crc.getValue();
}
 
开发者ID:IIlllII,项目名称:bitbreeds-webrtc,代码行数:11,代码来源:SignalUtil.java

示例4: checkSum

import java.util.zip.CRC32; //导入方法依赖的package包/类
/**
 * Startings of a method to compute the checksum of the signal sent to the MBO with the
 * Train's current position as X and Y coordinates
 */
public long checkSum() {
	CRC32 crc = new CRC32();
	crc.reset(); // in order to reuse the object for all signals
	String signal = this.trainID + ":" + Double.toString(this.trainWeight) + ":" + Double.toString(this.currentX) + "," + 
			Double.toString(this.currentY);
	crc.update(signal.getBytes()); // signal is a String containing your data
	long checksum = crc.getValue();
	return checksum;
}
 
开发者ID:kevingilboy,项目名称:COE1186,代码行数:14,代码来源:Train.java

示例5: Hash

import java.util.zip.CRC32; //导入方法依赖的package包/类
public static long Hash(byte[] data, int length) {
    CRC32 crc = new CRC32();
    crc.reset();
    crc.update(data, 0, length);
    return crc.getValue();
}
 
开发者ID:SamaGames,项目名称:AntiCheat,代码行数:7,代码来源:CalculationsUtil.java

示例6: writeEntry

import java.util.zip.CRC32; //导入方法依赖的package包/类
private void writeEntry(JarOutputStream j, String name,
                        long mtime, long lsize, boolean deflateHint,
                        ByteBuffer data0, ByteBuffer data1) throws IOException {
    int size = (int)lsize;
    if (size != lsize)
        throw new IOException("file too large: "+lsize);

    CRC32 crc32 = _crc32;

    if (_verbose > 1)
        Utils.log.fine("Writing entry: "+name+" size="+size
                         +(deflateHint?" deflated":""));

    if (_buf.length < size) {
        int newSize = size;
        while (newSize < _buf.length) {
            newSize <<= 1;
            if (newSize <= 0) {
                newSize = size;
                break;
            }
        }
        _buf = new byte[newSize];
    }
    assert(_buf.length >= size);

    int fillp = 0;
    if (data0 != null) {
        int size0 = data0.capacity();
        data0.get(_buf, fillp, size0);
        fillp += size0;
    }
    if (data1 != null) {
        int size1 = data1.capacity();
        data1.get(_buf, fillp, size1);
        fillp += size1;
    }
    while (fillp < size) {
        // Fill in rest of data from the stream itself.
        int nr = in.read(_buf, fillp, size - fillp);
        if (nr <= 0)  throw new IOException("EOF at end of archive");
        fillp += nr;
    }

    ZipEntry z = new ZipEntry(name);
    z.setTime(mtime * 1000);

    if (size == 0) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(0);
        z.setCrc(0);
        z.setCompressedSize(0);
    } else if (!deflateHint) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(size);
        z.setCompressedSize(size);
        crc32.reset();
        crc32.update(_buf, 0, size);
        z.setCrc(crc32.getValue());
    } else {
        z.setMethod(Deflater.DEFLATED);
        z.setSize(size);
    }

    j.putNextEntry(z);

    if (size > 0)
        j.write(_buf, 0, size);

    j.closeEntry();
    if (_verbose > 0) Utils.log.info("Writing " + Utils.zeString(z));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:73,代码来源:NativeUnpack.java


注:本文中的java.util.zip.CRC32.reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。