net.lingala.zip4j.model.ZipModel.getCentralDirectory()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(13.1k)|赞(0)|评价(0)|浏览(94)

本文整理了Java中net.lingala.zip4j.model.ZipModel.getCentralDirectory()方法的一些代码示例,展示了ZipModel.getCentralDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipModel.getCentralDirectory()方法的具体详情如下:
包路径:net.lingala.zip4j.model.ZipModel
类名称:ZipModel
方法名:getCentralDirectory

ZipModel.getCentralDirectory介绍

暂无

代码示例

代码示例来源:origin: net.lingala.zip4j/zip4j

/**
 * Returns the list of file headers in the zip file. Throws an exception if the 
 * zip file does not exist
 * @return list of file headers
 * @throws ZipException
 */
public List getFileHeaders() throws ZipException {
  readZipInfo();
  if (zipModel == null || zipModel.getCentralDirectory() == null) {
    return null;
  }
  return zipModel.getCentralDirectory().getFileHeaders();
}

代码示例来源:origin: com.github.axet/zip4j

/**
 * Returns the list of file headers in the zip file. Throws an exception if the 
 * zip file does not exist
 * @return list of file headers
 * @throws ZipException
 */
public List getFileHeaders() throws ZipException {
  readZipInfo();
  if (zipModel == null || zipModel.getCentralDirectory() == null) {
    return null;
  }
  return zipModel.getCentralDirectory().getFileHeaders();
}

代码示例来源:origin: net.lingala.zip4j/zip4j

/**
 * Writes central directory header data to an array list
 * @param zipModel
 * @param outputStream
 * @param headerBytesList
 * @return size of central directory
 * @throws ZipException
 */
private int writeCentralDirectory(ZipModel zipModel, 
    OutputStream outputStream, List headerBytesList) throws ZipException {
  if (zipModel == null || outputStream == null) {
    throw new ZipException("input parameters is null, cannot write central directory");
  }
  
  if (zipModel.getCentralDirectory() == null || 
      zipModel.getCentralDirectory().getFileHeaders() == null || 
      zipModel.getCentralDirectory().getFileHeaders().size() <= 0) {
    return 0;
  }
  
  int sizeOfCentralDir = 0;
  for (int i = 0; i < zipModel.getCentralDirectory().getFileHeaders().size(); i++) {
    FileHeader fileHeader = (FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i);
    int sizeOfFileHeader = writeFileHeader(zipModel, fileHeader, outputStream, headerBytesList);
    sizeOfCentralDir += sizeOfFileHeader;
  }
  return sizeOfCentralDir;
}

代码示例来源:origin: com.github.axet/zip4j

/**
 * Writes central directory header data to an array list
 * @param zipModel
 * @param outputStream
 * @param headerBytesList
 * @return size of central directory
 * @throws ZipException
 */
private int writeCentralDirectory(ZipModel zipModel, 
    NativeFile outputStream, List headerBytesList) throws ZipException {
  if (zipModel == null || outputStream == null) {
    throw new ZipException("input parameters is null, cannot write central directory");
  }
  
  if (zipModel.getCentralDirectory() == null || 
      zipModel.getCentralDirectory().getFileHeaders() == null || 
      zipModel.getCentralDirectory().getFileHeaders().size() <= 0) {
    return 0;
  }
  
  int sizeOfCentralDir = 0;
  for (int i = 0; i < zipModel.getCentralDirectory().getFileHeaders().size(); i++) {
    FileHeader fileHeader = (FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i);
    int sizeOfFileHeader = writeFileHeader(zipModel, fileHeader, outputStream, headerBytesList);
    sizeOfCentralDir += sizeOfFileHeader;
  }
  return sizeOfCentralDir;
}

代码示例来源:origin: net.lingala.zip4j/zip4j

/**
 * Sets the password for the zip file
 * @param password
 * @throws ZipException
 */
public void setPassword(char[] password) throws ZipException {
  if (zipModel == null) {
    readZipInfo();
    if (zipModel == null) {
      throw new ZipException("Zip Model is null");
    }
  }
  
  if (zipModel.getCentralDirectory() == null || zipModel.getCentralDirectory().getFileHeaders() == null) {
    throw new ZipException("invalid zip file");
  }
  
  for (int i = 0; i < zipModel.getCentralDirectory().getFileHeaders().size(); i++) {
    if (zipModel.getCentralDirectory().getFileHeaders().get(i) != null) {
      if (((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).isEncrypted()) {
        ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).setPassword(password);
      }
    }
  }
}

代码示例来源:origin: com.github.axet/zip4j

/**
 * Sets the password for the zip file
 * @param password
 * @throws ZipException
 */
public void setPassword(char[] password) throws ZipException {
  if (zipModel == null) {
    readZipInfo();
    if (zipModel == null) {
      throw new ZipException("Zip Model is null");
    }
  }
  
  if (zipModel.getCentralDirectory() == null || zipModel.getCentralDirectory().getFileHeaders() == null) {
    throw new ZipException("invalid zip file");
  }
  
  for (int i = 0; i < zipModel.getCentralDirectory().getFileHeaders().size(); i++) {
    if (zipModel.getCentralDirectory().getFileHeaders().get(i) != null) {
      if (((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).isEncrypted()) {
        ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).setPassword(password);
      }
    }
  }
}

代码示例来源:origin: com.github.axet/zip4j

private void updateSplitFileHeader(ZipModel zipModel, ArrayList fileSizeList, boolean splitSigRemoved) throws ZipException {
  try {
    if (zipModel.getCentralDirectory()== null) {
      throw new ZipException("corrupt zip model - getCentralDirectory, cannot update split zip model");
    int fileHeaderCount = zipModel.getCentralDirectory().getFileHeaders().size();
    int splitSigOverhead = 0;
    if (splitSigRemoved)
      long offsetLHToAdd = 0;
      for (int j = 0; j < ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).getDiskNumberStart(); j++) {
        offsetLHToAdd += ((Long)fileSizeList.get(j)).longValue();
      ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).setOffsetLocalHeader(
          ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).getOffsetLocalHeader() +
          offsetLHToAdd - splitSigOverhead);
      ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).setDiskNumberStart(0);

代码示例来源:origin: net.lingala.zip4j/zip4j

private void updateSplitFileHeader(ZipModel zipModel, ArrayList fileSizeList, boolean splitSigRemoved) throws ZipException {
  try {
    if (zipModel.getCentralDirectory()== null) {
      throw new ZipException("corrupt zip model - getCentralDirectory, cannot update split zip model");
    int fileHeaderCount = zipModel.getCentralDirectory().getFileHeaders().size();
    int splitSigOverhead = 0;
    if (splitSigRemoved)
      long offsetLHToAdd = 0;
      for (int j = 0; j < ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).getDiskNumberStart(); j++) {
        offsetLHToAdd += ((Long)fileSizeList.get(j)).longValue();
      ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).setOffsetLocalHeader(
          ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).getOffsetLocalHeader() +
          offsetLHToAdd - splitSigOverhead);
      ((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).setDiskNumberStart(0);

代码示例来源:origin: net.lingala.zip4j/zip4j

if (zipModel.getCentralDirectory() == null || zipModel.getCentralDirectory().getFileHeaders() == null) {
  throw new ZipException("invalid zip file");
ArrayList fileHeaderList = zipModel.getCentralDirectory().getFileHeaders();
for (int i = 0; i < fileHeaderList.size(); i++) {
  FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);

代码示例来源:origin: net.lingala.zip4j/zip4j

if (zipModel.getCentralDirectory() == null) {
  throw new ZipException("central directory is null, cannot determine file header with exact match for fileName: " + fileName);
if (zipModel.getCentralDirectory().getFileHeaders() == null) {
  throw new ZipException("file Headers are null, cannot determine file header with exact match for fileName: " + fileName);
if (zipModel.getCentralDirectory().getFileHeaders().size() <= 0) {
  return null;
ArrayList fileHeaders = zipModel.getCentralDirectory().getFileHeaders();
for (int i = 0; i < fileHeaders.size(); i++) {
  FileHeader fileHeader = (FileHeader)fileHeaders.get(i);

代码示例来源:origin: com.github.axet/zip4j

if (zipModel.getCentralDirectory() == null) {
  throw new ZipException("central directory is null, cannot determine file header with exact match for fileName: " + fileName);
if (zipModel.getCentralDirectory().getFileHeaders() == null) {
  throw new ZipException("file Headers are null, cannot determine file header with exact match for fileName: " + fileName);
if (zipModel.getCentralDirectory().getFileHeaders().size() <= 0) {
  return null;
ArrayList fileHeaders = zipModel.getCentralDirectory().getFileHeaders();
for (int i = 0; i < fileHeaders.size(); i++) {
  FileHeader fileHeader = (FileHeader)fileHeaders.get(i);

代码示例来源:origin: net.lingala.zip4j/zip4j

if (zipModel.getCentralDirectory() != null && 
    zipModel.getCentralDirectory().getFileHeaders() != null && 
    zipModel.getCentralDirectory().getFileHeaders().size() > 0) {
  String relativeFileName = Zip4jUtil.getRelativeFileName(
      ((File)fileList.get(i)).getAbsolutePath(), parameters.getRootFolderInZip(), parameters.getDefaultFolderPath());

代码示例来源:origin: net.lingala.zip4j/zip4j

private void updateSplitEndCentralDirectory(ZipModel zipModel) throws ZipException {
  try {
    if (zipModel == null) {
      throw new ZipException("zip model is null - cannot update end of central directory for split zip model");
    }
    
    if (zipModel.getCentralDirectory()== null) {
      throw new ZipException("corrupt zip model - getCentralDirectory, cannot update split zip model");
    }
    
    zipModel.getEndCentralDirRecord().setNoOfThisDisk(0);
    zipModel.getEndCentralDirRecord().setNoOfThisDiskStartOfCentralDir(0);
    zipModel.getEndCentralDirRecord().setTotNoOfEntriesInCentralDir(
        zipModel.getCentralDirectory().getFileHeaders().size());
    zipModel.getEndCentralDirRecord().setTotNoOfEntriesInCentralDirOnThisDisk(
        zipModel.getCentralDirectory().getFileHeaders().size());
    
  } catch (ZipException e) {
    throw e;
  } catch (Exception e) {
    throw new ZipException(e);
  }
}

代码示例来源:origin: com.github.axet/zip4j

private void updateSplitEndCentralDirectory(ZipModel zipModel) throws ZipException {
  try {
    if (zipModel == null) {
      throw new ZipException("zip model is null - cannot update end of central directory for split zip model");
    }
    
    if (zipModel.getCentralDirectory()== null) {
      throw new ZipException("corrupt zip model - getCentralDirectory, cannot update split zip model");
    }
    
    zipModel.getEndCentralDirRecord().setNoOfThisDisk(0);
    zipModel.getEndCentralDirRecord().setNoOfThisDiskStartOfCentralDir(0);
    zipModel.getEndCentralDirRecord().setTotNoOfEntriesInCentralDir(
        zipModel.getCentralDirectory().getFileHeaders().size());
    zipModel.getEndCentralDirRecord().setTotNoOfEntriesInCentralDirOnThisDisk(
        zipModel.getCentralDirectory().getFileHeaders().size());
    
  } catch (ZipException e) {
    throw e;
  } catch (Exception e) {
    throw new ZipException(e);
  }
}

代码示例来源:origin: net.lingala.zip4j/zip4j

/**
 * Returns FileHeader if a file header with the given fileHeader 
 * string exists in the zip model: If not returns null
 * @param fileName
 * @return FileHeader
 * @throws ZipException
 */
public FileHeader getFileHeader(String fileName) throws ZipException {
  if (!Zip4jUtil.isStringNotNullAndNotEmpty(fileName)) {
    throw new ZipException("input file name is emtpy or null, cannot get FileHeader");
  }
  
  readZipInfo();
  if (zipModel == null || zipModel.getCentralDirectory() == null) {
    return null;
  }
  
  return Zip4jUtil.getFileHeader(zipModel, fileName);
}

代码示例来源:origin: com.github.axet/zip4j

/**
 * Returns FileHeader if a file header with the given fileHeader 
 * string exists in the zip model: If not returns null
 * @param fileName
 * @return FileHeader
 * @throws ZipException
 */
public FileHeader getFileHeader(String fileName) throws ZipException {
  if (!Zip4jUtil.isStringNotNullAndNotEmpty(fileName)) {
    throw new ZipException("input file name is emtpy or null, cannot get FileHeader");
  }
  
  readZipInfo();
  if (zipModel == null || zipModel.getCentralDirectory() == null) {
    return null;
  }
  
  return Zip4jUtil.getFileHeader(zipModel, fileName);
}

代码示例来源:origin: com.github.axet/zip4j

private void initZipModel(ZipModel zipModel) {
  if (zipModel == null) {
    this.zipModel = new ZipModel();
  } else {
    this.zipModel = zipModel;
  }
  
  if (this.zipModel.getEndCentralDirRecord() == null)
    this.zipModel.setEndCentralDirRecord(new EndCentralDirRecord());
  
  if (this.zipModel.getCentralDirectory() == null)
    this.zipModel.setCentralDirectory(new CentralDirectory());
  
  if (this.zipModel.getCentralDirectory().getFileHeaders() == null)
    this.zipModel.getCentralDirectory().setFileHeaders(new ArrayList());
  
  if (this.zipModel.getLocalFileHeaderList() == null)
    this.zipModel.setLocalFileHeaderList(new ArrayList());
  
  if (this.outputStream instanceof SplitOutputStream) {
    if (((SplitOutputStream)outputStream).isSplitZipFile()) {
      this.zipModel.setSplitArchive(true);
      this.zipModel.setSplitLength(((SplitOutputStream)outputStream).getSplitLength());
    }
  }
  
  this.zipModel.getEndCentralDirRecord().setSignature(InternalZipConstants.ENDSIG);
}

代码示例来源:origin: net.lingala.zip4j/zip4j

private void initZipModel(ZipModel zipModel) {
  if (zipModel == null) {
    this.zipModel = new ZipModel();
  } else {
    this.zipModel = zipModel;
  }
  
  if (this.zipModel.getEndCentralDirRecord() == null)
    this.zipModel.setEndCentralDirRecord(new EndCentralDirRecord());
  
  if (this.zipModel.getCentralDirectory() == null)
    this.zipModel.setCentralDirectory(new CentralDirectory());
  
  if (this.zipModel.getCentralDirectory().getFileHeaders() == null)
    this.zipModel.getCentralDirectory().setFileHeaders(new ArrayList());
  
  if (this.zipModel.getLocalFileHeaderList() == null)
    this.zipModel.setLocalFileHeaderList(new ArrayList());
  
  if (this.outputStream instanceof SplitOutputStream) {
    if (((SplitOutputStream)outputStream).isSplitZipFile()) {
      this.zipModel.setSplitArchive(true);
      this.zipModel.setSplitLength(((SplitOutputStream)outputStream).getSplitLength());
    }
  }
  
  this.zipModel.getEndCentralDirRecord().setSignature(InternalZipConstants.ENDSIG);
}

代码示例来源:origin: net.lingala.zip4j/zip4j

public void extractAll(final UnzipParameters unzipParameters, final String outPath,
    final ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
  CentralDirectory centralDirectory = zipModel.getCentralDirectory();

代码示例来源:origin: com.github.axet/zip4j

public void extractAll(final UnzipParameters unzipParameters, final String outPath,
    final ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
  CentralDirectory centralDirectory = zipModel.getCentralDirectory();

相关文章