Java Code Examples for net.lingala.zip4j.model.LocalFileHeader#setFileNameLength()
The following examples show how to use
net.lingala.zip4j.model.LocalFileHeader#setFileNameLength() .
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: FileHeaderFactory.java From zip4j with Apache License 2.0 | 6 votes |
public LocalFileHeader generateLocalFileHeader(FileHeader fileHeader) { LocalFileHeader localFileHeader = new LocalFileHeader(); localFileHeader.setSignature(HeaderSignature.LOCAL_FILE_HEADER); localFileHeader.setVersionNeededToExtract(fileHeader.getVersionNeededToExtract()); localFileHeader.setCompressionMethod(fileHeader.getCompressionMethod()); localFileHeader.setLastModifiedTime(fileHeader.getLastModifiedTime()); localFileHeader.setUncompressedSize(fileHeader.getUncompressedSize()); localFileHeader.setFileNameLength(fileHeader.getFileNameLength()); localFileHeader.setFileName(fileHeader.getFileName()); localFileHeader.setEncrypted(fileHeader.isEncrypted()); localFileHeader.setEncryptionMethod(fileHeader.getEncryptionMethod()); localFileHeader.setAesExtraDataRecord(fileHeader.getAesExtraDataRecord()); localFileHeader.setCrc(fileHeader.getCrc()); localFileHeader.setCompressedSize(fileHeader.getCompressedSize()); localFileHeader.setGeneralPurposeFlag(fileHeader.getGeneralPurposeFlag().clone()); localFileHeader.setDataDescriptorExists(fileHeader.isDataDescriptorExists()); localFileHeader.setExtraFieldLength(fileHeader.getExtraFieldLength()); return localFileHeader; }
Example 2
Source File: HeaderReader.java From zip4j with Apache License 2.0 | 4 votes |
public LocalFileHeader readLocalFileHeader(InputStream inputStream, Charset charset) throws IOException { LocalFileHeader localFileHeader = new LocalFileHeader(); byte[] intBuff = new byte[4]; //signature int sig = rawIO.readIntLittleEndian(inputStream); if (sig != HeaderSignature.LOCAL_FILE_HEADER.getValue()) { return null; } localFileHeader.setSignature(HeaderSignature.LOCAL_FILE_HEADER); localFileHeader.setVersionNeededToExtract(rawIO.readShortLittleEndian(inputStream)); byte[] generalPurposeFlags = new byte[2]; if (readFully(inputStream, generalPurposeFlags) != 2) { throw new ZipException("Could not read enough bytes for generalPurposeFlags"); } localFileHeader.setEncrypted(isBitSet(generalPurposeFlags[0], 0)); localFileHeader.setDataDescriptorExists(isBitSet(generalPurposeFlags[0], 3)); localFileHeader.setFileNameUTF8Encoded(isBitSet(generalPurposeFlags[1], 3)); localFileHeader.setGeneralPurposeFlag(generalPurposeFlags.clone()); localFileHeader.setCompressionMethod(CompressionMethod.getCompressionMethodFromCode( rawIO.readShortLittleEndian(inputStream))); localFileHeader.setLastModifiedTime(rawIO.readIntLittleEndian(inputStream)); readFully(inputStream, intBuff); localFileHeader.setCrc(rawIO.readLongLittleEndian(intBuff, 0)); localFileHeader.setCrcRawData(intBuff.clone()); localFileHeader.setCompressedSize(rawIO.readLongLittleEndian(inputStream, 4)); localFileHeader.setUncompressedSize(rawIO.readLongLittleEndian(inputStream, 4)); int fileNameLength = rawIO.readShortLittleEndian(inputStream); localFileHeader.setFileNameLength(fileNameLength); localFileHeader.setExtraFieldLength(rawIO.readShortLittleEndian(inputStream)); if (fileNameLength > 0) { byte[] fileNameBuf = new byte[fileNameLength]; readFully(inputStream, fileNameBuf); // Modified after user reported an issue http://www.lingala.net/zip4j/forum/index.php?topic=2.0 // String fileName = new String(fileNameBuf, "Cp850"); // String fileName = Zip4jUtil.getCp850EncodedString(fileNameBuf); String fileName = decodeStringWithCharset(fileNameBuf, localFileHeader.isFileNameUTF8Encoded(), charset); if (fileName == null) { throw new ZipException("file name is null, cannot assign file name to local file header"); } if (fileName.contains(":" + System.getProperty("file.separator"))) { fileName = fileName.substring(fileName.indexOf(":" + System.getProperty("file.separator")) + 2); } localFileHeader.setFileName(fileName); localFileHeader.setDirectory(fileName.endsWith("/") || fileName.endsWith("\\")); } else { localFileHeader.setFileName(null); } readExtraDataRecords(inputStream, localFileHeader); readZip64ExtendedInfo(localFileHeader, rawIO); readAesExtraDataRecord(localFileHeader, rawIO); if (localFileHeader.isEncrypted()) { if (localFileHeader.getEncryptionMethod() == EncryptionMethod.AES) { //Do nothing } else { if (BigInteger.valueOf(localFileHeader.getGeneralPurposeFlag()[0]).testBit(6)) { localFileHeader.setEncryptionMethod(EncryptionMethod.ZIP_STANDARD_VARIANT_STRONG); } else { localFileHeader.setEncryptionMethod(EncryptionMethod.ZIP_STANDARD); } } } return localFileHeader; }