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

The following examples show how to use net.lingala.zip4j.model.FileHeader#getDiskNumberStart() . 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: MergeSplitZipFileTask.java    From zip4j with Apache License 2.0 5 votes vote down vote up
private void updateFileHeaderOffsetsForIndex(List<FileHeader> fileHeaders, long offsetToAdd, int index,
                                             int splitSignatureOverhead) {
  for (FileHeader fileHeader : fileHeaders) {
    if (fileHeader.getDiskNumberStart() == index) {
      fileHeader.setOffsetLocalHeader(fileHeader.getOffsetLocalHeader() + offsetToAdd - splitSignatureOverhead);
      fileHeader.setDiskNumberStart(0);
    }
  }
}
 
Example 2
Source File: HeaderWriter.java    From zip4j with Apache License 2.0 5 votes vote down vote up
public void updateLocalFileHeader(FileHeader fileHeader, ZipModel zipModel, SplitOutputStream outputStream)
    throws IOException {

  if (fileHeader == null || zipModel == null) {
    throw new ZipException("invalid input parameters, cannot update local file header");
  }

  boolean closeFlag = false;
  SplitOutputStream currOutputStream;

  if (fileHeader.getDiskNumberStart() != outputStream.getCurrentSplitFileCounter()) {
    String parentFile = zipModel.getZipFile().getParent();
    String fileNameWithoutExt = getZipFileNameWithoutExtension(zipModel.getZipFile().getName());
    String fileName = parentFile + System.getProperty("file.separator");
    if (fileHeader.getDiskNumberStart() < 9) {
      fileName += fileNameWithoutExt + ".z0" + (fileHeader.getDiskNumberStart() + 1);
    } else {
      fileName += fileNameWithoutExt + ".z" + (fileHeader.getDiskNumberStart() + 1);
    }
    currOutputStream = new SplitOutputStream(new File(fileName));
    closeFlag = true;
  } else {
    currOutputStream = outputStream;
  }

  long currOffset = currOutputStream.getFilePointer();

  currOutputStream.seek(fileHeader.getOffsetLocalHeader() + InternalZipConstants.UPDATE_LFH_CRC);
  rawIO.writeLongLittleEndian(longBuff, 0, fileHeader.getCrc());
  currOutputStream.write(longBuff, 0, 4);

  updateFileSizesInLocalFileHeader(currOutputStream, fileHeader);

  if (closeFlag) {
    currOutputStream.close();
  } else {
    outputStream.seek(currOffset);
  }
}
 
Example 3
Source File: HeaderWriter.java    From zip4j with Apache License 2.0 5 votes vote down vote up
private long countNumberOfFileHeaderEntriesOnDisk(List<FileHeader> fileHeaders, int numOfDisk) throws ZipException {
  if (fileHeaders == null) {
    throw new ZipException("file headers are null, cannot calculate number of entries on this disk");
  }

  int noEntries = 0;
  for (FileHeader fileHeader : fileHeaders) {
    if (fileHeader.getDiskNumberStart() == numOfDisk) {
      noEntries++;
    }
  }
  return noEntries;
}
 
Example 4
Source File: SplitInputStream.java    From zip4j with Apache License 2.0 5 votes vote down vote up
public void prepareExtractionForFileHeader(FileHeader fileHeader) throws IOException {

    if (isSplitZipArchive && (currentSplitFileCounter != fileHeader.getDiskNumberStart())) {
      openRandomAccessFileForIndex(fileHeader.getDiskNumberStart());
      currentSplitFileCounter = fileHeader.getDiskNumberStart();
    }

    randomAccessFile.seek(fileHeader.getOffsetLocalHeader());
  }
 
Example 5
Source File: HeaderWriter.java    From AndroidZip with Apache License 2.0 5 votes vote down vote up
private int countNumberOfFileHeaderEntriesOnDisk(ArrayList fileHeaders, 
		int numOfDisk) throws ZipException {
	if (fileHeaders == null) {
		throw new ZipException("file headers are null, cannot calculate number of entries on this disk");
	}
	
	int noEntries = 0;
	for (int i = 0; i < fileHeaders.size(); i++) {
		FileHeader fileHeader = (FileHeader)fileHeaders.get(i);
		if (fileHeader.getDiskNumberStart() == numOfDisk) {
			noEntries++;
		}
	}
	return noEntries;
}
 
Example 6
Source File: HeaderWriter.java    From zip4j with Apache License 2.0 4 votes vote down vote up
private boolean isZip64Entry(FileHeader fileHeader) {
  return fileHeader.getCompressedSize() >= ZIP_64_SIZE_LIMIT
      || fileHeader.getUncompressedSize() >= ZIP_64_SIZE_LIMIT
      || fileHeader.getOffsetLocalHeader() >= ZIP_64_SIZE_LIMIT
      || fileHeader.getDiskNumberStart() >= ZIP_64_NUMBER_OF_ENTRIES_LIMIT;
}