Java Code Examples for net.lingala.zip4j.model.FileHeader#setCompressedSize()

The following examples show how to use net.lingala.zip4j.model.FileHeader#setCompressedSize() . 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: HeaderWriterIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
private List<FileHeader> createFileHeaders(int numberOfEntriesInCentralDirectory, long compressedSize,
                                           long uncompressedSize) {
  List<FileHeader> fileHeaders = new ArrayList<>();

  for (int i = 0; i < numberOfEntriesInCentralDirectory; i++) {
    FileHeader fileHeader = new FileHeader();
    fileHeader.setVersionMadeBy(VERSION_MADE_BY);
    fileHeader.setVersionNeededToExtract(VERSION_NEEDED_TO_EXTRACT);
    fileHeader.setFileName(FILE_NAME_PREFIX + i);
    fileHeader.setGeneralPurposeFlag(generateGeneralPurposeBytes(true));
    fileHeader.setCompressedSize(compressedSize);
    fileHeader.setUncompressedSize(uncompressedSize);
    fileHeader.setCompressionMethod(CompressionMethod.DEFLATE);
    fileHeader.setExternalFileAttributes(EXTERNAL_FILE_ATTRIBUTES);
    fileHeader.setFileComment(FILE_COMMENT_PREFIX + i);
    fileHeaders.add(fileHeader);

  }

  return fileHeaders;
}
 
Example 2
Source File: FileHeaderFactoryTest.java    From zip4j with Apache License 2.0 6 votes vote down vote up
private FileHeader generateFileHeader(long lastModifiedFileTime) {
  FileHeader fileHeader = new FileHeader();
  fileHeader.setVersionNeededToExtract(20);
  fileHeader.setCompressionMethod(CompressionMethod.STORE);
  fileHeader.setLastModifiedTime(lastModifiedFileTime);
  fileHeader.setUncompressedSize(1000L);
  fileHeader.setFileName(FILE_NAME_IN_ZIP);
  fileHeader.setFileNameLength(FILE_NAME_IN_ZIP.getBytes(InternalZipConstants.CHARSET_UTF_8).length);
  fileHeader.setEncrypted(true);
  fileHeader.setEncryptionMethod(EncryptionMethod.AES);
  fileHeader.setCrc(1231231L);
  fileHeader.setCompressedSize(23523L);
  fileHeader.setGeneralPurposeFlag(new byte[] {2, 28});
  fileHeader.setDataDescriptorExists(true);
  fileHeader.setExtraFieldLength(190);
  return fileHeader;
}
 
Example 3
Source File: HeaderReader.java    From zip4j with Apache License 2.0 5 votes vote down vote up
private void readZip64ExtendedInfo(FileHeader fileHeader, RawIO rawIO) throws ZipException {
  if (fileHeader.getExtraDataRecords() == null || fileHeader.getExtraDataRecords().size() <= 0) {
    return;
  }

  Zip64ExtendedInfo zip64ExtendedInfo = readZip64ExtendedInfo(fileHeader.getExtraDataRecords(), rawIO,
      fileHeader.getUncompressedSize(), fileHeader.getCompressedSize(), fileHeader.getOffsetLocalHeader(),
      fileHeader.getDiskNumberStart());

  if (zip64ExtendedInfo == null) {
    return;
  }

  fileHeader.setZip64ExtendedInfo(zip64ExtendedInfo);

  if (zip64ExtendedInfo.getUncompressedSize() != -1) {
    fileHeader.setUncompressedSize(zip64ExtendedInfo.getUncompressedSize());
  }

  if (zip64ExtendedInfo.getCompressedSize() != -1) {
    fileHeader.setCompressedSize(zip64ExtendedInfo.getCompressedSize());
  }

  if (zip64ExtendedInfo.getOffsetLocalHeader() != -1) {
    fileHeader.setOffsetLocalHeader(zip64ExtendedInfo.getOffsetLocalHeader());
  }

  if (zip64ExtendedInfo.getDiskNumberStart() != -1) {
    fileHeader.setDiskNumberStart(zip64ExtendedInfo.getDiskNumberStart());
  }
}
 
Example 4
Source File: HeaderReader.java    From AndroidZip with Apache License 2.0 5 votes vote down vote up
/**
 * Reads Zip64 Extended info and saves it in the {@link FileHeader}
 * @param fileHeader
 * @throws ZipException
 */
private void readAndSaveZip64ExtendedInfo(FileHeader fileHeader) throws ZipException {
	if (fileHeader == null) {
		throw new ZipException("file header is null in reading Zip64 Extended Info");
	}
	
	if (fileHeader.getExtraDataRecords() == null || fileHeader.getExtraDataRecords().size() <= 0) {
		return;
	}
	
	Zip64ExtendedInfo zip64ExtendedInfo = readZip64ExtendedInfo(
			fileHeader.getExtraDataRecords(), 
			fileHeader.getUncompressedSize(), 
			fileHeader.getCompressedSize(), 
			fileHeader.getOffsetLocalHeader(), 
			fileHeader.getDiskNumberStart());
	
	if (zip64ExtendedInfo != null) {
		fileHeader.setZip64ExtendedInfo(zip64ExtendedInfo);
		if (zip64ExtendedInfo.getUnCompressedSize() != -1)
			fileHeader.setUncompressedSize(zip64ExtendedInfo.getUnCompressedSize());
		
		if (zip64ExtendedInfo.getCompressedSize() != -1)
			fileHeader.setCompressedSize(zip64ExtendedInfo.getCompressedSize());
		
		if (zip64ExtendedInfo.getOffsetLocalHeader() != -1)
			fileHeader.setOffsetLocalHeader(zip64ExtendedInfo.getOffsetLocalHeader());
		
		if (zip64ExtendedInfo.getDiskNumberStart() != -1)
			fileHeader.setDiskNumberStart(zip64ExtendedInfo.getDiskNumberStart());
	}
}