Java Code Examples for java.util.zip.ZipEntry#getCompressedSize()
The following examples show how to use
java.util.zip.ZipEntry#getCompressedSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZipOutputStreamTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.util.zip.ZipOutputStream#setMethod(int) */ public void test_setMethodI() throws IOException { ZipEntry ze = new ZipEntry("test"); zos.setMethod(ZipOutputStream.STORED); CRC32 tempCrc = new CRC32(); tempCrc.update(data.getBytes()); ze.setCrc(tempCrc.getValue()); ze.setSize(new String(data).length()); zos.putNextEntry(ze); zos.write(data.getBytes()); zos.closeEntry(); long csize = ze.getCompressedSize(); zos.setMethod(ZipOutputStream.DEFLATED); zos.putNextEntry(ze = new ZipEntry("test2")); zos.write(data.getBytes()); zos.closeEntry(); assertTrue("setLevel failed", csize >= ze.getCompressedSize()); }
Example 2
Source File: Utils.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 3
Source File: TMSLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected void fillFromZipInt(Uri uri, IProgressor progressor) throws IOException, NGException, RuntimeException { InputStream inputStream; String url = uri.toString(); if (NetworkUtil.isValidUri(url)) inputStream = new URL(url).openStream(); else inputStream = mContext.getContentResolver().openInputStream(uri); if (inputStream == null) throw new NGException(mContext.getString(R.string.error_download_data)); int streamSize = inputStream.available(); if (null != progressor) progressor.setMax(streamSize); int increment = 0; byte[] buffer = new byte[Constants.IO_BUFFER_SIZE]; ZipInputStream zis = new ZipInputStream(inputStream); ZipEntry ze; while ((ze = zis.getNextEntry()) != null) { FileUtil.unzipEntry(zis, ze, buffer, mPath); increment += ze.getCompressedSize(); zis.closeEntry(); if (null != progressor) { if(progressor.isCanceled()) return; progressor.setValue(increment); progressor.setMessage(getContext().getString(R.string.processed) + " " + increment + " " + getContext().getString(R.string.of) + " " + streamSize); } } }
Example 4
Source File: Utils.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 5
Source File: Utils.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 6
Source File: Utils.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 7
Source File: ZipSecurity.java From jadx with Apache License 2.0 | 5 votes |
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; }
Example 8
Source File: Utils.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 9
Source File: Utils.java From hottub with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 10
Source File: Utils.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 11
Source File: Utils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 12
Source File: ZipSecurity.java From Box with Apache License 2.0 | 5 votes |
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; }
Example 13
Source File: Utils.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 14
Source File: ApkBreakdownGeneratorTest.java From bundletool with Apache License 2.0 | 5 votes |
private static long compress(byte[] data) throws IOException { ZipEntry zipEntry = new ZipEntry("entry"); try (ZipOutputStream zos = new ZipOutputStream(ByteStreams.nullOutputStream())) { zipEntry.setMethod(ZipEntry.DEFLATED); zos.putNextEntry(zipEntry); zos.write(data); zos.closeEntry(); } return zipEntry.getCompressedSize(); }
Example 15
Source File: Utils.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 16
Source File: DexConversionEnqueuer.java From bazel with Apache License 2.0 | 5 votes |
@Override public Void call() throws InterruptedException, IOException { try { Enumeration<? extends ZipEntry> entries = in.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); // Since these entries come from an existing zip file, they should always know their size // (meaning, never return -1). We also can't handle files that don't fit into a byte array. checkArgument(entry.getSize() >= 0, "Cannot process entry with unknown size: %s", entry); checkArgument(entry.getSize() <= Integer.MAX_VALUE, "Entry too large: %s", entry); byte[] content; if (entry.getSize() == 0L) { content = EMPTY; // this in particular covers directory entries } else { try (InputStream entryStream = in.getInputStream(entry)) { // Read all the content at once, which avoids temporary arrays and extra array copies content = new byte[(int) entry.getSize()]; ByteStreams.readFully(entryStream, content); // throws if file is smaller than expected checkState(entryStream.read() == -1, "Too many bytes in jar entry %s, expected %s", entry, entry.getSize()); } } if (!entry.isDirectory() && entry.getName().endsWith(".class")) { files.put(toDex(entry, content)); } else { // Copy other files and directory entries if (entry.getCompressedSize() != 0) { entry.setCompressedSize(-1L); // We may compress differently from source Zip } files.put(immediateFuture(new ZipEntryContent(entry, content))); } } } finally { // Use try-finally to make absolutely sure we do this, otherwise the reader might deadlock files.put(immediateFuture((ZipEntryContent) null)); // "end of stream" marker } return null; }
Example 17
Source File: Utils.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
static String zeString(ZipEntry ze) { int store = (ze.getCompressedSize() > 0) ? (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 ) : 0 ; // Follow unzip -lv output return ze.getSize() + "\t" + ze.getMethod() + "\t" + ze.getCompressedSize() + "\t" + store + "%\t" + new Date(ze.getTime()) + "\t" + Long.toHexString(ze.getCrc()) + "\t" + ze.getName() ; }
Example 18
Source File: ZippedEntry.java From rxjava-extras with Apache License 2.0 | 5 votes |
public ZippedEntry(ZipEntry e, InputStream is) { this.name = e.getName(); this.time = e.getTime(); // this.mtime = e.getLastModifiedTime(); // this.atime = e.getLastAccessTime(); // this.ctime = e.getCreationTime(); this.crc = e.getCrc(); this.size = e.getSize(); this.csize = e.getCompressedSize(); this.method = e.getMethod(); this.extra = e.getExtra(); this.comment = e.getComment(); this.is = is; }
Example 19
Source File: ZipFileEntryInputStream.java From fingen with Apache License 2.0 | 4 votes |
/** * position input stream to start of ZipEntry this instance was created for * * @throws IOException */ public void nextEntry( ZipEntry ze ) throws IOException { LOG.fine("nextEntry().currentPos=" + currentPos); byte[] intBuffer = new byte[4]; int bytesRead = fis.read(intBuffer); LOG.fine("bytes read="+bytesRead); if( bytesRead==-1 ) { // this occurred on android once, with FileInputStream as my superclass throw new IOException("no data available - available=" + fis.available()); } int dataDescriptorLength = 0; if( Arrays.equals(intBuffer, new byte[] { 0x50, 0x4b, 0x07, 0x08 }) ) { // header does not belong to next file, but is start of the "data descriptor" of last file // skip this data descriptor containing crc32(4), compressedSize(4), uncompressedSize(4) dataDescriptorLength = 4 + 4 + 4; fis.skip( dataDescriptorLength ); // read local file header signature fis.read(intBuffer); } if( !Arrays.equals(intBuffer, new byte[] { 0x50, 0x4b, 0x03, 0x04 }) ) { throw new IOException("wrong local file header signature - value=" + ByteArrayHelper.toString(intBuffer) ); } // info only - if bit-3 is set, current entry is followed by data descriptor boolean hasDataDescriptor = (ze.getMethod() & 8) > 0; LOG.fine( "nextEntry().hasDataDescriptor=" + hasDataDescriptor ); this.compressedSize = ze.getCompressedSize(); fis.skip(14 + 4 + 4); // 14 + localFileHeaderSignature(4) + compressedSize(4) + size(4) byte[] shortBuffer = new byte[2]; fis.read(shortBuffer); int fileNameLength = ByteArrayHelper.toInt(shortBuffer); fis.read(shortBuffer); int extraFieldLength = ByteArrayHelper.toInt(shortBuffer); startPos = 18 + 12 + fileNameLength + extraFieldLength + dataDescriptorLength; currentPos = startPos; endPos = startPos + this.compressedSize; fis.skip( fileNameLength + extraFieldLength ); }
Example 20
Source File: ZipRODirectory.java From ratel with Apache License 2.0 | 4 votes |
@Override public long getCompressedSize(String fileName) throws DirectoryException { ZipEntry entry = getZipFileEntry(fileName); return entry.getCompressedSize(); }