/** * Zip the data. * * @param srcDate * @param compressedData * @param buffSize * @param level */ public static void zipTheDate(byte[] srcDate, byte[] compressedData, int buffSize, int level) { Deflater compressor = new Deflater(); compressor.setLevel(Deflater.BEST_COMPRESSION); compressor.setInput(srcDate); compressor.finish(); ByteArrayOutputStream bos = new ByteArrayOutputStream(srcDate.length); if (buffSize < 1) buffSize = 512; byte[] buf = new byte[buffSize]; while (!compressor.finished()) { int count = compressor.deflate(buf); bos.write(buf, 0, count); } try { bos.close(); } catch (IOException e) { } compressedData = bos.toByteArray(); System.out.println("srcDate length=" + srcDate.length); System.out.println("compressedData length=" + compressedData.length); } /** * UnZipTheDate. * * @param compressedData * @param decompressedData * @param buffSize * @param level */ public static void unZipTheDate(byte[] compressedData, byte[] decompressedData, int buffSize, int level) { Inflater decompressor = new Inflater(); decompressor.setInput(compressedData); ByteArrayOutputStream bos1 = new ByteArrayOutputStream( compressedData.length); if (buffSize < 1) buffSize = 512; byte[] buf1 = new byte[buffSize]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf1); bos1.write(buf1, 0, count); } catch (DataFormatException e) { } } try { bos1.close(); } catch (IOException e) { } decompressedData = bos1.toByteArray(); System.out.println("compressedData length=" + compressedData.length); System.out .println("decompressedData length=" + decompressedData.length); }