如何将文件附加到 Java 中的 .tar 存档? [英] How do I append files to a .tar archive in Java?

查看:29
本文介绍了如何将文件附加到 Java 中的 .tar 存档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 Java 创建一个 tar 存档.我有不断被创建的文件,我想要一个工作线程从队列中引用这些文件并将它们复制到存档中.

I would like to create a tar archive in Java. I have files which are constantly being created and I'd like a worker thread to take a reference to those files from a queue and copy them into the archive.

我尝试使用 Apache 压缩库的 TarArchiveOutputStream 来执行此操作,但我不希望在程序的整个持续时间内保持存档打开(因为除非我完成存档,否则它可能会损坏 - 所以我宁愿附加分批添加到它),而且我还没有找到一种用他们的库附加到现有 tar 存档的好方法(他们确实有ChangeSetPerformer"类,但它基本上只是创建一个新的 tar 并且需要复制旧的完全,这对我不利,性能方面).

I tried using Apache Compression library's TarArchiveOutputStream to do this, but I do not wish to keep the archive open for the entire duration of the program (since unless i finalize the archive, it can become corrupted - so i'd rather append to it in batches), and I haven't found a good way to append to an existing tar archive with their library (They do have the "ChangeSetPerformer" class, but it basically just creates a new tar and needs to copy the old one entirely, which isn't good for me, performance wise).

我还需要库对存档的大小没有下限(即 4g 左右是不够的),我宁愿避免实际压缩存档.

I also need the library to not have a low limit for the size of the archive (i.e. 4g or so is not enough), and i'd rather avoid having to actually compress the archive.

任何建议将不胜感激!谢谢.

Any suggestions would be greatly appreciated! thank you.

推荐答案

你在 tar 的限制下运行:http://en.wikipedia.org/wiki/Tar_(file_format)#Random_access

You run here in a limitation of tar: http://en.wikipedia.org/wiki/Tar_(file_format)#Random_access

因为在不复制整个存档的情况下很难添加或删除单个文件.

because of that it is hard to add or remove single files without copying the whole archive.

这篇关于如何将文件附加到 Java 中的 .tar 存档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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