Here is a small testcase that uses java.util.zip.Deflater //**************************************************** import java.util.Random; import java.util.zip.Deflater; public class TestDeflater { public static void main(String[] args) { int max_byte_length = 200000000; byte[] inputData = new byte[max_byte_length]; Random random = new Random(); random.nextBytes(inputData); System.out.println("dataSize:" + inputData.length); Deflater compressor = new Deflater(Deflater.BEST_COMPRESSION); compressor.setInput(inputData); compressor.finish(); byte[] tempBuf = new byte[inputData.length]; int compressedLength = compressor.deflate(tempBuf); System.out.println("compressedSize:" + compressedLength); System.out.println("finishedFlag:"+compressor.finished()); compressor.end(); } } //**************************************************** This is how it works normally: $ java TestDeflater dataSize:200000000 compressedSize:200000000 finishedFlag:false However, if either virtual memory (swap space) is scarce or the Java process is about to hit the (4GB on Solaris32 / 2GB on Windows/Linux) process size limit, then we will see this: $ ulimit -d 100000 //simulating low memory condition $ java TestDeflater dataSize:200000000 compressedSize:0 <<<<< finishedFlag:false The expected behaviour should be to throw an OOME instead.
|