本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveEntry.getSize方法的具体用法?Java ZipArchiveEntry.getSize怎么用?Java ZipArchiveEntry.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.zip.ZipArchiveEntry
的用法示例。
在下文中一共展示了ZipArchiveEntry.getSize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStroomZipNameSet
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
public StroomZipNameSet getStroomZipNameSet() throws IOException {
if (stroomZipNameSet == null) {
stroomZipNameSet = new StroomZipNameSet(false);
Enumeration<ZipArchiveEntry> entryE = getZipFile().getEntries();
while (entryE.hasMoreElements()) {
ZipArchiveEntry entry = entryE.nextElement();
// Skip Dir's
if (!entry.isDirectory()) {
String fileName = entry.getName();
stroomZipNameSet.add(fileName);
}
long entrySize = entry.getSize();
if (entrySize == -1 || totalSize == -1) {
// Can nolonger sum
} else {
totalSize += entrySize;
}
}
}
return stroomZipNameSet;
}
示例2: getStroomZipNameSet
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
public StroomZipNameSet getStroomZipNameSet() throws IOException {
if (stroomZipNameSet == null) {
stroomZipNameSet = new StroomZipNameSet(false);
Enumeration<ZipArchiveEntry> entryE = getZipFile().getEntries();
while (entryE.hasMoreElements()) {
ZipArchiveEntry entry = entryE.nextElement();
// Skip Dir's
if (!entry.isDirectory()) {
String fileName = entry.getName();
stroomZipNameSet.add(fileName);
}
long entrySize = entry.getSize();
if (entrySize > 0) {
totalSize += entrySize;
}
}
}
return stroomZipNameSet;
}
示例3: unZip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/** uncompresses a single file content that had zip applied */
private static byte[] unZip(byte[] content) throws IOException {
// this code only works if we throw an exception above, meaning we can't uncompress with the generalized approach
try (
ByteArrayInputStream compressedIn = new ByteArrayInputStream(content);
ZipArchiveInputStream zipArcInStream = new ZipArchiveInputStream(compressedIn);
ByteArrayOutputStream out = new ByteArrayOutputStream();
) {
ZipArchiveEntry entry = zipArcInStream.getNextZipEntry();
long entrySize = entry.getSize();
final byte[] buffer = new byte[8192];
int n;
while ((n = zipArcInStream.read(buffer,0, 8192 )) != -1) {
out.write(buffer, 0, n);
}
byte[] uncompressed = out.toByteArray();
return uncompressed;
}
}
示例4: checkBarFileEntrySize
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
* barファイル内エントリのファイルサイズチェック.
* @param zae barファイル内エントリ
* @param entryName エントリ名
* @param maxBarEntryFileSize エントリのファイルサイズ
*/
protected void checkBarFileEntrySize(ZipArchiveEntry zae, String entryName,
long maxBarEntryFileSize) {
// [400]barファイル内エントリのファイルサイズが上限値を超えている
if (zae.getSize() > (long) (maxBarEntryFileSize * MB)) {
String message = "Bar file entry size too large invalid file [%s: %sB]";
log.info(String.format(message, entryName, String.valueOf(zae.getSize())));
throw PersoniumCoreException.BarInstall.BAR_FILE_ENTRY_SIZE_TOO_LARGE
.params(entryName, String.valueOf(zae.getSize()));
}
}
示例5: 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;
}
示例6: getApplicationResourceInputStream
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
public static InputStream getApplicationResourceInputStream(FileSystem fs,
Path appPath,
String entry)
throws IOException {
InputStream is = null;
FSDataInputStream appStream = null;
try {
appStream = fs.open(appPath);
ZipArchiveInputStream zis = new ZipArchiveInputStream(appStream);
ZipArchiveEntry zipEntry;
boolean done = false;
while (!done && (zipEntry = zis.getNextZipEntry()) != null) {
if (entry.equals(zipEntry.getName())) {
int size = (int) zipEntry.getSize();
if (size != -1) {
log.info("Reading {} of size {}", zipEntry.getName(),
zipEntry.getSize());
byte[] content = new byte[size];
int offset = 0;
while (offset < size) {
offset += zis.read(content, offset, size - offset);
}
is = new ByteArrayInputStream(content);
} else {
log.debug("Size unknown. Reading {}", zipEntry.getName());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (true) {
int byteRead = zis.read();
if (byteRead == -1) {
break;
}
baos.write(byteRead);
}
is = new ByteArrayInputStream(baos.toByteArray());
}
done = true;
}
}
} finally {
IOUtils.closeStream(appStream);
}
return is;
}
示例7: toBytes
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
* Converts the given zip entry to a byte array.
*
* @author S3460
* @param zipfile the zipfile
* @param entry the entry
* @return the byte[]
* @throws Exception the exception
*/
private byte[] toBytes(ZipFile zipfile, ZipArchiveEntry entry) throws Exception {
int entrySize = (int) entry.getSize();
byte[] bytes = new byte[entrySize];
InputStream entryStream = zipfile.getInputStream(entry);
for (int erg = entryStream.read(bytes); erg < bytes.length; erg += entryStream.read(bytes, erg, bytes.length - erg));
return bytes;
}
示例8: 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());
}