首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >压缩Apache的压缩输入

压缩Apache的压缩输入
EN

Stack Overflow用户
提问于 2018-03-06 01:41:31
回答 2查看 1.7K关注 0票数 0

我需要在Apache中读取和处理中的zip归档中的特定文件。

在文档中,我发现

Flink目前支持透明解压缩输入文件,如果这些文件标记为适当的文件扩展名。

https://ci.apache.org/projects/flink/flink-docs-release-1.4/dev/batch/#read-compressed-files

是否有可能在Apache中动态解压缩时处理它?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-08 04:56:47

同时,我想分享我实现的解决方案。

因此,在创建自己的InputFormat之后,我在open()方法中使用了以下代码:

代码语言:javascript
复制
@Override
public void open(final FileInputSplit ignored) throws IOException {
    ...
    final XMLInputFactory xmlif = XMLInputFactory.newInstance();
    final XMLStreamReader xmlr = xmlif.createXMLStreamReader(filePath.toString(),
              InputFormatUtil.readFileWithinZipArchive(filePath, nestedXmlFileName));
    while (xmlr.hasNext()) {
    ...
}

其中,readFileWithinZipArchive(...)的实现是:

代码语言:javascript
复制
public static InputStream readFileWithinZipArchive(final Path zipPath, final String filename) throws IOException {
    // using org.apache.flink.core.fs.Path for getting the InputStream from the (remote) zip archive
    final InputStream zipInputStream = zipPath.getFileSystem().open(zipPath);
    // generating a temporary local copy of the zip file
    final File tmpFile = stream2file(zipInputStream);
    // then using java.util.zip.ZipFile for extracting the InputStream for the specific file within the zip archive
    final ZipFile zipFile = new ZipFile(tmpFile);
    return zipFile.getInputStream(zipFile.getEntry(filename));
}
票数 0
EN

Stack Overflow用户

发布于 2018-03-06 07:01:28

FileInputFormat将将读取的压缩文件委托给GZIPInputStream,后者将在解压缩时返回部分解压缩数据。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49122170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档