本文整理了Java中java.util.zip.ZipEntry.getSize()
方法的一些代码示例,展示了ZipEntry.getSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEntry.getSize()
方法的具体详情如下:
包路径:java.util.zip.ZipEntry
类名称:ZipEntry
方法名:getSize
[英]Gets the uncompressed size of this ZipEntry.
[中]获取此ZipEntry的未压缩大小。
代码示例来源:origin: skylot/jadx
public static boolean isZipBomb(ZipEntry entry) {
long compressedSize = entry.getCompressedSize();
long uncompressedSize = entry.getSize();
if (compressedSize < 0 || uncompressedSize < 0) {
LOG.error("Zip bomb attack detected, invalid sizes: compressed {}, uncompressed {}, name {}",
compressedSize, uncompressedSize, entry.getName());
return true;
}
if (compressedSize * MAX_SIZE_DIFF < uncompressedSize) {
LOG.error("Zip bomb attack detected, invalid sizes: compressed {}, uncompressed {}, name {}",
compressedSize, uncompressedSize, entry.getName());
return true;
}
return false;
}
代码示例来源:origin: Tencent/tinker
ZipEntry zipEntry = (ZipEntry) entries.nextElement();
if (!zipEntry.isDirectory()) {
String key = zipEntry.getName();
String value = zipEntry.getCrc() + Constant.Symbol.DOT + zipEntry.getSize();
map.put(key, value);
代码示例来源:origin: apache/nifi
@Override
protected void processInputStream(InputStream stream, final FlowFile flowFile, final Writer writer) throws IOException {
try (final ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(stream))) {
ZipEntry zipEntry;
while ((zipEntry = zipIn.getNextEntry()) != null) {
if (zipEntry.isDirectory()) {
continue;
}
final File file = new File(zipEntry.getName());
final String key = file.getName();
long fileSize = zipEntry.getSize();
final InputStreamWritable inStreamWritable = new InputStreamWritable(zipIn, (int) fileSize);
writer.append(new Text(key), inStreamWritable);
logger.debug("Appending FlowFile {} to Sequence File", new Object[]{key});
}
}
}
}
代码示例来源:origin: Tencent/tinker
ZipEntry zipEntry = entries.nextElement();
if (!zipEntry.isDirectory()) {
String zipEntryName = zipEntry.getName();
String oldZipEntryHash = map.get(zipEntryName);
String newZipEntryHash = zipEntry.getCrc() + Constant.Symbol.DOT + zipEntry.getSize();
代码示例来源:origin: stackoverflow.com
import java.io.FileInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class Main {
public static void main(String[] args) throws Exception
{
FileInputStream fis = new FileInputStream("c:/inas400.zip");
// this is where you start, with an InputStream containing the bytes from the zip file
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry entry;
// while there are entries I process them
while ((entry = zis.getNextEntry()) != null)
{
System.out.println("entry: " + entry.getName() + ", " + entry.getSize());
// consume all the data from this entry
while (zis.available() > 0)
zis.read();
// I could close the entry, but getNextEntry does it automatically
// zis.closeEntry()
}
}
}
代码示例来源:origin: spotbugs/spotbugs
for (Enumeration<? extends ZipEntry> e = zipInputFile.entries(); e.hasMoreElements();) {
ZipEntry ze = e.nextElement();
if (!ze.isDirectory() && ze.getName().endsWith(".class") && ze.getSize() != 0) {
handler.handle(zipInputFile, ze);
代码示例来源:origin: graphhopper/graphhopper
while (ze != null) {
if (ze.isDirectory()) {
new File(toFolder, ze.getName()).mkdir();
} else {
double factor = 1;
if (ze.getCompressedSize() > 0 && ze.getSize() > 0)
factor = (double) ze.getCompressedSize() / ze.getSize();
File newFile = new File(toFolder, ze.getName());
FileOutputStream fos = new FileOutputStream(newFile);
try {
代码示例来源:origin: spotbugs/spotbugs
String name = e.getName();
long size = e.getSize();
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
if (zipEntry.getSize() > 0) {
File file = FileUtil.getFileByPath(unzipPath + "/" + zipEntry.getName(), false);
OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
InputStream is = zipFile.getInputStream(zipEntry);
FileUtil.getFileByPath(unzipPath + "/" + zipEntry.getName(), true);
代码示例来源:origin: typ0520/fastdex
ZipEntry zipEntry = (ZipEntry) entries.nextElement();
if (!zipEntry.isDirectory()) {
String key = zipEntry.getName();
String value = zipEntry.getCrc() + Constant.Symbol.DOT + zipEntry.getSize();
map.put(key, value);
代码示例来源:origin: rmtheis/android-ocr
destinationFile = new File(destinationDir, entry.getName());
} else {
long zippedFileSize = entry.getSize();
代码示例来源:origin: Sable/soot
try {
stream = zipFile.getInputStream(zipEntry);
ret = doJDKBugWorkaround(stream, zipEntry.getSize());
} catch (Exception e) {
throw new RuntimeException("Error: Failed to open a InputStream for the entry '" + zipEntry.getName()
+ "' of the archive at path '" + zipFile.getName() + "'.", e);
} finally {
代码示例来源:origin: Sable/soot
private void copyAllButClassesDexAndSigFiles(ZipFile source, ZipOutputStream destination) throws IOException {
Enumeration<? extends ZipEntry> sourceEntries = source.entries();
while (sourceEntries.hasMoreElements()) {
ZipEntry sourceEntry = sourceEntries.nextElement();
String sourceEntryName = sourceEntry.getName();
if (sourceEntryName.endsWith(".dex") || isSignatureFile(sourceEntryName)) {
continue;
}
// separate ZipEntry avoids compression problems due to encodings
ZipEntry destinationEntry = new ZipEntry(sourceEntryName);
// use the same compression method as the original (certain files
// are stored, not compressed)
destinationEntry.setMethod(sourceEntry.getMethod());
// copy other necessary fields for STORE method
destinationEntry.setSize(sourceEntry.getSize());
destinationEntry.setCrc(sourceEntry.getCrc());
// finally craft new entry
destination.putNextEntry(destinationEntry);
InputStream zipEntryInput = source.getInputStream(sourceEntry);
byte[] buffer = new byte[2048];
int bytesRead = zipEntryInput.read(buffer);
while (bytesRead > 0) {
destination.write(buffer, 0, bytesRead);
bytesRead = zipEntryInput.read(buffer);
}
zipEntryInput.close();
}
}
代码示例来源:origin: xalan/xalan
String entryName = entry.getName();
if (entry.getSize() > 0 &&
(entryName.equals(transletFullName) ||
(entryName.endsWith(".class") &&
int size = (int)entry.getSize();
byte[] bytes = new byte[size];
readFromInputStream(bytes, input, size);
代码示例来源:origin: robovm/robovm
entry = getEntry(entry.getName());
if (entry == null) {
return null;
} else {
rafStream.endOffset = rafStream.offset + entry.compressedSize;
int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L));
return new ZipInflaterInputStream(rafStream, new Inflater(true), bufSize, entry);
代码示例来源:origin: neo4j/neo4j
new File( targetDirectory, entry.getName() ).mkdirs();
try ( OutputStream file = new BufferedOutputStream( new FileOutputStream( new File( targetDirectory, entry.getName() ) ) ) )
long toCopy = entry.getSize();
while ( toCopy > 0 )
代码示例来源:origin: typ0520/fastdex
ZipEntry zipEntry = entries.nextElement();
if (!zipEntry.isDirectory()) {
String zipEntryName = zipEntry.getName();
String oldZipEntryHash = map.get(zipEntryName);
String newZipEntryHash = zipEntry.getCrc() + Constant.Symbol.DOT + zipEntry.getSize();
代码示例来源:origin: org.apache.ant/ant
String name = inputEntry.getName();
outputEntry.setMethod(ZipEntry.STORED);
outputEntry.setCrc(inputEntry.getCrc());
outputEntry.setSize(inputEntry.getSize());
代码示例来源:origin: robovm/robovm
return null;
if (verifier == null || ze.getSize() == -1) {
return in;
JarVerifier.VerifierEntry entry = verifier.initEntry(ze.getName());
if (entry == null) {
return in;
代码示例来源:origin: zeroturnaround/zt-zip
/**
* Copy entry with another name.
*
* @param original - zipEntry to copy
* @param newName - new entry name, optional, if null, ogirinal's entry
* @return copy of the original entry, but with the given name
*/
static ZipEntry copy(ZipEntry original, String newName) {
ZipEntry copy = new ZipEntry(newName == null ? original.getName() : newName);
if (original.getCrc() != -1) {
copy.setCrc(original.getCrc());
}
if (original.getMethod() != -1) {
copy.setMethod(original.getMethod());
}
if (original.getSize() >= 0) {
copy.setSize(original.getSize());
}
if (original.getExtra() != null) {
copy.setExtra(original.getExtra());
}
copy.setComment(original.getComment());
copy.setTime(original.getTime());
return copy;
}
内容来源于网络,如有侵权,请联系作者删除!