开发者

How to modify file fist 256kb without creating a new file and copying?

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开发者_如何学Python.

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;


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜