List of usage examples for java.util.zip GZIPInputStream close
public void close() throws IOException
From source file:Main.java
public static File ungzip(File gzip, File toDir) throws IOException { toDir.mkdirs();/*from w ww . j av a 2 s . com*/ File out = new File(toDir, gzip.getName()); GZIPInputStream gin = null; FileOutputStream fout = null; try { FileInputStream fin = new FileInputStream(gzip); gin = new GZIPInputStream(fin); fout = new FileOutputStream(out); copy(gin, fout); gin.close(); fout.close(); } finally { closeQuietly(gin); closeQuietly(fout); } return out; }
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.co m 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
private static void decompressGzipFile(String gzipFile) { try {/* w w w . ja va 2 s . c om*/ 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:com.cip.crane.agent.utils.FileExtractUtils.java
/** * Ungzip an input file into an output file. * <p>// w ww . j ava2 s .co m * The output file is created in the output folder, having the same name * as the input file, minus the '.gz' extension. * * @param inputFile the input .gz file * @param outputDir the output directory file. * @throws IOException * @throws FileNotFoundException * * @return The {@File} with the ungzipped content. */ public static File unGzip(final File inputFile, final File outputDir) throws FileNotFoundException, IOException { LOG.debug(String.format("Ungzipping %s to dir %s.", inputFile.getAbsolutePath(), outputDir.getAbsolutePath())); final File outputFile = new File(outputDir, inputFile.getName().substring(0, inputFile.getName().length() - 3)); final GZIPInputStream in = new GZIPInputStream(new FileInputStream(inputFile)); final FileOutputStream out = new FileOutputStream(outputFile); IOUtils.copy(in, out); in.close(); out.close(); return outputFile; }
From source file:Main.java
public static byte[] unGzip(byte[] data) { byte[] b = null; try {//from w w w. jav a 2 s . c om 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:Main.java
/** * Uncompress gzipped files//from ww w.ja v a 2 s . c o 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:uk.ac.bbsrc.tgac.miso.integration.util.IntegrationUtils.java
public static byte[] decompress(byte[] contentBytes) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPInputStream bis = new GZIPInputStream(new Base64InputStream(new ByteArrayInputStream(contentBytes))); byte[] buffer = new byte[1024 * 4]; int n = 0;/* w ww .j a va 2s . com*/ while (-1 != (n = bis.read(buffer))) { out.write(buffer, 0, n); } bis.close(); return out.toByteArray(); }
From source file:bencoding.securely.Converters.java
public static Object deserializeObjectFromString(String objectString) throws Exception { ByteArrayInputStream arrayInputStream = new ByteArrayInputStream( Base64.decode(objectString, Base64.DEFAULT)); GZIPInputStream gzipInputStream = new GZIPInputStream(arrayInputStream); ObjectInputStream objectInputStream = new ObjectInputStream(gzipInputStream); Object object = objectInputStream.readObject(); objectInputStream.close();/* w w w . j a v a 2 s . c om*/ gzipInputStream.close(); arrayInputStream.close(); return object; }
From source file:Main.java
public static byte[] decompress(byte[] bytes) throws IOException { GZIPInputStream gzip = null; ByteArrayOutputStream baos = null; try {/*from ww w . j a v a 2s . c o m*/ baos = new ByteArrayOutputStream(); gzip = new GZIPInputStream(new ByteArrayInputStream(bytes)); int len = 0; byte data[] = new byte[BUFFER_SIZE]; while ((len = gzip.read(data, 0, BUFFER_SIZE)) != -1) { baos.write(data, 0, len); } gzip.close(); baos.flush(); return baos.toByteArray(); } finally { if (gzip != null) { gzip.close(); } if (baos != null) { baos.close(); } } }
From source file:com.cloudera.knittingboar.utils.Utils.java
/** * Ungzip an input file into an output file. * <p>//from w ww .j a v a 2 s . c o m * The output file is created in the output folder, having the same name as * the input file, minus the '.gz' extension. * * @param inputFile * the input .gz file * @param outputDir * the output directory file. * @throws IOException * @throws FileNotFoundException * * @return The {@File} with the ungzipped content. */ private static File unGzip(final File inputFile, final File outputDir) throws FileNotFoundException, IOException { System.out.println(String.format("Ungzipping %s to dir %s.", inputFile.getAbsolutePath(), outputDir.getAbsolutePath())); final File outputFile = new File(outputDir, inputFile.getName().substring(0, inputFile.getName().length() - 3)); final GZIPInputStream in = new GZIPInputStream(new FileInputStream(inputFile)); final FileOutputStream out = new FileOutputStream(outputFile); for (int c = in.read(); c != -1; c = in.read()) { out.write(c); } in.close(); out.close(); return outputFile; }