Java Code Examples for net.lingala.zip4j.model.FileHeader#getGeneralPurposeFlag()
The following examples show how to use
net.lingala.zip4j.model.FileHeader#getGeneralPurposeFlag() .
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: ZipOutputStreamIT.java From zip4j with Apache License 2.0 | 6 votes |
private void verifyEntries() throws ZipException { ZipFile zipFile = new ZipFile(generatedZipFile); for (FileHeader fileHeader : zipFile.getFileHeaders()) { byte[] generalPurposeBytes = fileHeader.getGeneralPurposeFlag(); assertThat(BitUtils.isBitSet(generalPurposeBytes[0], 3)).isTrue(); if (fileHeader.isEncrypted() && fileHeader.getEncryptionMethod().equals(EncryptionMethod.AES)) { if (fileHeader.getAesExtraDataRecord().getAesVersion().equals(AesVersion.TWO)) { assertThat(fileHeader.getCrc()).isZero(); } else if (fileHeader.getCompressedSize() > 0) { assertThat(fileHeader.getCrc()).isNotZero(); } } } }
Example 2
Source File: HeaderReaderIT.java From zip4j with Apache License 2.0 | 5 votes |
private void testWithoutUtf8FileName(String fileName, String entryComment, boolean shouldFileNamesMatch, boolean unsetUtf8Flag, Charset charsetToUseForReading) throws IOException { ZipModel actualZipModel = generateZipModel(3); FileHeader secondFileHeader = actualZipModel.getCentralDirectory().getFileHeaders().get(1); if (unsetUtf8Flag) { // Unset utf8 flag byte[] generalPurposeBytes = secondFileHeader.getGeneralPurposeFlag(); generalPurposeBytes[1] = BitUtils.unsetBit(generalPurposeBytes[1], 3); secondFileHeader.setGeneralPurposeFlag(generalPurposeBytes); } secondFileHeader.setFileName(fileName); secondFileHeader.setFileComment(entryComment); File headersFile = writeZipHeaders(actualZipModel); actualZipModel.setZipFile(headersFile); try(RandomAccessFile randomAccessFile = new RandomAccessFile(actualZipModel.getZipFile(), RandomAccessFileMode.READ.getValue())) { ZipModel readZipModel = headerReader.readAllHeaders(randomAccessFile, charsetToUseForReading); FileHeader fileHeader = readZipModel.getCentralDirectory().getFileHeaders().get(1); if (shouldFileNamesMatch) { assertThat(fileHeader.getFileName()).isEqualTo(fileName); assertThat(fileHeader.getFileComment()).isEqualTo(entryComment); } else { assertThat(fileHeader.getFileName()).isNotEqualTo(fileName); assertThat(fileHeader.getFileComment()).isNotEqualTo(entryComment); } assertThat(readZipModel.getCentralDirectory().getFileHeaders().get(0).getFileCommentLength()).isEqualTo(0); assertThat(readZipModel.getCentralDirectory().getFileHeaders().get(0).getFileComment()).isNull(); assertThat(readZipModel.getCentralDirectory().getFileHeaders().get(2).getFileCommentLength()).isEqualTo(0); assertThat(readZipModel.getCentralDirectory().getFileHeaders().get(2).getFileComment()).isNull(); } }