如何在不创建新文件和复制的情况下修改文件拳头256kb?

发布于 2024-12-01 01:44:21 字数 379 浏览 3 评论 0原文

我正在从亚马逊 S3 服务器下载一些文件音频/视频/PDF。我正在做的是在下载开始时加密每个文件唯一的前 256kb。 最近我添加了简历功能。我想做的是等待文件下载完成。完成后我将加密文件的第一个 256kb。

我想加密文件的前 256kb,而不为此创建新文件。就像我创建一个新文件一样,在 256kb 之后我必须将其他字节复制到新文件中。这将需要一些时间,因为文件大小可能为 200MB 到 500MB。

最好的解决方案是什么? 我使用的是 JDK1.6 通过输入/输出流下载。

import java.io.InputStream;
import java.io.FileOutputStream;

I am downloading some file Audio/Video/PDF from amazon S3 server. What I am doing is at the start of download encrypt the only first 256kb for each file.
Recently I add resume functionality. What I want to do is to wait for complete downloading of file. One completed then I will encrypt the frist 256kb of file.

I want to encrypt first 256kb of file without creating a new file for that. As if I create a new then after 256kb I have to copy the other bytes to new file. This will take time as file size can be 200MB to 500MB.

What is the best solution for that?
I am using JDK1.6 Downloading is via input/output stream.

import java.io.InputStream;
import java.io.FileOutputStream;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

べ映画 2024-12-08 01:44:21

您可能想使用 RandomAccessFile。读取 250K,在内存中加密,在同一个文件中覆盖。

You might want to use RandomAccessFile. Read your 250K, encrypt on memory, overwrite in the same file.

墨落画卷 2024-12-08 01:44:21

其他选项是创建您自己的 CustomInputStream 类,该类扩展了 InputStream。当您从 customInputStream 读取数据时,保持读取的字节数,一旦读取字节达到 256,您就可以解密它们,然后在 onwords 上您只需调用 super.read() 方法即可。

Other option is to create your own CustomInputStream class which extends InputStream. When you are reading from your customInputStream keep the count of bytes read as soon as read bytes reaches 256 you can decrypt them then onwords you can just call super.read() method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文