Modify the bytes read by an InputStream while reading, not later?

Streams are designed to wrap. That's why you frequently see lines like: InputStream is=new BufferedInputStream(new FileInputStream(file)) So, create a DecryptingInputStream that does your decryption, wrapping around another InputStream All that being said, this won't be tough to crack, as your decryption keys and algorithm will be easily determinable by anyone who decompiles your app.

Streams are designed to wrap. That's why you frequently see lines like: InputStream is=new BufferedInputStream(new FileInputStream(file)); So, create a DecryptingInputStream that does your decryption, wrapping around another InputStream. All that being said, this won't be tough to crack, as your decryption keys and algorithm will be easily determinable by anyone who decompiles your app.

Well, this kind of decryption is just to scramble the files on the sdcard. Just to stop the normal user from copying the files from the phone. Wrapping will not reduce the memory usage, right?

The way I have to modify the bytes is the same. Or am I wrong? – WarrenFaith Sep 27 at 18:33 @WarrenFaith: "Wrapping will not reduce the memory usage, right?" -- it will as much as overriding the methods would.

– CommonsWare Sep 27 at 18:44.

FileInputStream is not your problem. The read() function will not read in more than DEFAULT_BUFFER_SIZE on each call. It is your use of ByteArrayOutputStream which is using up a lot of memory as your are writing to it.

If you want to reduce the amount of memory required then I suggest you write directly to a FileOutputStream instead of a ByteArrayOutputStream. So encrypt and write to disk as you read DEFAULT_BUFFER_SIZE from the InputStream.

I don't save it on the disk. It is already encrypted saved on the disk. I need an on-the-fly decryption while reading from the disk.As my current implementation decrypt outside the InputStream, I need a byte array to perform the decryption.

That is the reason I need the array. I will try to wrap it like CommonsWare suggested. – WarrenFaith Sep 27 at 20:39.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions