@Override public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length) { super.parseFromCentralDirectoryData(data, offset, length); this.rcount = ZipShort.getValue(data, offset); this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2)); } }
/** * Whether the compressed size for the entry is either known or * not required by the compression method being used. */ private boolean supportsCompressedSizeFor(final ZipArchiveEntry entry) { return entry.getCompressedSize() != ArchiveEntry.SIZE_UNKNOWN || entry.getMethod() == ZipEntry.DEFLATED || entry.getMethod() == ZipMethod.ENHANCED_DEFLATED.getCode() || (entry.getGeneralPurposeBit().usesDataDescriptor() && allowStoredEntriesWithDataDescriptor && entry.getMethod() == ZipEntry.STORED); }
/** * Get the central data length. * If there is no central data, get the local file data length. * @return the central data length */ @Override public ZipShort getCentralDirectoryLength() { if (centralData != null) { return new ZipShort(centralData.length); } return getLocalFileDataLength(); }
@Test public void test1() throws IOException { ZipArchiveInputStream zis = new ZipArchiveInputStream(BadZipEntryFlagTest.class.getResourceAsStream("/bad.zip")); for (ZipArchiveEntry e = zis.getNextZipEntry(); e != null; e = zis.getNextZipEntry()) { e.getGeneralPurposeBit().useEncryption(false); if (!e.isDirectory()) { zis.read(); System.out.println(e.getName()); } } }
private void writeLocalFileHeader(final ZipArchiveEntry ze, final boolean phased) throws IOException { final boolean encodable = zipEncoding.canEncode(ze.getName()); final ByteBuffer name = getName(ze); if (createUnicodeExtraFields != UnicodeExtraFieldPolicy.NEVER) { addUnicodeExtraFields(ze, encodable, name); } final long localHeaderStart = streamCompressor.getTotalBytesWritten(); final byte[] localHeader = createLocalFileHeader(ze, name, encodable, phased, localHeaderStart); metaData.put(ze, new EntryMetaData(localHeaderStart, usesDataDescriptor(ze.getMethod(), phased))); entry.localDataStart = localHeaderStart + LFH_CRC_OFFSET; // At crc offset writeCounted(localHeader); entry.dataStart = streamCompressor.getTotalBytesWritten(); }
@Override public void putArchiveEntry(final ArchiveEntry ze) throws IOException { if (!jarMarkerAdded) { ((ZipArchiveEntry)ze).addAsFirstExtraField(JarMarker.getInstance()); jarMarkerAdded = true; } super.putArchiveEntry(ze); } }
/** * Whether this library supports the encryption used by the given * entry. * * @return true if the entry isn't encrypted at all */ private static boolean supportsEncryptionOf(final ZipArchiveEntry entry) { return !entry.getGeneralPurposeBit().usesEncryption(); }
/** * Ensures all bytes sent to the deflater are written to the stream. */ private void flushDeflater() throws IOException { if (entry.entry.getMethod() == DEFLATED) { streamCompressor.flushDeflater(); } }
@Override public int read() throws IOException { if (!buffer.available()) { fillBuffer(); } final int ret = buffer.get(); if (ret > -1) { uncompressedCount++; } return ret; }
@Override public ZipShort getCentralDirectoryLength() { if (data == null) { assembleData(); } return new ZipShort(data != null ? data.length : 0); }
/** * Length of the complete extra field in the central directory. * * @return The CentralDirectoryLength value */ @Override public ZipShort getCentralDirectoryLength() { return centralDirectoryData == null ? getLocalFileDataLength() : new ZipShort(centralDirectoryData.length); }
/** * Retrieves the extra data for the central directory. * @return the central directory extra data */ public byte[] getCentralDirectoryExtra() { return ExtraFieldUtils.mergeCentralDirectoryData(getAllExtraFieldsNoCopy()); }
/** * Creates new BoundedInputStream, according to implementation of * underlying archive channel. */ private BoundedInputStream createBoundedInputStream(long start, long remaining) { return archive instanceof FileChannel ? new BoundedFileChannelInputStream(start, remaining) : new BoundedInputStream(start, remaining); }
@Override public int hashCode() { return 3 * super.hashCode() + (int) getLocalHeaderOffset()+(int)(getLocalHeaderOffset()>>32); }
/** * Get the central data. * @return the central data if present, else return the local file data */ @Override public byte[] getCentralDirectoryData() { if (centralData != null) { return ZipUtil.copy(centralData); } return getLocalFileDataData(); }
/** * The actual data to put into central directory. * * @return The CentralDirectoryData value */ @Override public byte[] getCentralDirectoryData() { return centralDirectoryData == null ? getLocalFileDataData() : ZipUtil.copy(centralDirectoryData); }
@Override public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length) { super.parseFromCentralDirectoryData(data, offset, length); parseCentralDirectoryFormat(data, offset, length); } }
/** * Get the central data. * * @return the central data if present, else return the local file data */ @Override public byte[] getCentralDirectoryData() { if (centralData != null) { return ZipUtil.copy(centralData); } return getLocalFileDataData(); }
@Override public void parseFromLocalFileData(final byte[] data, final int offset, final int length) { super.parseFromLocalFileData(data, offset, length); parseFileFormat(data, offset, length); }