用Java编写未知(大)大小的Tar文件 [英] Write Tar File of Unknown (Large) Size in Java

查看:26
本文介绍了用Java编写未知(大)大小的Tar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 Java 将大量未知大小的流写入 tar 文件.我知道 Apache 有 commons 压缩库,其中 处理 tar 文件,但它们要求我提前知道大小.考虑 Apache 自己的 example:

I'd like to write a large stream of unknown size to a tar file in Java. I know that Apache has the commons compress library which handles tar files, but they require me to know the size in advance. Consider Apache's own example:

TarArchiveEntry entry = new TarArchiveEntry(name);
entry.setSize(size);
tarOutput.putArchiveEntry(entry);
tarOutput.write(contentOfEntry);
tarOutput.closeArchiveEntry();

写完之后我会知道条目的大小,但之前不会.有没有一种方法可以写内容,当我完成大小然后写入标题?

I will know the size of the entry after I write it, but not before. Isn't there a way that I can write the content and when I finish the size is then written to the header?

推荐答案

我最终选择了 jtar 并修改它,这样您就不必在写入后指定大小.似乎没有本地执行此操作的软件包...我设置了一个 请求此更改的问题.不幸的是,它需要大量丑陋的代码并创建我自己的 RandomAccessFileInputStream(),这不适合上传补丁.

I ended up taking jtar and modifying it so you don't have to specify the size until after you write. It seems there is no package that does this natively... I set up an issue that requests this change. Unfortunately, it required a lot of ugly code and creating my own RandomAccessFileInputStream(), which is unsuitable for uploading a patch.

这篇关于用Java编写未知(大)大小的Tar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆