List of usage examples for java.util.zip Deflater deflate
public int deflate(byte[] output, int off, int len)
From source file:Main.java
public static void main(String[] args) throws IOException { Deflater def = new Deflater(); byte[] input = new byte[1024]; byte[] output = new byte[1024]; FileInputStream fin = new FileInputStream("a.dat"); FileOutputStream fout = new FileOutputStream("b.dat"); int numRead = fin.read(input); def.setInput(input, 0, numRead);/*from w ww. java 2 s . com*/ while (!def.needsInput()) { int numCompressedBytes = def.deflate(output, 0, output.length); if (numCompressedBytes > 0) { fout.write(output, 0, numCompressedBytes); } } def.finish(); fin.close(); fout.flush(); fout.close(); def.reset(); }