Code example for GZIPOutputStream

Methods: writeclose

0
 
public class SimpleGzip { 
 
	public static byte[] compress(byte[] bytes) throws IOException {
	    ByteArrayOutputStream os = new ByteArrayOutputStream(bytes.length);
	    GZIPOutputStream gos = new GZIPOutputStream(os);
	    gos.write(bytes);
	    gos.close();
	    byte[] compressed = os.toByteArray();
	    os.close();
	    return compressed;
	} 
 
	public static String decompress(byte[] compressed) throws IOException {
	    final int BUFFER_SIZE = 32;
	    ByteArrayInputStream is = new ByteArrayInputStream(compressed);
	    GZIPInputStream gis = new GZIPInputStream(is, BUFFER_SIZE);
	    StringBuilder string = new StringBuilder();
	    byte[] data = new byte[BUFFER_SIZE];
	    int bytesRead;
Stop searching for code, let great code find you!  Add Codota to your java IDE