Here you can find the source of deflate(byte[] data, byte[] dictionary)
Parameter | Description |
---|---|
data | the input data |
dictionary | the dictionary, or null if none |
public static byte[] deflate(byte[] data, byte[] dictionary)
//package com.java2s; /**/*from w w w.j a va 2 s . co m*/ * Copyright (c) 2010 Martin Geisse * * This file is distributed under the terms of the MIT license. */ import java.io.ByteArrayOutputStream; import java.util.zip.Deflater; public class Main { /** * DEFLATEs the specified input data. * * @param data the input data * @param dictionary the dictionary, or null if none * @return the compressed data */ public static byte[] deflate(byte[] data, byte[] dictionary) { Deflater deflater = new Deflater(8, true); if (dictionary != null) { deflater.setDictionary(dictionary); } deflater.setInput(data); deflater.finish(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[256]; while (!deflater.finished()) { int n = deflater.deflate(buffer); byteArrayOutputStream.write(buffer, 0, n); } byte[] result = byteArrayOutputStream.toByteArray(); return result; } }