Java examples for File Path IO:GZIP
Decompress data bytes with gzip algorithm.
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPInputStream; public class Main { /**//from w ww. j av a 2s .com * Decompress data bytes with gzip algorithm. * * @param data * @return data decompressed. * @throws IOException */ public static byte[] ungzip(byte[] data) throws IOException { if (data == null) { return data; } ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(data); GZIPInputStream gis = null; try { gis = new GZIPInputStream(in); byte[] buffer = new byte[1024]; int n; while ((n = gis.read(buffer)) >= 0) { out.write(buffer, 0, n); } } finally { if (gis != null) { gis.close(); } } return out.toByteArray(); } }