org.apache.commons.compress.archivers.zip.ZipFile.getInputStream()方法的使用及代码示例

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

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

ZipFile.getInputStream介绍

[英]Returns an InputStream for reading the contents of the given entry.
[中]返回用于读取给定条目内容的InputStream。

代码示例

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

@Override
  public InputStream getInputStream() throws IOException {
    return in.getInputStream(current);
  }
}

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

@Override
public InputStream getInputStream(ZipArchiveEntry entry) throws IOException {
  InputStream is = zipFile.getInputStream(entry);
  return new CipherInputStream(is, ci);
}

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

@Override
public InputStream getInputStream(ZipArchiveEntry entry) throws IOException {
 if (zipArchive == null)
   throw new IllegalStateException("Zip File is closed");
 
 return zipArchive.getInputStream(entry);
}

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

@Override
  public void writeEntryDataTo(ArchiveEntry entry, OutputStream out) throws IOException {
    try (InputStream in = archive.getInputStream((ZipArchiveEntry) entry)) {
      IOUtils.copy(in, out);
    }
  }
}, targetDirectory);

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

/**
 * Returns an input stream for reading the contents of the specified
 * zip file entry.
 *
 * <p> Closing this ZIP file will, in turn, close all input
 * streams that have been returned by invocations of this method.
 *
 * @param entry the zip file entry
 * @return the input stream for reading the contents of the specified
 * zip file entry.
 * @throws IOException if an I/O error has occurred
 * @throws IllegalStateException if the zip file has been closed
 */
@Override
@SuppressWarnings("resource")
public ZipArchiveThresholdInputStream getInputStream(ZipArchiveEntry entry) throws IOException {
  ZipArchiveThresholdInputStream zatis = new ZipArchiveThresholdInputStream(super.getInputStream(entry));
  zatis.setEntry(entry);
  return zatis;
}

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

/**
 * <p>
 * Convenience method to return the entry's content as a String if isUnixSymlink()
 * returns true for it, otherwise returns null.
 * </p>
 *
 * <p>This method assumes the symbolic link's file name uses the
 * same encoding that as been specified for this ZipFile.</p>
 *
 * @param entry ZipArchiveEntry object that represents the symbolic link
 * @return entry's content as a String
 * @throws IOException problem with content's input stream
 * @since 1.5
 */
public String getUnixSymlink(final ZipArchiveEntry entry) throws IOException {
  if (entry != null && entry.isUnixSymlink()) {
    try (InputStream in = getInputStream(entry)) {
      return zipEncoding.decode(IOUtils.toByteArray(in));
    }
  }
  return null;
}

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

InputStream in = null;
try {
  byte[] bytes =  getBytesFromInputStream( zf.getInputStream(entry) );

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

@Nonnull
@Override
public InputStream getContents()
  throws IOException
{
  return zipFile.getInputStream( zipEntry );
}

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

public static IWORKDocumentType detectType(ZipArchiveEntry entry, ZipFile zip) {
 try {
   if (entry == null) {
     return null;
   }
   try (InputStream stream = zip.getInputStream(entry)) {
     return detectType(stream);
   }
 } catch (IOException e) {
   return null;
 }
}

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

@Nonnull
@Override
public InputStream getContents()
  throws IOException
{
  final InputStream inputStream = zipFile.getInputStream( entry );
  return new ClosingInputStream( streamTransformer.transform( this, inputStream ), inputStream );
}

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

/**
 * OpenDocument files, along with EPub files and ASiC ones, have a 
 *  mimetype entry in the root of their Zip file. This entry contains
 *  the mimetype of the overall file, stored as a single string.  
 */
private static MediaType detectOpenDocument(ZipFile zip) {
  try {
    ZipArchiveEntry mimetype = zip.getEntry("mimetype");
    if (mimetype != null) {
      try (InputStream stream = zip.getInputStream(mimetype)) {
        return MediaType.parse(IOUtils.toString(stream, UTF_8));
      }
    } else {
      return null;
    }
  } catch (IOException e) {
    return null;
  }
}

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

protected Map<String, String> readZipArchive(InputStream inputStream) throws IOException {
  Map<String, String> data = new HashMap<String, String>();
  Path tempFile = writeTemporaryArchiveFile(inputStream, "zip");
  ZipFile zip = new ZipFile(tempFile.toFile());
  Enumeration<ZipArchiveEntry> entries = zip.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry entry = entries.nextElement();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    IOUtils.copy(zip.getInputStream(entry), bos);
    data.put(entry.getName(), DigestUtils.md5Hex(bos.toByteArray()));
  }
  zip.close();
  Files.delete(tempFile);
  return data;
}

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

protected String readArchiveText(InputStream inputStream) throws IOException {
  Path tempFile = writeTemporaryArchiveFile(inputStream, "zip");
  ZipFile zip = new ZipFile(tempFile.toFile());
  zip.getEntry(UnpackerResource.TEXT_FILENAME);
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  IOUtils.copy(zip.getInputStream(zip.getEntry(UnpackerResource.TEXT_FILENAME)), bos);
  zip.close();
  Files.delete(tempFile);
  return bos.toString(UTF_8.name());
}

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

in = zipFile.getInputStream( ze );

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

if ( isSelected( fileInfo.getName(), fileInfo ) )
  in = zf.getInputStream( ze );

代码示例来源:origin: org.apache.tika/tika-parsers

public static IWORKDocumentType detectType(ZipArchiveEntry entry, ZipFile zip) {
 try {
   if (entry == null) {
     return null;
   }
   try (InputStream stream = zip.getInputStream(entry)) {
     return detectType(stream);
   }
 } catch (IOException e) {
   return null;
 }
}

代码示例来源:origin: de.unkrig.commons/commons-file

@Override @Nullable public ArchiveEntry
getNextEntry() throws IOException {
  if (!this.entries.hasMoreElements()) {
    this.stream = null;
    return null;
  }
  ZipArchiveEntry zae = this.entries.nextElement();
  this.stream = this.zipFile.getInputStream(zae);
  return zae;
}

代码示例来源:origin: org.apache.wookie/wookie-parser

/**
 * Retrieves the Manifest entry as a String
 * @param zipFile the zip file from which to extract the manifest
 * @return a String representing the manifest contents
 * @throws IOException
 */
public static String extractManifest(ZipFile zipFile) throws IOException{
  ZipArchiveEntry entry = zipFile.getEntry(IW3CXMLConfiguration.MANIFEST_FILE);
  return IOUtils.toString(zipFile.getInputStream(entry), "UTF-8");
}

代码示例来源:origin: edu.jhu.hlt/acute

@Override
public byte[] next() {
 try {
  ZipArchiveEntry entry = this.iter.nextElement();
  try (InputStream in = this.zf.getInputStream(entry);) {
   byte[] bytes = IOUtils.toByteArray(in);
   return bytes;
  }
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility

@Test
  public void testHandleFileEntry() throws IOException, RepositoryException {
    //GIVEN
    when(zipArchiveEntry.getName()).thenReturn("folderName/fileName.jpg");
    inputStream = new ByteArrayInputStream(new byte[10]);
    when(zipFile.getInputStream(zipArchiveEntry)).thenReturn(inputStream);

    //WHEN
    importZipCommand.handleFileEntry(zipFile, zipArchiveEntry); //then should not thrown PathNotFoundException

    //THEN
    assertThat(mockContext.getJCRSession("assets").getRootNode(), hasNode("folderName", NodeTypes.Folder.NAME));
  }
}

相关文章