mbaHeader=new Property("IDAT");
byte[] output = new byte[1024]; //buffer to read from Deflater
ByteBuilder deflated=new ByteBuilder(); //complete deflate-stream
Deflater compresser = new Deflater(Deflater.DEFAULT_COMPRESSION); //deflater-obj
compresser.setInput(imagedata);
compresser.finish(); //indicate: there is no more input
int compressedDataLength=0;
while( compresser.finished()==false ){ //reading loop
int tmpComprLength = compresser.deflate(output);
//if stop-button is clicked
if(Thread.currentThread().isInterrupted()){
return;
}
deflated.appendArray(
(tmpComprLength==output.length)
?output
:Arrays.copyOf(output, tmpComprLength));
//append new data to existing data
compressedDataLength+=tmpComprLength; //total read bytes so far
}
assert(compresser.getBytesWritten()==compressedDataLength);
mbaDeflatedStream=deflated.getArray();
}