gpt4 book ai didi

com.mucommander.commons.file.archive.zip.ZipArchiveFile类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 11:11:30 31 4
gpt4 key购买 nike

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

ZipArchiveFile介绍

[英]ZipArchiveFile provides read and write access (under certain conditions) to archives in the Zip format.

Two different packages that implement the actual Zip compression format are used: the homemade com.mucommander.commons.file.impl.zip.provider package and Java's java.util.zip. com.mucommander.commons.file.impl.zip.provider provides additional functionality and improved performance over java.util.zip but requires the underlying file to supply a RandomAccessInputStream for read access and a RandomAccessOutputStream for write access. If the underlying file can't provide at least a RandomAccessInputStream, the lesser java.util.zip package is used.
[中]ZipArchiveFile(在特定条件下)提供对Zip格式档案的读写访问。
使用了两个实现实际Zip压缩格式的不同包:自制的com.mucommander.commons.file.impl.zip.provider包和Java的java.util.zipcom.mucommander.commons.file.impl.zip.provider提供了比java.util.zip更多的功能和改进的性能,但要求基础文件提供RandomAccessInputStream的读访问权限和RandomAccessOutputStream的写访问权限。如果基础文件不能提供至少一个RandomAccessInputStream,则使用较小的java.util.zip包。

代码示例

代码示例来源:origin: mucommander/mucommander

@Override
public AbstractArchiveFile getFile(AbstractFile file) throws IOException {
  return new ZipArchiveFile(file);
}

代码示例来源:origin: mucommander/mucommander

/**
 * Adds the given {@link ArchiveEntry} to the entries tree and declares the Zip file and entries tree up-to-date.
 *
 * @param entry the entry to add to the entries tree
 * @throws IOException if an error occurred while adding the entry to the tree
 * @throws UnsupportedFileOperationException if this operation is not supported by the underlying filesystem,
 * or is not implemented.
 */
private void finishAddEntry(ArchiveEntry entry) throws IOException, UnsupportedFileOperationException {
  // Declare the zip file and entries tree up-to-date
  declareZipFileUpToDate();
  declareEntriesTreeUpToDate();
  // Add the new entry to the entries tree
  addToEntriesTree(entry);
}

代码示例来源:origin: mucommander/mucommander

@Override
public synchronized void optimizeArchive() throws IOException, UnsupportedFileOperationException {
  checkZipFile();
  // Defragment the zip file
  zipFile.defragment();
  // Declare the zip file and entries tree up-to-date
  declareZipFileUpToDate();
  declareEntriesTreeUpToDate();
}

代码示例来源:origin: mucommander/mucommander

/**
   * Creates an empty, valid Zip file. The resulting file is 22 bytes long.
   */
  @Override
  public void mkfile() throws IOException, UnsupportedFileOperationException {
    if(exists())
      throw new IOException();

    copyStream(new ByteArrayInputStream(EMPTY_ZIP_BYTES), false, EMPTY_ZIP_BYTES.length);
  }
}

代码示例来源:origin: mucommander/mucommander

@Override
public synchronized void deleteEntry(ArchiveEntry entry) throws IOException, UnsupportedFileOperationException {
  ZipEntry zipEntry = (com.mucommander.commons.file.archive.zip.provider.ZipEntry)entry.getEntryObject();
  // Most of the time, the ZipEntry will not be null. However, it can be null in some rare cases, when directory
  // entries have been created in the entries tree but don't exist in the Zip file.
  // That is the case when a file entry exists in the Zip file but has no directory entry for the parent.
  if(zipEntry!=null) {
    // Entry exists physically in the zip file
    checkZipFile();
    // Delete the entry from the zip file (physically)
    zipFile.deleteEntry(zipEntry);
    // Remove the ZipEntry object from the AchiveEntry
    entry.setEntryObject(null);
    // Declare the zip file and entries tree up-to-date
    declareZipFileUpToDate();
    declareEntriesTreeUpToDate();
  }
  // Else entry doesn't physically exist in the zip file, only in the entries tree
  // Remove the entry from the entries tree
  removeFromEntriesTree(entry);
}

代码示例来源:origin: mucommander/mucommander

@Override
public synchronized OutputStream addEntry(final ArchiveEntry entry) throws IOException, UnsupportedFileOperationException {
  checkZipFile();
  final ZipEntry zipEntry = createZipEntry(entry);
  if(zipEntry.isDirectory()) {
    // Add the new directory entry to the zip file (physically)
    zipFile.addEntry(zipEntry);
    // Set the ZipEntry object into the ArchiveEntry
    entry.setEntryObject(zipEntry);
    // Declare the zip file and entries tree up-to-date and add the new entry to the entries tree
    finishAddEntry(entry);
    return null;
  }
  else {
    // Set the ZipEntry object into the ArchiveEntry
    entry.setEntryObject(zipEntry);
    return new FilteredOutputStream(zipFile.addEntry(zipEntry)) {
      @Override
      public void close() throws IOException {
        super.close();
        // Declare the zip file and entries tree up-to-date and add the new entry to the entries tree
          finishAddEntry(entry);
        }
    };
  }
}

代码示例来源:origin: mucommander/mucommander

/**
 * Overridden to delete the archive file after each test.
 */
@Override
@AfterMethod
public void tearDown() throws IOException {
  // Delete all archive entries
  super.tearDown();
  // Assert that the file is still an archive
  assert tempZipFile.isArchive();
  tempZipFile.delete();
  // Assert that the file is no longer an archive
  assert !tempZipFile.isArchive();
}

代码示例来源:origin: mucommander/mucommander

public ArchiveEntry nextEntry() throws IOException {
  ZipEntry entry;
  if(!iterator.hasNext() || (entry = iterator.next())==null)
    return null;
  return createArchiveEntry(entry);
}

代码示例来源:origin: mucommander/mucommander

@Override
public synchronized ArchiveEntryIterator getEntryIterator() throws IOException, UnsupportedFileOperationException {
  // If the underlying AbstractFile has random read access, use our own ZipFile implementation to read entries
  if (file.isFileOperationSupported(FileOperation.RANDOM_READ_FILE)) {
    checkZipFile();
    final Iterator<ZipEntry> iterator = zipFile.getEntries();
    return new ArchiveEntryIterator() {
      public ArchiveEntry nextEntry() throws IOException {
        ZipEntry entry;
        if(!iterator.hasNext() || (entry = iterator.next())==null)
          return null;
        return createArchiveEntry(entry);
      }
      public void close() throws IOException {
      }
    };
  }
  // If the underlying AbstractFile doesn't have random read access, use java.util.zip.ZipInputStream to
  // read the entries. This is much slower than the former method as the file cannot be sought through and needs
  // to be traversed.
  else {
    return new JavaUtilZipEntryIterator(new ZipInputStream(file.getInputStream()));
  }
}

代码示例来源:origin: mucommander/mucommander

/**
 * Checks if the underlying Zip file is up-to-date, i.e. exists and has not changed without this archive file
 * being aware of it. If one of those 2 conditions are not met, (re)load the ZipFile instance (parse the entries)
 * and declare the Zip file as up-to-date.
 *
 * @throws IOException if an error occurred while reloading
 */
private void checkZipFile() throws IOException, UnsupportedFileOperationException {
  long currentDate = file.getDate();
  if(zipFile==null || currentDate!=lastZipFileDate) {
    zipFile = new ZipFile(file);
    declareZipFileUpToDate();
  }
}

代码示例来源:origin: mucommander/mucommander

/**
 * Advances the {@link ZipInputStream} to the next entry and returns the corresponding {@link ArchiveEntry}.
 *
 * @return the next ArchiveEntry
 * @throws java.io.IOException if an I/O error occurred
 */
private ArchiveEntry getNextEntry() throws IOException {
  try {
    ZipEntry entry = zin.getNextEntry();
    if(entry==null)
      return null;
    return ZipArchiveFile.createArchiveEntry(new com.mucommander.commons.file.archive.zip.provider.ZipEntry(entry));
  }
  catch(Exception e) {
    // java.util.zip.ZipInputStream can throw an IllegalArgumentException when the filename/comment encoding
    // is not UTF-8 as expected (ZipInputStream always expects UTF-8). The more general Exception is caught
    // (just to be safe) and an IOException thrown.
    throw new IOException();
  }
  catch(Error e) {
    // ZipInputStream#getNextEntry() will throw a java.lang.InternalError ("invalid compression method")
    // if the compression method is different from DEFLATED or STORED (happens with IMPLODED for example).
    throw new IOException();
  }
}

代码示例来源:origin: mucommander/mucommander

checkZipFile();

代码示例来源:origin: mucommander/mucommander

@Override
public void updateEntry(ArchiveEntry entry) throws IOException, UnsupportedFileOperationException {
  ZipEntry zipEntry = (com.mucommander.commons.file.archive.zip.provider.ZipEntry)entry.getEntryObject();
  // Most of the time, the ZipEntry will not be null. However, it can be null in some rare cases, when directory
  // entries have been created in the entries tree but don't exist in the Zip file.
  // That is the case when a file entry exists in the Zip file but has no directory entry for the parent.
  if(zipEntry!=null) {
    // Entry exists physically in the zip file
    checkZipFile();
    zipEntry.setTime(entry.getDate());
    zipEntry.setUnixMode(entry.getPermissions().getIntValue());
    
    // Physically update the entry's attributes in the Zip file
    zipFile.updateEntry(zipEntry);
    // Declare the zip file and entries tree up-to-date
    declareZipFileUpToDate();
    declareEntriesTreeUpToDate();
  }
}

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