List of usage examples for java.util.zip GZIPInputStream GZIPInputStream
public GZIPInputStream(InputStream in) throws IOException
From source file:deodex.tools.TarGzUtils.java
/** * Ungzip an input file into an output file. * <p>// ww w .j a v a2 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 { 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:com.citypark.api.parser.XMLParser.java
protected InputStream getInputStream() throws IOException { try {// w w w .java2s .c om HttpUriRequest request = new HttpGet(feedUrl.toString()); request.addHeader("Accept-Encoding", "gzip"); //request.addHeader("encoding", "utf-8"); final HttpResponse response = new DefaultHttpClient().execute(request); Header ce = response.getFirstHeader("Content-Encoding"); String contentEncoding = null; StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 500) { //TODO currently return 500, after server fix replace with 401 //re login LoginTask.login(null); return null; } HttpEntity entity = response.getEntity(); InputStream instream = null; if (entity != null) instream = entity.getContent(); if (ce != null) { contentEncoding = ce.getValue(); if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); } } return instream; } catch (IOException e) { Log.e(e.getMessage(), "XML parser - " + feedUrl); throw e; } }
From source file:com.anhth12.lambda.app.serving.AbstractLambdaResource.java
protected static InputStream maybeDecompress(String contentType, InputStream in) throws IOException { if (contentType != null) { switch (contentType) { case "application/zip": in = new ZipInputStream(in); break; case "application/gzip": case "application/x-gzip": in = new GZIPInputStream(in); break; }/*from w w w . jav a 2 s . c om*/ } return in; }
From source file:cascading.util.Util.java
public static Object deserializeBase64(String string, boolean decompress) throws IOException { if (string == null || string.length() == 0) return null; ObjectInputStream in = null;//from w w w . j av a 2s . c o m try { ByteArrayInputStream bytes = new ByteArrayInputStream(Base64.decodeBase64(string.getBytes())); in = new ObjectInputStream(decompress ? new GZIPInputStream(bytes) : bytes) { @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { try { return Class.forName(desc.getName(), false, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException exception) { return super.resolveClass(desc); } } }; return in.readObject(); } catch (ClassNotFoundException exception) { throw new FlowException("unable to deserialize data", exception); } finally { if (in != null) in.close(); } }
From source file:com.zotoh.core.io.StreamUte.java
/** * @param bits/*from w w w . j a va2s .c om*/ * @return * @throws IOException */ public static byte[] gunzip(byte[] bits) throws IOException { return bits == null ? null : bits.length == 0 ? new byte[0] : getBytes(new GZIPInputStream(asStream(bits))); }
From source file:forge.quest.io.QuestDataIO.java
/** * <p>// w w w. j a va2s . com * loadData. * </p> * * @param xmlSaveFile *   {@link java.io.File} * @return {@link forge.quest.data.QuestData} */ public static QuestData loadData(final File xmlSaveFile) { try { QuestData data; final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile)); final StringBuilder xml = new StringBuilder(); final char[] buf = new char[1024]; final InputStreamReader reader = new InputStreamReader(zin); while (reader.ready()) { final int len = reader.read(buf); if (len == -1) { break; } // when end of stream was reached xml.append(buf, 0, len); } zin.close(); String bigXML = xml.toString(); data = (QuestData) QuestDataIO.getSerializer(true).fromXML(bigXML); if (data.getVersionNumber() != QuestData.CURRENT_VERSION_NUMBER) { try { QuestDataIO.updateSaveFile(data, bigXML, xmlSaveFile.getName().replace(".dat", "")); } catch (final Exception e) { //BugReporter.reportException(e); throw new RuntimeException(e); } } return data; } catch (final Exception ex) { //BugReporter.reportException(ex, "Error loading Quest Data"); throw new RuntimeException(ex); } }
From source file:uk.ac.ebi.eva.pipeline.jobs.steps.VepAnnotationGeneratorStepTest.java
@Test public void shouldGenerateVepAnnotations() throws Exception { makeGzipFile("20\t60343\t60343\tG/A\t+", jobOptions.getVepInput()); File vepOutputFile = JobTestUtils.createTempFile(); jobOptions.setVepOutput(vepOutputFile.getAbsolutePath()); vepOutputFile.delete();// w w w . java2s .c om TestCase.assertFalse(vepOutputFile.exists()); // ensure the annot file doesn't exist from previous executions // When the execute method in variantsAnnotCreate is executed JobExecution jobExecution = jobLauncherTestUtils.launchStep(AnnotationJob.GENERATE_VEP_ANNOTATION); //Then variantsAnnotCreate step should complete correctly assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); // And VEP output should exist and annotations should be in the file TestCase.assertTrue(vepOutputFile.exists()); Assert.assertEquals(537, JobTestUtils.getLines(new GZIPInputStream(new FileInputStream(vepOutputFile)))); vepOutputFile.delete(); }
From source file:com.amazonaws.services.logs.subscriptions.CloudWatchLogsSubscriptionTransformer.java
private static byte[] uncompress(byte[] compressedData) throws IOException { byte[] buffer = new byte[1024]; try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { try (GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(compressedData))) { int len; while ((len = gzis.read(buffer)) > 0) { out.write(buffer, 0, len); }/* w w w . ja va2 s .co m*/ } out.flush(); return out.toByteArray(); } }
From source file:edu.cornell.med.icb.goby.readers.FastXReader.java
/** * Create the FASTX reader.//ww w .j av a2s . co m * @param file the file that contains the FASTA / FASTQ data * @throws IOException error reading or the input stream doesn't support "mark" */ public FastXReader(final String file) throws IOException { this(file.endsWith(".gz") ? new GZIPInputStream(new FastBufferedInputStream(new FileInputStream(file))) : new FileInputStream(file)); }
From source file:de.zib.scalaris.examples.wikipedia.data.Revision.java
/** * De-compresses the given text and returns it as a string. * /*from ww w . ja v a 2s. c o m*/ * @param text * the compressed text * * @return the de-compressed text * * @throws RuntimeException * if de-compressing the text did not work */ protected static String unpackText(byte[] text) throws RuntimeException { try { ByteArrayOutputStream unpacked = new ByteArrayOutputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(text); GZIPInputStream gis = new GZIPInputStream(bis); byte[] bbuf = new byte[256]; int read = 0; while ((read = gis.read(bbuf)) >= 0) { unpacked.write(bbuf, 0, read); } gis.close(); return new String(unpacked.toString("UTF-8")); } catch (IOException e) { throw new RuntimeException(e); } }