gpt4 book ai didi

net.lingala.zip4j.model.ZipModel类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 10:06:20 27 4
gpt4 key购买 nike

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

ZipModel介绍

暂无

代码示例

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

int currSplitFileCounter = 0;
  if (outputStream instanceof SplitOutputStream) {
    zipModel.getEndCentralDirRecord().setOffsetOfStartOfCentralDir(
        ((SplitOutputStream)outputStream).getFilePointer());
    currSplitFileCounter = ((SplitOutputStream)outputStream).getCurrSplitFileCounter();
  if (zipModel.isZip64Format()) {
    if (zipModel.getZip64EndCentralDirRecord() == null) {
      zipModel.setZip64EndCentralDirRecord(new Zip64EndCentralDirRecord());
    if (zipModel.getZip64EndCentralDirLocator() == null) {
      zipModel.setZip64EndCentralDirLocator(new Zip64EndCentralDirLocator());
    zipModel.getZip64EndCentralDirLocator().setNoOfDiskStartOfZip64EndOfCentralDirRec(currSplitFileCounter);
    zipModel.getZip64EndCentralDirLocator().setTotNumberOfDiscs(currSplitFileCounter + 1);
  zipModel.getEndCentralDirRecord().setNoOfThisDisk(currSplitFileCounter);
  zipModel.getEndCentralDirRecord().setNoOfThisDiskStartOfCentralDir(currSplitFileCounter);
} catch (IOException e) {
  throw new ZipException(e);

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

private long calculateTotalWorkForMergeOp(ZipModel zipModel) throws ZipException {
    long totSize = 0;
    if (zipModel.isSplitArchive()) {
      int totNoOfSplitFiles = zipModel.getEndCentralDirRecord().getNoOfThisDisk();
      String partFile = null;
      String curZipFile = zipModel.getZipFile();
      int partNumber = 0;
      for (int i = 0; i <= totNoOfSplitFiles; i++) {
        if (partNumber == zipModel.getEndCentralDirRecord().getNoOfThisDisk()) {
          partFile = zipModel.getZipFile();
        } else {
          if (partNumber >= 9) {
            partFile = curZipFile.substring(0, curZipFile.lastIndexOf(".")) + ".z" + (partNumber+ 1);
          } else{
            partFile = curZipFile.substring(0, curZipFile.lastIndexOf(".")) + ".z0" + (partNumber+ 1);
          }
        }
        
        totSize += Zip4jUtil.getFileLengh(new File(partFile)); 
      }
      
    }
    return totSize;
  }
}

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

/**
 * Creates a new instance of zip model
 * @throws ZipException
 */
private void createNewZipModel() {
  zipModel = new ZipModel();
  zipModel.setZipFile(file);
  zipModel.setFileNameCharset(fileNameCharset);
}

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

zipModel = new ZipModel();
zipModel.setFileNameCharset(fileNameCharset);
zipModel.setEndCentralDirRecord(readEndOfCentralDirectoryRecord());
zipModel.setZip64EndCentralDirLocator(readZip64EndCentralDirLocator());
if (zipModel.isZip64Format()) {
  zipModel.setZip64EndCentralDirRecord(readZip64EndCentralDirRec());
  if(zipModel.getZip64EndCentralDirRecord() != null && 
      zipModel.getZip64EndCentralDirRecord().getNoOfThisDisk() > 0){
    zipModel.setSplitArchive(true);
  } else {
    zipModel.setSplitArchive(false);
zipModel.setCentralDirectory(readCentralDirectory());

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

if (zipModel.isSplitArchive()) {
  throw new ZipException("This is a split archive. Zip file format does not allow updating split/spanned files");
tmpZipFileName = zipModel.getZipFile() + currTime%1000;
File tmpFile = new File(tmpZipFileName);
  tmpZipFileName = zipModel.getZipFile() + currTime%1000;
  tmpFile = new File(tmpZipFileName);
zipFile = new File(zipModel.getZipFile());
long offsetStartCentralDir = zipModel.getEndCentralDirRecord().getOffsetOfStartOfCentralDir();
if (zipModel.isZip64Format()) {
  if (zipModel.getZip64EndCentralDirRecord() != null) {
    offsetStartCentralDir = zipModel.getZip64EndCentralDirRecord().getOffsetStartCenDirWRTStartDiskNo();
ArrayList fileHeaderList = zipModel.getCentralDirectory().getFileHeaders();
  if (zipModel.getCentralDirectory().getFileHeaders().size() > 1) {
zipModel.getEndCentralDirRecord().setOffsetOfStartOfCentralDir(((SplitOutputStream)outputStream).getFilePointer());
zipModel.getEndCentralDirRecord().setTotNoOfEntriesInCentralDir(
    zipModel.getEndCentralDirRecord().getTotNoOfEntriesInCentralDir() - 1);
zipModel.getEndCentralDirRecord().setTotNoOfEntriesInCentralDirOnThisDisk(
    zipModel.getEndCentralDirRecord().getTotNoOfEntriesInCentralDirOnThisDisk() - 1);
zipModel.getCentralDirectory().getFileHeaders().remove(indexOfFileHeader);
for (int i = indexOfFileHeader; i < zipModel.getCentralDirectory().getFileHeaders().size(); i++) {

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

if (zipModel.getCentralDirectory() != null && 
    zipModel.getCentralDirectory().getFileHeaders() != null &&
    zipModel.getCentralDirectory().getFileHeaders().size() > 0) {
  Raw.writeShortLittleEndian(shortByte, 0, 
      (short)((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(0)).getVersionMadeBy());
  copyByteArrayToArrayList(shortByte, headerBytesList);
      (short)((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(0)).getVersionNeededToExtract());
  copyByteArrayToArrayList(shortByte, headerBytesList);
} else {
Raw.writeIntLittleEndian(intByte, 0, zipModel.getEndCentralDirRecord().getNoOfThisDisk());
copyByteArrayToArrayList(intByte, headerBytesList);
Raw.writeIntLittleEndian(intByte, 0, zipModel.getEndCentralDirRecord().getNoOfThisDiskStartOfCentralDir());
copyByteArrayToArrayList(intByte, headerBytesList);
if (zipModel.getCentralDirectory() == null || 
    zipModel.getCentralDirectory().getFileHeaders() == null) {
  throw new ZipException("invalid central directory/file headers, " +
      "cannot write end of central directory record");
} else {
  numEntries = zipModel.getCentralDirectory().getFileHeaders().size();
  if (zipModel.isSplitArchive()) {
    countNumberOfFileHeaderEntriesOnDisk(zipModel.getCentralDirectory().getFileHeaders(), 
        zipModel.getEndCentralDirRecord().getNoOfThisDisk());
  } else {
    numEntriesOnThisDisk = numEntries;

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

zipModel.getEndCentralDirRecord().setComment(encodedComment);
zipModel.getEndCentralDirRecord().setCommentBytes(commentBytes);
zipModel.getEndCentralDirRecord().setCommentLength(commentLength);
  outputStream = new SplitOutputStream(zipModel.getZipFile());
  if (zipModel.isZip64Format()) {
    outputStream.seek(zipModel.getZip64EndCentralDirRecord().getOffsetStartCenDirWRTStartDiskNo());
  } else {
    outputStream.seek(zipModel.getEndCentralDirRecord().getOffsetOfStartOfCentralDir());

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

if (!zipModel.isSplitArchive()) {
  ZipException e = new ZipException("archive not a split zip file");
  progressMonitor.endProgressMonitorError(e);
try {
  int totNoOfSplitFiles = zipModel.getEndCentralDirRecord().getNoOfThisDisk();
      if (zipModel.getCentralDirectory() != null && 
          zipModel.getCentralDirectory().getFileHeaders() != null && 
          zipModel.getCentralDirectory().getFileHeaders().size() > 0) {
        byte[] buff = new byte[4];
        inputStream.seek(0);
      end = new Long(zipModel.getEndCentralDirRecord().getOffsetOfStartOfCentralDir());
  ZipModel newZipModel = (ZipModel)zipModel.clone();
  newZipModel.getEndCentralDirRecord().setOffsetOfStartOfCentralDir(totBytesWritten);

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

if (zipModel.getEndCentralDirRecord() == null) {
  zipModel.setEndCentralDirRecord(createEndOfCentralDirectoryRecord());
  boolean isZipFileAlreadExists = Zip4jUtil.checkFileExists(zipModel.getZipFile());
  SplitOutputStream splitOutputStream = new SplitOutputStream(new File(zipModel.getZipFile()), zipModel.getSplitLength());
  outputStream = new ZipOutputStream(splitOutputStream, this.zipModel);
    if (zipModel.getEndCentralDirRecord() == null) {
      throw new ZipException("invalid end of central directory record");
    splitOutputStream.seek(zipModel.getEndCentralDirRecord().getOffsetOfStartOfCentralDir());

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

if (zipModel.getEndCentralDirRecord() == null) {
  throw new ZipException("EndCentralRecord was null, maybe a corrupt zip file");
  ArrayList fileHeaderList = new ArrayList();
  EndCentralDirRecord endCentralDirRecord = zipModel.getEndCentralDirRecord();
  long offSetStartCentralDir = endCentralDirRecord.getOffsetOfStartOfCentralDir();
  int centralDirEntryCount = endCentralDirRecord.getTotNoOfEntriesInCentralDir();
  if (zipModel.isZip64Format()) {
    offSetStartCentralDir = zipModel.getZip64EndCentralDirRecord().getOffsetStartCenDirWRTStartDiskNo();
    centralDirEntryCount = (int)zipModel.getZip64EndCentralDirRecord().getTotNoOfEntriesInCentralDir();
      if (Zip4jUtil.isStringNotNullAndNotEmpty(zipModel.getFileNameCharset())) {
        fileName = new String(fileNameBuf, zipModel.getFileNameCharset());
      } else {
        fileName = Zip4jUtil.decodeFileName(fileNameBuf, fileHeader.isFileNameUTF8Encoded());

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

checkParameters(parameters);
boolean isZipFileAlreadExists = Zip4jUtil.checkFileExists(zipModel.getZipFile());
SplitOutputStream splitOutputStream = new SplitOutputStream(new File(zipModel.getZipFile()), zipModel.getSplitLength());
outputStream = new ZipOutputStream(splitOutputStream, this.zipModel);
  if (zipModel.getEndCentralDirRecord() == null) {
    throw new ZipException("invalid end of central directory record");
  splitOutputStream.seek(zipModel.getEndCentralDirRecord().getOffsetOfStartOfCentralDir());

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

public RandomAccessFile startNextSplitFile() throws IOException, FileNotFoundException {
  String currZipFile = zipModel.getZipFile();
  String partFile = null;
  if (currSplitFileCounter == zipModel.getEndCentralDirRecord().getNoOfThisDisk()) {
    partFile = zipModel.getZipFile();
  } else {
    if (currSplitFileCounter >= 9) {
      partFile = currZipFile.substring(0, currZipFile.lastIndexOf(".")) + ".z" + (currSplitFileCounter + 1);
    } else {
      partFile = currZipFile.substring(0, currZipFile.lastIndexOf(".")) + ".z0" + (currSplitFileCounter + 1);
    }
  }
  currSplitFileCounter++;
  try {
    if(!Zip4jUtil.checkFileExists(partFile)) {
      throw new IOException("zip split file does not exist: " + partFile);
    }
  } catch (ZipException e) {
    throw new IOException(e.getMessage());
  }
  return new RandomAccessFile(partFile, InternalZipConstants.READ_MODE);
}

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

zipModel.setZip64Format(true);
  writingZip64Rec = true;
  localFileHeader.setWriteComprSizeInZip64ExtraRecord(true);
if (Zip4jUtil.isStringNotNullAndNotEmpty(zipModel.getFileNameCharset())) {
  byte[] fileNameBytes = localFileHeader.getFileName().getBytes(zipModel.getFileNameCharset());
  copyByteArrayToArrayList(fileNameBytes,    byteArrayList);
} else {

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

private RandomAccessFile createFileHandler(ZipModel zipModel, String mode) throws ZipException {
  if (zipModel == null || !Zip4jUtil.isStringNotNullAndNotEmpty(zipModel.getZipFile())) {
    throw new ZipException("input parameter is null in getFilePointer, cannot create file handler to remove file");
  }
  
  try {
    return new RandomAccessFile(new File(zipModel.getZipFile()), mode);
  } catch (FileNotFoundException e) {
    throw new ZipException(e);
  }
}

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

private RandomAccessFile createFileHandler(String mode) throws ZipException {
  if (this.zipModel == null || !Zip4jUtil.isStringNotNullAndNotEmpty(this.zipModel.getZipFile())) {
    throw new ZipException("input parameter is null in getFilePointer");
  }
  
  try {
    RandomAccessFile raf = null;
    if (zipModel.isSplitArchive()) {
      raf = checkSplitFile();
    } else {
      raf = new RandomAccessFile(new File(this.zipModel.getZipFile()), mode);
    }
    return raf;
  } catch (FileNotFoundException e) {
    throw new ZipException(e);
  } catch (Exception e) {
    throw new ZipException(e);
  }
}

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

private void updateSplitZip64EndCentralDirRec(ZipModel zipModel, ArrayList fileSizeList) throws ZipException {
  if (zipModel == null) {
    throw new ZipException("zip model is null, cannot update split Zip64 end of central directory record");
  }
  
  if (zipModel.getZip64EndCentralDirRecord() == null) {
    return;
  }
  
  zipModel.getZip64EndCentralDirRecord().setNoOfThisDisk(0);
  zipModel.getZip64EndCentralDirRecord().setNoOfThisDiskStartOfCentralDir(0);
  zipModel.getZip64EndCentralDirRecord().setTotNoOfEntriesInCentralDirOnThisDisk(
      zipModel.getEndCentralDirRecord().getTotNoOfEntriesInCentralDir());
  
  long offsetStartCenDirWRTStartDiskNo = 0;
  
  for (int i = 0; i < fileSizeList.size(); i++) {
    offsetStartCenDirWRTStartDiskNo += ((Long)fileSizeList.get(i)).longValue();
  }
  
  zipModel.getZip64EndCentralDirRecord().setOffsetStartCenDirWRTStartDiskNo(
      ((Zip64EndCentralDirRecord)zipModel.getZip64EndCentralDirRecord()).getOffsetStartCenDirWRTStartDiskNo() + 
      offsetStartCenDirWRTStartDiskNo);
}

代码示例来源: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: 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());
  FileHeader fileHeader = Zip4jUtil.getFileHeader(zipModel, relativeFileName);
  if (fileHeader != null) {
    totalWork += (Zip4jUtil.getFileLengh(new File(zipModel.getZipFile())) - fileHeader.getCompressedSize());

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com