List of usage examples for java.util.zip GZIPInputStream close
public void close() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { int sChunk = 8192; String zipname = "a.txt.gz"; String source = "a.txt"; FileInputStream in = new FileInputStream(zipname); GZIPInputStream zipin = new GZIPInputStream(in); byte[] buffer = new byte[sChunk]; FileOutputStream out = new FileOutputStream(source); int length;/*from ww w .ja v a 2 s . co m*/ while ((length = zipin.read(buffer, 0, sChunk)) != -1) out.write(buffer, 0, length); out.close(); zipin.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String source = "s.gzip"; GZIPInputStream in = new GZIPInputStream(new FileInputStream(source)); String target = "outfile"; OutputStream out = new FileOutputStream(target); byte[] buf = new byte[1024]; int len;/*from w w w. ja v a 2 s.c om*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String inFilename = "infile.gzip"; GZIPInputStream in = new GZIPInputStream(new FileInputStream(inFilename)); String outFilename = "outfile"; OutputStream out = new FileOutputStream(outFilename); byte[] buf = new byte[1024]; int len;/* w w w .j a va2 s . c o m*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String zipname = "data.txt.gz"; String source = "data.txt.gz"; GZIPInputStream zipin; FileInputStream in = new FileInputStream(zipname); zipin = new GZIPInputStream(in); byte[] buffer = new byte[sChunk]; // decompress the file FileOutputStream out = new FileOutputStream(source); int length;//w w w . ja v a2 s . c o m while ((length = zipin.read(buffer, 0, sChunk)) != -1) out.write(buffer, 0, length); out.close(); zipin.close(); }
From source file:Main.java
static public byte[] gunzip(byte src[], byte default_value[]) { try {// w w w .ja v a 2s. c o m if (src == null) return default_value; ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(src)); IOUtils.copy(in, out); in.close(); out.close(); return out.toByteArray(); } catch (Exception e) { return default_value; } }
From source file:com.giacomodrago.immediatecrypt.messagecipher.Compression.java
public static byte[] decompress(byte[] plaintext) { try {//from w ww. j av a 2 s.c o m ByteArrayOutputStream writer = new ByteArrayOutputStream(); ByteArrayInputStream reader = new ByteArrayInputStream(plaintext); GZIPInputStream gzipStream = new GZIPInputStream(reader); IOUtils.copy(gzipStream, writer); gzipStream.close(); writer.flush(); writer.close(); return writer.toByteArray(); } catch (IOException ex) { return null; // Invalid source data } }
From source file:Main.java
public static byte[] decompressGZIP(byte bytes[]) throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(bytes); GZIPInputStream gzipis = new GZIPInputStream(is); ByteArrayOutputStream os = new ByteArrayOutputStream(); int i;/*from w w w .j a v a2 s. co m*/ while ((i = gzipis.read()) != -1) { os.write(i); } gzipis.close(); os.close(); return os.toByteArray(); }
From source file:org.projectforge.common.GZIPHelper.java
/** * @param base64ByteArray/*from w w w . j ava 2 s . c o m*/ * @return */ public static String uncompress(final String base64ByteArray) { if (base64ByteArray == null || base64ByteArray.length() == 0) { return base64ByteArray; } try { final byte[] byteArray = (byte[]) Base64Helper.decodeObject(base64ByteArray); final ByteArrayInputStream in = new ByteArrayInputStream(byteArray); final GZIPInputStream gzip = new GZIPInputStream(in); final ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(gzip, out); gzip.close(); return out.toString(); } catch (final IOException ex) { log.error("Error while uncompressing string: " + ex.getMessage(), ex); return null; } catch (final ClassNotFoundException ex) { log.error("Error while uncompressing string: " + ex.getMessage(), ex); return null; } }
From source file:ByteUtils.java
public static byte[] unpackRaw(byte[] b) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayInputStream bais = new ByteArrayInputStream(b); GZIPInputStream zis = new GZIPInputStream(bais); byte[] tmpBuffer = new byte[256]; int n;//ww w . jav a 2 s .c o m while ((n = zis.read(tmpBuffer)) >= 0) baos.write(tmpBuffer, 0, n); zis.close(); return baos.toByteArray(); }
From source file:Main.java
public static byte[] unzip(byte[] output) { if (output == null || output.length == 0) { return output; }//from w w w . ja va2 s . com try { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(output); GZIPInputStream gunzip = new GZIPInputStream(in); byte[] buffer = new byte[BUFFER_SIZE]; int ret; while ((ret = gunzip.read(buffer)) >= 0) { out.write(buffer, 0, ret); } gunzip.close(); return out.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }