gpt4 book ai didi

org.apache.commons.compress.archivers.zip.ZipArchiveEntry类的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 10:38:40 24 4
gpt4 key购买 nike

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

ZipArchiveEntry介绍

[英]Extension that adds better handling of extra fields and provides access to the internal and external file attributes.

The extra data is expected to follow the recommendation of APPNOTE.TXT:

  • the extra byte array consists of a sequence of extra fields
  • each extra fields starts by a two byte header id followed by a two byte sequence holding the length of the remainder of data.

Any extra data that cannot be parsed by the rules above will be consumed as "unparseable" extra data and treated differently by the methods of this class. Versions prior to Apache Commons Compress 1.1 would have thrown an exception if any attempt was made to read or write extra data not conforming to the recommendation.
[中]扩展名,可以更好地处理额外字段,并提供对内部和外部文件属性的访问。
预计额外数据将遵循APPNOTE.TXT的建议:
*额外字节数组由一系列额外字段组成
*每个额外字段的开头是一个两字节的头id,后面是一个两字节的序列,其中包含剩余数据的长度。
上述规则无法解析的任何额外数据都将作为“不可解析”的额外数据使用,并由此类的方法进行不同的处理。如果试图读取或写入不符合建议的额外数据,Apache Commons Compress 1.1之前的版本会引发异常。

代码示例

代码示例来源:origin: plutext/docx4j

log.info( "Couldn't find " + f.getPath() );
  zf = new ZipFile(f);
} catch (IOException ioe) {
  ioe.printStackTrace() ;
Enumeration entries = zf.getEntries();
while (entries.hasMoreElements()) {
  ZipArchiveEntry entry = (ZipArchiveEntry) entries.nextElement();
  policePartSize(f, entry.getSize(), entry.getName());
  InputStream in = null;
  try {
    byte[] bytes =  getBytesFromInputStream( zf.getInputStream(entry) );
    policePartSize(f, bytes.length, entry.getName()); // in case earlier check ineffective
    partByteArrays.put(entry.getName(), new ByteArray(bytes) );
  } catch (PartTooLargeException e) {
    throw e;

代码示例来源:origin: org.apache.poi/poi-ooxml

protected void injectData(ZipEntrySource zipEntrySource, OutputStream out) throws IOException {
  ZipArchiveOutputStream zos = new ZipArchiveOutputStream(out);
  try {
    Enumeration<? extends ZipArchiveEntry> en = zipEntrySource.getEntries();
    while (en.hasMoreElements()) {
      ZipArchiveEntry ze = en.nextElement();
      ZipArchiveEntry zeOut = new ZipArchiveEntry(ze.getName());
      zeOut.setSize(ze.getSize());
      zeOut.setTime(ze.getTime());
      zos.putArchiveEntry(zeOut);
      try (final InputStream is = zipEntrySource.getInputStream(ze)) {
        if (is instanceof ZipArchiveThresholdInputStream) {
        XSSFSheet xSheet = getSheetFromZipEntryName(ze.getName());
        zos.closeArchiveEntry();

代码示例来源:origin: jeremylong/DependencyCheck

ZipFile zip = null;
try {
  zip = new ZipFile(dependency.getActualFilePath());
  if (zip.getEntry("META-INF/MANIFEST.MF") != null
      || zip.getEntry("META-INF/maven") != null) {
    final Enumeration<ZipArchiveEntry> entries = zip.getEntries();
    while (entries.hasMoreElements()) {
      final ZipArchiveEntry entry = entries.nextElement();
      if (!entry.isDirectory()) {
        final String name = entry.getName().toLowerCase();
        if (name.endsWith(".class")) {
          isJar = true;

代码示例来源:origin: org.apache.commons/commons-compress

private boolean isTooLageForZip32(final ZipArchiveEntry zipArchiveEntry){
  return zipArchiveEntry.getSize() >= ZIP64_MAGIC || zipArchiveEntry.getCompressedSize() >= ZIP64_MAGIC;
}

代码示例来源:origin: org.apache.commons/commons-compress

/**
 * Sets Unix permissions in a way that is understood by Info-Zip's
 * unzip command.
 * @param mode an <code>int</code> value
 */
public void setUnixMode(final int mode) {
  // CheckStyle:MagicNumberCheck OFF - no point
  setExternalAttributes((mode << SHORT_SHIFT)
             // MS-DOS read-only attribute
             | ((mode & 0200) == 0 ? 1 : 0)
             // MS-DOS directory flag
             | (isDirectory() ? 0x10 : 0));
  // CheckStyle:MagicNumberCheck ON
  platform = PLATFORM_UNIX;
}

代码示例来源:origin: org.apache.commons/commons-compress

/**
 * If the mode is AsNeeded and the entry is a compressed entry of
 * unknown size that gets written to a non-seekable stream then
 * change the default to Never.
 *
 * @since 1.3
 */
private Zip64Mode getEffectiveZip64Mode(final ZipArchiveEntry ze) {
  if (zip64Mode != Zip64Mode.AsNeeded
    || channel != null
    || ze.getMethod() != DEFLATED
    || ze.getSize() != ArchiveEntry.SIZE_UNKNOWN) {
    return zip64Mode;
  }
  return Zip64Mode.Never;
}

代码示例来源:origin: apache/tika

private static MediaType detectKmz(ZipFile zip) {
  boolean kmlFound = false;
  Enumeration<ZipArchiveEntry> entries = zip.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry entry = entries.nextElement();
    String name = entry.getName();
    if (!entry.isDirectory()
        && name.indexOf('/') == -1 && name.indexOf('\\') == -1) {
      if (name.endsWith(".kml") && !kmlFound) {
        kmlFound = true;
      } else {
        return null;
      }
    }
  }
  if (kmlFound) {
    return MediaType.application("vnd.google-earth.kmz");
  } else {
    return null;
  }
}

代码示例来源:origin: org.apache.poi/poi-examples

/**
 *
 * @param zipfile the template file
 * @param tmpfile the XML file with the sheet data
 * @param entry the name of the sheet entry to substitute, e.g. xl/worksheets/sheet1.xml
 * @param out the stream to write the result to
 */
private static void substitute(File zipfile, File tmpfile, String entry, OutputStream out) throws IOException {
  try (ZipFile zip = ZipHelper.openZipFile(zipfile)) {
    try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(out)) {
      Enumeration<? extends ZipArchiveEntry> en = zip.getEntries();
      while (en.hasMoreElements()) {
        ZipArchiveEntry ze = en.nextElement();
        if (!ze.getName().equals(entry)) {
          zos.putArchiveEntry(new ZipArchiveEntry(ze.getName()));
          try (InputStream is = zip.getInputStream(ze)) {
            copyStream(is, zos);
          }
          zos.closeArchiveEntry();
        }
      }
      zos.putArchiveEntry(new ZipArchiveEntry(entry));
      try (InputStream is = new FileInputStream(tmpfile)) {
        copyStream(is, zos);
      }
      zos.closeArchiveEntry();
    }
  }
}

代码示例来源:origin: apache/tika

private static MediaType tryStreamingDetection(TikaInputStream stream) {
  Set<String> entryNames = new HashSet<>();
  try (InputStream is = new FileInputStream(stream.getFile())) {
    ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(is);
    ZipArchiveEntry zae = zipArchiveInputStream.getNextZipEntry();
    while (zae != null) {
      if (zae.isDirectory()) {
        zae = zipArchiveInputStream.getNextZipEntry();
        continue;
      entryNames.add(zae.getName());
      if (zae.getName().equals("[Content_Types].xml")) {
        MediaType mt = parseContentTypes(zipArchiveInputStream);
        if (mt != null) {

代码示例来源:origin: biezhi/java-library-examples

private static void addToArchiveCompression(ZipArchiveOutputStream out, File file, String dir) throws IOException {
  String name = dir + File.separator + file.getName();
  if (file.isFile()) {
    ZipArchiveEntry entry = new ZipArchiveEntry(name);
    out.putArchiveEntry(entry);
    entry.setSize(file.length());
    IOUtils.copy(new FileInputStream(file), out);
    out.closeArchiveEntry();
  } else if (file.isDirectory()) {
    File[] children = file.listFiles();
    if (children != null) {
      for (File child : children) {
        addToArchiveCompression(out, child, name);
      }
    }
  } else {
    System.out.println(file.getName() + " is not supported");
  }
}

代码示例来源:origin: org.codehaus.plexus/plexus-archiver

try
  zipFile = new org.apache.commons.compress.archivers.zip.ZipFile( getSourceFile(), encoding, true );
  final Enumeration e = zipFile.getEntriesInPhysicalOrder();
  while ( e.hasMoreElements() )
    final ZipArchiveEntry ze = (ZipArchiveEntry) e.nextElement();
    final ZipEntryFileInfo fileInfo = new ZipEntryFileInfo( zipFile, ze );
    if ( !isSelected( ze.getName(), fileInfo ) )
    if ( ze.getName().startsWith( path ) )
      in = zipFile.getInputStream( ze );
                  ze.getName(), new Date( ze.getTime() ), ze.isDirectory(),
                  ze.getUnixMode() != 0 ? ze.getUnixMode() : null,
                  resolveSymlink( zipFile, ze ), getFileMappers() );

代码示例来源:origin: apache/incubator-gobblin

@edu.umd.cs.findbugs.annotations.SuppressWarnings(
  value = "OBL_UNSATISFIED_OBLIGATION",
  justification = "Lombok construct of @Cleanup is handing this, but not detected by FindBugs")
private static void addFilesToZip(File zipFile, List<File> filesToAdd) throws IOException {
 try {
  @Cleanup
  OutputStream archiveStream = new FileOutputStream(zipFile);
  @Cleanup
  ArchiveOutputStream archive =
    new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
  for (File fileToAdd : filesToAdd) {
   ZipArchiveEntry entry = new ZipArchiveEntry(fileToAdd.getName());
   archive.putArchiveEntry(entry);
   @Cleanup
   BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileToAdd));
   IOUtils.copy(input, archive);
   archive.closeArchiveEntry();
  }
  archive.finish();
 } catch (ArchiveException e) {
  throw new IOException("Issue with creating archive", e);
 }
}

代码示例来源:origin: walmartlabs/concord

public static void unzip(Path in, Path targetDir, boolean skipExisting, CopyOption... options) throws IOException {
  try (ZipFile zip = new ZipFile(in.toFile())) {
    Enumeration<ZipArchiveEntry> entries = zip.getEntries();
    while (entries.hasMoreElements()) {
      ZipArchiveEntry e = entries.nextElement();
      Path p = targetDir.resolve(e.getName());
      if (skipExisting && Files.exists(p)) {
        continue;
      }
      if (e.isDirectory()) {
        Files.createDirectories(p);
      } else {
        Path parent = p.getParent();
        if (!Files.exists(parent)) {
          Files.createDirectories(parent);
        }
        try (InputStream src = zip.getInputStream(e)) {
          Files.copy(src, p, options);
        }
        int unixMode = e.getUnixMode();
        if (unixMode <= 0) {
          unixMode = Posix.DEFAULT_UNIX_MODE;
        }
        Files.setPosixFilePermissions(p, Posix.posix(unixMode));
      }
    }
  }
}

代码示例来源:origin: apache/tika

private static InputStream getZipStream(String zipPath, ZipPackage zipPackage) throws IOException, TikaException {
    String targPath = (zipPath.length() > 1 && zipPath.startsWith("/") ? zipPath.substring(1) : zipPath);
    ZipEntrySource zipEntrySource = zipPackage.getZipArchive();
    Enumeration<? extends ZipArchiveEntry> zipEntryEnumeration = zipEntrySource.getEntries();
    ZipArchiveEntry zipEntry = null;
    while (zipEntryEnumeration.hasMoreElements()) {
      ZipArchiveEntry ze = zipEntryEnumeration.nextElement();
      if (ze.getName().equals(targPath)) {
        zipEntry = ze;
        break;
      }
    }
    if (zipEntry == null) {
      throw new TikaException("Couldn't find required zip entry: " + zipPath);
    }
    return zipEntrySource.getInputStream(zipEntry);
  }
}

代码示例来源:origin: naver/ngrinder

ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
zos.setEncoding(charsetName);
FileInputStream fis = null;
    ze = new ZipArchiveEntry(name);
    zos.putArchiveEntry(ze);
    try {
      fis = new FileInputStream(f);
      while ((length = fis.read(buf, 0, buf.length)) >= 0) {
        zos.write(buf, 0, length);

代码示例来源:origin: apache/tika

private static void repairCopy(File brokenZip, File fixedZip) {
  try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(fixedZip)) {
    try (InputStream is = new FileInputStream(brokenZip)) {
      ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(is);
      ZipArchiveEntry zae = zipArchiveInputStream.getNextZipEntry();
      while (zae != null) {
        try {
          if (!zae.isDirectory() && zipArchiveInputStream.canReadEntryData(zae)) {
            outputStream.putArchiveEntry(zae);
            outputStream.flush();
            outputStream.closeArchiveEntry();
            if (!successfullyCopied) {

代码示例来源:origin: de.flapdoodle.embedmongo/de.flapdoodle.embedmongo

progressListener.start(progressLabel);
FileInputStream fin = new FileInputStream(source);
BufferedInputStream in = new BufferedInputStream(fin);
ZipArchiveInputStream zipIn = new ZipArchiveInputStream(in);
try {
  ZipArchiveEntry entry;
  while ((entry = zipIn.getNextZipEntry()) != null) {
    if (file.matcher(entry.getName()).matches()) {
      if (zipIn.canReadEntryData(entry)) {
        long size = entry.getSize();
        Files.write(zipIn, size, destination);
        destination.setExecutable(true);

代码示例来源:origin: USPTO/PatentPublicData

public ZipArchiveEntry nextEntry() {
  while (hasNext()) {
    currentEntry = entries.nextElement();
    File entryFile = new File(currentEntry.getName());
    if (filter.accept(entryFile)) {
      return currentEntry;
    }
  }
  throw new NoSuchElementException();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

Cipher ciEnc = CryptoFunctions.getCipher(skeySpec, CipherAlgorithm.aes128, ChainingMode.cbc, ivBytes, Cipher.ENCRYPT_MODE, PADDING);
ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
FileOutputStream fos = new FileOutputStream(tmpFile);
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos);
while ((ze = zis.getNextZipEntry()) != null) {
  ZipArchiveEntry zeNew = new ZipArchiveEntry(ze.getName());
  zeNew.setComment(ze.getComment());
  zeNew.setExtra(ze.getExtra());
  zeNew.setTime(ze.getTime());
  zos.putArchiveEntry(zeNew);
  FilterOutputStream fos2 = new FilterOutputStream(zos) {
  cos.close();
  fos2.close();
  zos.closeArchiveEntry();
zos.close();
fos.close();
zis.close();

代码示例来源:origin: plutext/docx4j

public void saveContentTypes(ContentTypeManager ctm) throws Docx4JException {
  try {
    zos.putArchiveEntry(new ZipArchiveEntry("[Content_Types].xml"));
    ctm.marshal(zos);
    zos.closeArchiveEntry();
  } catch (Exception e) {
    throw new Docx4JException("Error marshalling Content_Types ", e);
  }
}

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