net.lingala.zip4j.core.ZipFile.readZipInfo()方法的使用及代码示例

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

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

ZipFile.readZipInfo介绍

[英]Reads the zip header information for this zip file. If the zip file does not exist, then this method throws an exception.

Note: This method does not read local file header information
[中]读取此zip文件的zip头信息。如果zip文件不存在,则此方法引发异常。
注意:此方法不读取本地文件头信息

代码示例

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

/**
 * Checks to see if the input zip file is a valid zip file. This method
 * will try to read zip headers. If headers are read successfully, this
 * method returns true else false 
 * @return boolean
 * @since 1.2.3
 */
public boolean isValidZipFile() {
  try {
    readZipInfo();
    return true;
  } catch (Exception e) {
    return false;
  }
}

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

/**
 * Checks to see if the input zip file is a valid zip file. This method
 * will try to read zip headers. If headers are read successfully, this
 * method returns true else false 
 * @return boolean
 * @since 1.2.3
 */
public boolean isValidZipFile() {
  try {
    readZipInfo();
    return true;
  } catch (Exception e) {
    return false;
  }
}

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

/**
 * Loads the zip model if zip model is null and if zip file exists.
 * @throws ZipException
 */
private void checkZipModel() throws ZipException {
  if (this.zipModel == null) {
    if (Zip4jUtil.checkFileExists(file)) {
      readZipInfo();
    } else {
      createNewZipModel();
    }
  }
}

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

/**
 * Loads the zip model if zip model is null and if zip file exists.
 * @throws ZipException
 */
private void checkZipModel() throws ZipException {
  if (this.zipModel == null) {
    if (Zip4jUtil.checkFileExists(file)) {
      readZipInfo();
    } else {
      createNewZipModel();
    }
  }
}

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

/**
 * Checks if the zip file is a split archive
 * @return true if split archive, false if not
 * @throws ZipException
 */
public boolean isSplitArchive() throws ZipException {
  if (zipModel == null) {
    readZipInfo();
    if (zipModel == null) {
      throw new ZipException("Zip Model is null");
    }
  }
  
  return zipModel.isSplitArchive();

}

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

/**
 * Checks if the zip file is a split archive
 * @return true if split archive, false if not
 * @throws ZipException
 */
public boolean isSplitArchive() throws ZipException {
  if (zipModel == null) {
    readZipInfo();
    if (zipModel == null) {
      throw new ZipException("Zip Model is null");
    }
  }
  
  return zipModel.isSplitArchive();

}

代码示例来源: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

/**
 * 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: net.lingala.zip4j/zip4j

readZipInfo();
if (zipModel == null) {
  throw new ZipException("Zip Model is null");

代码示例来源: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: net.lingala.zip4j/zip4j

/**
 * Extracts a specific file from the zip file to the destination path.
 * If destination path is invalid, then this method throws an exception.
 * @param fileHeader
 * @param destPath
 * @param unzipParameters
 * @param newFileName
 * @throws ZipException
 */
public void extractFile(FileHeader fileHeader, String destPath, 
    UnzipParameters unzipParameters, String newFileName) throws ZipException {
  
  if (fileHeader == null) {
    throw new ZipException("input file header is null, cannot extract file");
  }
  
  if (!Zip4jUtil.isStringNotNullAndNotEmpty(destPath)) {
    throw new ZipException("destination path is empty or null, cannot extract file");
  }
  
  readZipInfo();
  
  if (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
    throw new ZipException("invalid operation - Zip4j is in busy state");
  }
  
  fileHeader.extractFile(zipModel, destPath, unzipParameters, newFileName, progressMonitor, runInThread);
  
}

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

/**
 * Extracts a specific file from the zip file to the destination path.
 * If destination path is invalid, then this method throws an exception.
 * @param fileHeader
 * @param destPath
 * @param unzipParameters
 * @param newFileName
 * @throws ZipException
 */
public void extractFile(FileHeader fileHeader, String destPath, 
    UnzipParameters unzipParameters, String newFileName) throws ZipException {
  
  if (fileHeader == null) {
    throw new ZipException("input file header is null, cannot extract file");
  }
  
  if (!Zip4jUtil.isStringNotNullAndNotEmpty(destPath)) {
    throw new ZipException("destination path is empty or null, cannot extract file");
  }
  
  readZipInfo();
  
  if (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
    throw new ZipException("invalid operation - Zip4j is in busy state");
  }
  
  fileHeader.extractFile(zipModel, destPath, unzipParameters, newFileName, progressMonitor, runInThread);
  
}

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

/**
 * Removes the file provided in the input file header from the zip file.
 * If zip file is a split zip file, then this method throws an exception as
 * zip specification does not allow for updating split zip archives.
 * @param fileHeader
 * @throws ZipException
 */
public void removeFile(FileHeader fileHeader) throws ZipException {
  if (fileHeader == null) {
    throw new ZipException("file header is null, cannot remove file");
  }
  
  if (zipModel == null) {
    if (Zip4jUtil.checkFileExists(file)) {
      readZipInfo();
    }
  }
  
  if (zipModel.isSplitArchive()) {
    throw new ZipException("Zip file format does not allow updating split/spanned files");
  }
  
  ArchiveMaintainer archiveMaintainer = new ArchiveMaintainer();
  archiveMaintainer.initProgressMonitorForRemoveOp(zipModel, fileHeader, progressMonitor);
  archiveMaintainer.removeZipFile(zipModel, fileHeader, progressMonitor, runInThread);
}

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

/**
 * Removes the file provided in the input file header from the zip file.
 * If zip file is a split zip file, then this method throws an exception as
 * zip specification does not allow for updating split zip archives.
 * @param fileHeader
 * @throws ZipException
 */
public void removeFile(FileHeader fileHeader) throws ZipException {
  if (fileHeader == null) {
    throw new ZipException("file header is null, cannot remove file");
  }
  
  if (zipModel == null) {
    if (Zip4jUtil.checkFileExists(file)) {
      readZipInfo();
    }
  }
  
  if (zipModel.isSplitArchive()) {
    throw new ZipException("Zip file format does not allow updating split/spanned files");
  }
  
  ArchiveMaintainer archiveMaintainer = new ArchiveMaintainer();
  archiveMaintainer.initProgressMonitorForRemoveOp(zipModel, fileHeader, progressMonitor);
  archiveMaintainer.removeZipFile(zipModel, fileHeader, progressMonitor, runInThread);
}

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

/**
 * Sets comment for the Zip file
 * @param comment
 * @throws ZipException
 */
public void setComment(String comment) throws ZipException {
  if (comment == null) {
    throw new ZipException("input comment is null, cannot update zip file");
  }
  
  if (!Zip4jUtil.checkFileExists(file)) {
    throw new ZipException("zip file does not exist, cannot set comment for zip file");
  }
  
  readZipInfo();
  
  if (this.zipModel == null) {
    throw new ZipException("zipModel is null, cannot update zip file");
  }
  
  if (zipModel.getEndCentralDirRecord() == null) {
    throw new ZipException("end of central directory is null, cannot set comment");
  }
  
  ArchiveMaintainer archiveMaintainer = new ArchiveMaintainer();
  archiveMaintainer.setComment(zipModel, comment);
}

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

/**
 * Sets comment for the Zip file
 * @param comment
 * @throws ZipException
 */
public void setComment(String comment) throws ZipException {
  if (comment == null) {
    throw new ZipException("input comment is null, cannot update zip file");
  }
  
  if (!Zip4jUtil.checkFileExists(file)) {
    throw new ZipException("zip file does not exist, cannot set comment for zip file");
  }
  
  readZipInfo();
  
  if (this.zipModel == null) {
    throw new ZipException("zipModel is null, cannot update zip file");
  }
  
  if (zipModel.getEndCentralDirRecord() == null) {
    throw new ZipException("end of central directory is null, cannot set comment");
  }
  
  ArchiveMaintainer archiveMaintainer = new ArchiveMaintainer();
  archiveMaintainer.setComment(zipModel, comment);
}

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

readZipInfo();

相关文章