I have an byte[] of about 9mil bytes, and I would like to store it to a file. I wanted to use Deflater to compress the array, but it seems like the process only made the array (slightly) bigger. Is my data incompressible? If so, why? Are there any other ways to make the array smaller?
my code:
ByteArrayOutputStream baos = null;
Deflater dfl = new Deflater();
dfl.setLevel(Deflater.BEST_COMPRESSION);
dfl.setInput(data);
dfl.finish();
baos = new ByteArrayOutputStream();
byte[] tmp = new byte[1024];
try{
while(!dfl.finished()){
int size = dfl.deflate(tmp);
baos.write(tmp, 0, size);
}
} catch (Exception ex){
} finally {
try{
if(baos != null) baos.close();
} catch(Exception ex){}
}
Log.d(TAG, data.length + " " + baos.toByteArray().length);
return baos.toByteArray();
EDIT:
I converted an image from disk into a byte array. I then encrypted it. Now I would like to store that (encrypted) byte[] in a file, so that later I can read it and decrypt it, and therefore recreate the image. The original image is ~0.6MB, and the encrypted file turns out to be ~9MB.. I would like to avoid such a big difference, for the user's sake..