本文整理匯總了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.getCrc方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipArchiveEntry.getCrc方法的具體用法?Java ZipArchiveEntry.getCrc怎麽用?Java ZipArchiveEntry.getCrc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.compress.archivers.zip.ZipArchiveEntry
的用法示例。
在下文中一共展示了ZipArchiveEntry.getCrc方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findBestSource
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
* Find best source.
*
* @param source the source
* @param target the target
* @param targetEntry the target entry
* @return the zip archive entry
* @throws IOException Signals that an I/O exception has occurred.
*/
public ZipArchiveEntry findBestSource(ZipFile source, ZipFile target, ZipArchiveEntry targetEntry) throws IOException {
ArrayList<ZipArchiveEntry> ret = new ArrayList<>();
for (ZipArchiveEntry next : source.getEntries(targetEntry.getName())) {
if (next.getCrc() == targetEntry.getCrc())
return next;
ret.add(next);
}
if (ret.size() == 0)
return null;
if (ret.size() == 1 || targetEntry.isDirectory())
return ret.get(0);
//More than one and no matching crc --- need to calculate xdeltas and pick the shortest
ZipArchiveEntry retEntry = null;
for (ZipArchiveEntry sourceEntry : ret) {
try (ByteArrayOutputStream outbytes = new ByteArrayOutputStream()) {
Delta d = new Delta();
DiffWriter diffWriter = new GDiffWriter(new DataOutputStream(outbytes));
int sourceSize = (int) sourceEntry.getSize();
byte[] sourceBytes = new byte[sourceSize];
try (InputStream sourceStream = source.getInputStream(sourceEntry)) {
for (int erg = sourceStream.read(sourceBytes); erg < sourceBytes.length; erg += sourceStream.read(sourceBytes, erg, sourceBytes.length - erg));
}
d.compute(sourceBytes, target.getInputStream(targetEntry), diffWriter);
byte[] nextDiff = outbytes.toByteArray();
if (calculatedDelta == null || calculatedDelta.length > nextDiff.length) {
retEntry = sourceEntry;
calculatedDelta = nextDiff;
}
}
}
return retEntry;
}
示例2: getEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
* Gets the entry.
*
* @param source the source
* @param name the name
* @param crc the crc
* @return the entry
*/
private ZipArchiveEntry getEntry(ZipFile source, String name, long crc) {
for (ZipArchiveEntry next : source.getEntries(name)) {
if (next.getCrc() == crc)
return next;
}
if (!JarDelta.zipFilesPattern.matcher(name).matches()) {
return null;
} else {
return source.getEntry(name);
}
}
示例3: closeEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
* Close entry.
*
* @param output the output
* @param outEntry the out entry
* @param crc the crc
* @throws IOException Signals that an I/O exception has occurred.
*/
private void closeEntry(ZipArchiveOutputStream output, ZipArchiveEntry outEntry, long crc) throws IOException {
output.flush();
output.closeArchiveEntry();
if (outEntry.getCrc() != crc)
throw new IOException("CRC mismatch for " + outEntry.getName());
}
示例4: equal
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
* Test if the content of two byte arrays is completly identical.
*
* @param sourceEntry the source entry
* @param targetEntry the target entry
* @return true if source and target contain the same bytes.
*/
public boolean equal(ZipArchiveEntry sourceEntry, ZipArchiveEntry targetEntry) {
return (sourceEntry.getSize() == targetEntry.getSize()) && (sourceEntry.getCrc() == targetEntry.getCrc());
}