package com.nmmc.dms.utils.compression;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
public class CompressingOutputStream extends DeflaterOutputStream {
public CompressingOutputStream(final OutputStream out) {
super(out, new Deflater(Deflater.BEST_COMPRESSION, true),4*1024);
}
private static final byte[] EMPTYBYTEARRAY = new byte[0];
/**
* Insure all remaining data will be output.
*/
public void flush() throws IOException {
/**
* Now this is tricky: We force the Deflater to flush its data by
* switching compression level. As yet, a perplexingly simple workaround
* for
*
* http://developer.java.sun.com/developer/bugParade/bugs/42557 43.html
*/
def.setInput(EMPTYBYTEARRAY, 0, 0);
def.setLevel(Deflater.NO_COMPRESSION);
deflate();
def.setLevel(Deflater.DEFAULT_COMPRESSION);
deflate();
out.flush();
}
} // class
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
public class CompressingOutputStream extends DeflaterOutputStream {
public CompressingOutputStream(final OutputStream out) {
super(out, new Deflater(Deflater.BEST_COMPRESSION, true),4*1024);
}
private static final byte[] EMPTYBYTEARRAY = new byte[0];
/**
* Insure all remaining data will be output.
*/
public void flush() throws IOException {
/**
* Now this is tricky: We force the Deflater to flush its data by
* switching compression level. As yet, a perplexingly simple workaround
* for
*
* http://developer.java.sun.com/developer/bugParade/bugs/42557 43.html
*/
def.setInput(EMPTYBYTEARRAY, 0, 0);
def.setLevel(Deflater.NO_COMPRESSION);
deflate();
def.setLevel(Deflater.DEFAULT_COMPRESSION);
deflate();
out.flush();
}
} // class