List of usage examples for java.util.zip GZIPInputStream close
public void close() throws IOException
From source file:org.cloudata.core.common.io.CWritableUtils.java
public static byte[] readCompressedByteArray(DataInput in) throws IOException { int length = in.readInt(); if (length == -1) return null; byte[] buffer = new byte[length]; in.readFully(buffer); // could/should use readFully(buffer,0,length)? GZIPInputStream gzi = new GZIPInputStream(new ByteArrayInputStream(buffer, 0, buffer.length)); byte[] outbuf = new byte[length]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); int len;/*from w w w .ja va 2 s. c o m*/ while ((len = gzi.read(outbuf, 0, outbuf.length)) != -1) { bos.write(outbuf, 0, len); } byte[] decompressed = bos.toByteArray(); bos.close(); gzi.close(); return decompressed; }
From source file:org.killbill.billing.beatrix.integration.osgi.util.SetupBundleWithAssertion.java
private static File unGzip(final File inputFile, final File outputDir) throws IOException { GZIPInputStream in = null; FileOutputStream out = null;/*from w w w . java 2 s . co m*/ try { final File outputFile = new File(outputDir, inputFile.getName().substring(0, inputFile.getName().length() - 3)); in = new GZIPInputStream(new FileInputStream(inputFile)); out = new FileOutputStream(outputFile); for (int c = in.read(); c != -1; c = in.read()) { out.write(c); } return outputFile; } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } }
From source file:org.apache.helix.tools.ZkGrep.java
/** * Gunzip a file// www .java 2s .c o m * @param zipFile * @return */ static File gunzip(File zipFile) { File outputFile = new File(stripGzSuffix(zipFile.getAbsolutePath())); byte[] buffer = new byte[1024]; try { GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(zipFile)); FileOutputStream out = new FileOutputStream(outputFile); int len; while ((len = gzis.read(buffer)) > 0) { out.write(buffer, 0, len); } gzis.close(); out.close(); return outputFile; } catch (IOException e) { LOG.error("fail to gunzip file: " + zipFile, e); } return null; }
From source file:com.beligum.core.utils.AssetPacker.java
private static String decodeGzip(byte[] content) throws IOException { String retVal = null;/* w ww . ja v a2 s .c om*/ ByteArrayInputStream in = null; GZIPInputStream gzip = null; try { in = new ByteArrayInputStream(content); gzip = new GZIPInputStream(in); BufferedReader reader = new BufferedReader(new InputStreamReader(gzip, "UTF-8")); StringBuilder sb = new StringBuilder(); String s; while ((s = reader.readLine()) != null) { sb.append(s); } gzip.close(); in.close(); retVal = sb.toString(); } catch (Exception e) { if (gzip != null) { gzip.close(); } if (in != null) { in.close(); } } return retVal; }
From source file:org.ofbiz.webapp.event.RestEventHandler.java
/** * ? /*from ww w .j av a2s. c o m*/ * * @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:org.mitre.opensextant.util.FileUtility.java
/** * * @param fname/*from w w w.j a v a2 s . c o m*/ * @return * @throws IOException */ public static String readGzipFile(String fname) throws IOException { if (fname == null) { return null; } FileInputStream instream = new FileInputStream(fname); GZIPInputStream gzin = new GZIPInputStream(new BufferedInputStream(instream), default_buffer); byte[] inputBytes = new byte[default_buffer]; StringBuilder buf = new StringBuilder(); int readcount = 0; while ((readcount = gzin.read(inputBytes, 0, default_buffer)) != -1) { buf.append(new String(inputBytes, 0, readcount, default_encoding)); } instream.close(); gzin.close(); return buf.toString(); }
From source file:com.fhc25.percepcion.osiris.mapviewer.common.restutils.RestClient.java
private static String convertGZIPStreamToString(GZIPInputStream is) { StringBuilder sb = new StringBuilder(); String line = null;//from www.j av a 2 s .c o m int lineCount = 0; try { Reader decoder = new InputStreamReader(is, "UTF-8"); BufferedReader reader = new BufferedReader(decoder); while ((line = reader.readLine()) != null) { sb.append(line + "\n"); lineCount++; } if (lineCount == 1) { sb.deleteCharAt(sb.length() - 1); } is.close(); decoder.close(); reader.close(); } catch (IOException e) { } return sb.toString(); }
From source file:com.googlecode.jgenhtml.JGenHtmlUtils.java
/** * Unzips a file./*w ww .j av a 2s .c o m*/ * @param gzippedFile A gzipped file. * @return The gunzipped version of the file. * @throws IOException If you screw up. */ public static File gunzip(File gzippedFile) throws IOException { OutputStream out = null; GZIPInputStream gzipInputStream = null; File gunzippedFile = new File(System.getProperty("java.io.tmpdir") + File.separatorChar + gzippedFile.getName().replace(".gz", "")); try { InputStream in = new FileInputStream(gzippedFile); gzipInputStream = new GZIPInputStream(in); out = new FileOutputStream(gunzippedFile); byte[] buf = new byte[1024]; int len; while ((len = gzipInputStream.read(buf)) > 0) { out.write(buf, 0, len); } } finally { if (gzipInputStream != null) { gzipInputStream.close(); } if (out != null) { out.close(); } } return gunzippedFile; }
From source file:edu.stanford.epad.common.util.EPADFileUtils.java
/** * Ungzip an input file into an output file. * <p>//from w ww.ja va 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. */ 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:edu.ku.brc.specify.web.HttpLargeFileTransfer.java
/** * @param infileName/* ww w. ja v a 2s.co m*/ * @param outFileName * @param changeListener * @return */ public static boolean uncompressFile(final String infileName, final String outFileName) { File file = new File(infileName); if (file.exists()) { long fileSize = file.length(); if (fileSize > 0) { try { GZIPInputStream fis = new GZIPInputStream(new FileInputStream(infileName)); BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(outFileName)); byte[] bytes = new byte[BUFFER_SIZE * 10]; while (true) { int len = fis.read(bytes); if (len > 0) { fos.write(bytes, 0, len); } else { break; } } fis.close(); fos.close(); return true; } catch (IOException ex) { ex.printStackTrace(); } } else { // file doesn't exist } } else { // file doesn't exist } return false; }