當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。