List of usage examples for java.util.zip GZIPInputStream read
public int read(byte b[]) throws IOException
b.length
bytes of data from this input stream into an array of bytes. From source file:Main.java
protected static ByteArrayOutputStream inflate(final ByteArrayOutputStream pOutCompressed) throws IOException { final ByteArrayOutputStream uncompressed = new ByteArrayOutputStream(ONE_MB); final GZIPInputStream zin = new GZIPInputStream(new ByteArrayInputStream(pOutCompressed.toByteArray())); int read;// www . java 2 s .c om final byte[] buf = new byte[ONE_MB]; while ((read = zin.read(buf)) != -1) { uncompressed.write(buf, 0, read); } return uncompressed; }
From source file:Main.java
public static void unzip(InputStream is, OutputStream os) { GZIPInputStream gzip = null; try {// w w w . j ava 2 s. co m gzip = new GZIPInputStream(is); byte[] buf = new byte[1024]; int len; while ((len = gzip.read(buf)) != -1) { os.write(buf, 0, len); } } catch (IOException e) { e.printStackTrace(); } finally { closeIO(gzip, os); } }
From source file:Main.java
public static void unzip(InputStream is, OutputStream os) { GZIPInputStream gzip = null; try {//from w w w . ja v a2 s . c o m gzip = new GZIPInputStream(is); byte[] buf = new byte[1024]; int len; while ((len = gzip.read(buf)) != -1) { os.write(buf, 0, len); } } catch (IOException e) { e.printStackTrace(); } finally { closeIO(gzip); closeIO(os); } }
From source file:Main.java
public static byte[] decompressInGzip(byte[] compressData, int offset, int length) throws Exception { ByteArrayInputStream bis = new ByteArrayInputStream(compressData, offset, length); GZIPInputStream gzipInStream = new GZIPInputStream(bis); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int count;//from www . j a v a 2 s . co m byte[] buf = new byte[1024]; while ((count = gzipInStream.read(buf)) > 0) { bos.write(buf, 0, count); } gzipInStream.close(); byte[] originalData = bos.toByteArray(); bos.close(); return originalData; }
From source file:Main.java
private static void decompressGzipFile(String gzipFile) { try {//from w ww.j av a2 s.c o m File newFile = new File(Environment.getExternalStorageDirectory() + File.separator + "FlockLoad"); FileInputStream fis = new FileInputStream(gzipFile); GZIPInputStream gis = new GZIPInputStream(fis); FileOutputStream fos = new FileOutputStream(newFile); byte[] buffer = new byte[1024]; int len; while ((len = gis.read(buffer)) != -1) { fos.write(buffer, 0, len); } //close resources fos.close(); gis.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static final byte[] unCompress(byte[] buf) throws IOException { GZIPInputStream gzi = new GZIPInputStream(new ByteArrayInputStream(buf)); ByteArrayOutputStream bos = new ByteArrayOutputStream(buf.length); int count;//w w w . j a va 2 s . c om byte[] tmp = new byte[2048]; while ((count = gzi.read(tmp)) != -1) { bos.write(tmp, 0, count); } // store uncompressed back to buffer gzi.close(); return bos.toByteArray(); }
From source file:Main.java
/** * decompress a gzip byte array, using a default buffer length of 1024 * <p>/* w w w .jav a2s . co m*/ * @param compressedByteArray gzip-compressed byte array * @param bufferlength size of the buffer in bytes * @return decompressed byte array * @throws IOException thrown if there was a failure to construct the GzipInputStream */ public static byte[] decompressGzipByteArray(byte[] compressedByteArray, int bufferlength) throws IOException { ByteArrayOutputStream uncompressedStream = new ByteArrayOutputStream(); GZIPInputStream compressedStream = new GZIPInputStream(new ByteArrayInputStream(compressedByteArray)); byte[] buffer = new byte[bufferlength]; int index = -1; while ((index = compressedStream.read(buffer)) != -1) { uncompressedStream.write(buffer, 0, index); } return uncompressedStream.toByteArray(); }
From source file:GZIPUtils.java
/** * Returns an gunzipped copy of the input array. * @throws IOException if the input cannot be properly decompressed *///from w ww .j a va 2s . c o m public static final byte[] unzip(byte[] in) throws IOException { // decompress using GZIPInputStream ByteArrayOutputStream outStream = new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length); GZIPInputStream inStream = new GZIPInputStream(new ByteArrayInputStream(in)); byte[] buf = new byte[BUF_SIZE]; while (true) { int size = inStream.read(buf); if (size <= 0) break; outStream.write(buf, 0, size); } outStream.close(); return outStream.toByteArray(); }
From source file:com.spstudio.common.image.ImageUtils.java
public static byte[] uncompress(byte[] bytes) { if (bytes == null || bytes.length == 0) { return null; }/*from w w w. ja va 2s.co m*/ ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(bytes); try { GZIPInputStream ungzip = new GZIPInputStream(in); byte[] buffer = new byte[256]; int n; while ((n = ungzip.read(buffer)) >= 0) { out.write(buffer, 0, n); } } catch (IOException e) { logger.error("gzip uncompress error.", e); } return out.toByteArray(); }
From source file:com.ery.ertc.estorm.util.GZIPUtils.java
/** * Returns an gunzipped copy of the input array. * /*from w w w . j a va 2 s. co m*/ * @throws IOException * if the input cannot be properly decompressed */ public static final byte[] unzip(byte[] in) throws IOException { // decompress using GZIPInputStream ByteArrayOutputStream outStream = new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length); GZIPInputStream inStream = new GZIPInputStream(new ByteArrayInputStream(in)); byte[] buf = new byte[BUF_SIZE]; while (true) { int size = inStream.read(buf); if (size <= 0) break; outStream.write(buf, 0, size); } outStream.close(); return outStream.toByteArray(); }