List of usage examples for java.util.zip GZIPInputStream read
public int read(byte[] buf, int off, int len) 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 w ww. j a v a 2 s. c o m*/ while ((length = zipin.read(buffer, 0, sChunk)) != -1) out.write(buffer, 0, length); out.close(); zipin.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 . j a v a2 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
static byte[] decompress(byte[] compressed) throws IOException { int nRead;//from ww w . ja v a2 s.c o m byte[] data = new byte[2048]; ByteArrayInputStream bis = new ByteArrayInputStream(compressed); GZIPInputStream gzip = new GZIPInputStream(bis); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); while ((nRead = gzip.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } bis.close(); gzip.close(); return buffer.toByteArray(); }
From source file:Main.java
static byte[] decompress(byte[] compressed) throws IOException { int nRead;//from w ww . ja v a 2 s . c o m byte[] data = new byte[2048]; ByteArrayInputStream bis = new ByteArrayInputStream(compressed); GZIPInputStream gzip = new GZIPInputStream(bis); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); while ((nRead = gzip.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } gzip.close(); bis.close(); return buffer.toByteArray(); }
From source file:CompressTransfer.java
/** * ?/*from ww w . ja v a 2 s .c om*/ * * @param is * @param os * @throws Exception */ public static void decompress(InputStream is, OutputStream os) throws Exception { GZIPInputStream gis = new GZIPInputStream(is); int count; byte data[] = new byte[BUFFER]; while ((count = gis.read(data, 0, BUFFER)) != -1) { os.write(data, 0, count); } gis.close(); }
From source file:Main.java
public static byte[] unGzip(byte[] data) { byte[] b = null; try {// ww w . j a va 2s. c o m ByteArrayInputStream bis = new ByteArrayInputStream(data); GZIPInputStream gzip = new GZIPInputStream(bis); byte[] buf = new byte[1024]; int num = -1; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((num = gzip.read(buf, 0, buf.length)) != -1) { baos.write(buf, 0, num); } b = baos.toByteArray(); baos.flush(); baos.close(); gzip.close(); bis.close(); } catch (Exception ex) { ex.printStackTrace(); } return b; }
From source file:ZipDemo.java
public static final String uncompress(final byte[] compressed) throws IOException { String uncompressed = ""; try {// w w w . j a v a 2 s . co m ByteArrayInputStream bais = new ByteArrayInputStream(compressed); GZIPInputStream zis = new GZIPInputStream(bais); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int numBytesRead = 0; byte[] tempBytes = new byte[DEFAULT_BUFFER_SIZE]; while ((numBytesRead = zis.read(tempBytes, 0, tempBytes.length)) != -1) { baos.write(tempBytes, 0, numBytesRead); } uncompressed = new String(baos.toByteArray()); } catch (ZipException e) { e.printStackTrace(System.err); } return uncompressed; }
From source file:Main.java
/** * Uncompress gzipped files// w ww. j av a 2s. co m * @param gzippedFile The file to uncompress * @param destinationFile The resulting file * @throws java.io.IOException thrown if there is a problem finding or writing the files */ public static void gunzip(File gzippedFile, File destinationFile) throws IOException { int buffer = 2048; FileInputStream in = new FileInputStream(gzippedFile); GZIPInputStream zipin = new GZIPInputStream(in); byte[] data = new byte[buffer]; // decompress the file FileOutputStream out = new FileOutputStream(destinationFile); try { int length; while ((length = zipin.read(data, 0, buffer)) != -1) out.write(data, 0, length); } finally { out.close(); zipin.close(); in.close(); } }
From source file:pl.otros.logview.io.Utils.java
public static boolean checkIfIsGzipped(byte[] buffer, int lenght) throws IOException { boolean gziped = false; try {/*w w w. j a v a2s .c o m*/ ByteArrayInputStream bin = new ByteArrayInputStream(buffer, 0, lenght); GZIPInputStream gzipInputStream = new GZIPInputStream(bin); gzipInputStream.read(new byte[buffer.length], 0, bin.available()); gziped = true; } catch (IOException e) { gziped = false; } return gziped; }
From source file:pl.otros.logview.api.io.Utils.java
public static boolean checkIfIsGzipped(byte[] buffer, int lenght) throws IOException { boolean gziped; try {//www . ja va 2 s .c o m ByteArrayInputStream bin = new ByteArrayInputStream(buffer, 0, lenght); GZIPInputStream gzipInputStream = new GZIPInputStream(bin); gzipInputStream.read(new byte[buffer.length], 0, bin.available()); gziped = true; } catch (IOException e) { gziped = false; } return gziped; }