/** * Parses the supported flags from the given archive data. * * @param data local file header or a central directory entry. * @param offset offset at which the general purpose bit starts * @return GeneralPurposeBit */ public static GeneralPurposeBit parse(final byte[] data, final int offset) { final int generalPurposeFlag = ZipShort.getValue(data, offset); GeneralPurposeBit b = new GeneralPurposeBit(); b.useDataDescriptor((generalPurposeFlag & DATA_DESCRIPTOR_FLAG) != 0); b.useUTF8ForNames((generalPurposeFlag & UFT8_NAMES_FLAG) != 0); b.useStrongEncryption((generalPurposeFlag & STRONG_ENCRYPTION_FLAG) != 0); b.useEncryption((generalPurposeFlag & ENCRYPTION_FLAG) != 0); return b; }
/** * Encodes the set bits in a form suitable for ZIP archives. * * @return byte[] */ public byte[] encode() { byte[] result = new byte[2]; encode(result, 0); return result; }
/** * 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(ZipEntry entry) { return !entry.getGeneralPurposeBit().usesEncryption(); }
private GeneralPurposeBit getGeneralPurposeBits(final int zipMethod, final boolean utfFallback) { GeneralPurposeBit b = new GeneralPurposeBit(); b.useUTF8ForNames(useUTF8Flag || utfFallback); if (isDeflatedToOutputStream(zipMethod)) { b.useDataDescriptor(true); } return b; }
final GeneralPurposeBit gpFlag = GeneralPurposeBit.parse(CFH_BUF, off); final boolean hasUTF8Flag = gpFlag.usesUTF8ForNames(); final ZipEncoding entryEncoding = hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
/** * whether the current entry will be encrypted using strong encryption * * @param b boolean */ public void useStrongEncryption(boolean b) { strongEncryptionFlag = b; if (b) { useEncryption(true); } }
&& Arrays.equals(getCentralDirectoryExtra(), other.getCentralDirectoryExtra()) && Arrays.equals(getLocalFileDataExtra(), other.getLocalFileDataExtra()) && gpb.equals(other.gpb);
/** * Creates a new zip entry with fields taken from the specified zip entry. * * <p>Assumes the entry represents a directory if and only if the * name ends with a forward slash "/".</p> * * @param entry the entry to get fields from * @throws ZipException on error * @since 1.1 */ public ZipEntry(final ZipEntry entry) throws ZipException { this((java.util.zip.ZipEntry) entry); setInternalAttributes(entry.getInternalAttributes()); setExternalAttributes(entry.getExternalAttributes()); setExtraFields(getAllExtraFieldsNoCopy()); setPlatform(entry.getPlatform()); GeneralPurposeBit other = entry.getGeneralPurposeBit(); setGeneralPurposeBit(other == null ? null : (GeneralPurposeBit) other.clone()); }
generalPurposeBit.encode(buf, LFH_GPB_OFFSET);
final boolean encodable = zipEncoding.canEncode(ze.getName()); putShort(versionNeededToExtract(zipMethod, needsZip64Extra), buf, CFH_VERSION_NEEDED_OFFSET); getGeneralPurposeBits(zipMethod, !encodable && fallbackToUTF8).encode(buf, CFH_GPB_OFFSET);