Example usage for java.util.zip GZIPInputStream GZIPInputStream

List of usage examples for java.util.zip GZIPInputStream GZIPInputStream

Introduction

In this page you can find the example usage for java.util.zip GZIPInputStream GZIPInputStream.

Prototype

public GZIPInputStream(InputStream in) throws IOException 

Source Link

Document

Creates a new input stream with a default buffer size.

Usage

From source file:io.digibyte.tools.util.BRCompressor.java

public static byte[] gZipExtract(byte[] compressed) {
    if (compressed == null || compressed.length == 0)
        return null;
    try {/* w w w. j av  a2s .  c  o m*/
        InputStream isr = new GZIPInputStream(new ByteArrayInputStream(compressed));
        return IOUtils.toByteArray(isr);
    } catch (IOException e) {
        BRReportsManager.reportBug(e);
        e.printStackTrace();
    }
    return null;
}

From source file:edu.cornell.med.icb.goby.algorithmic.data.HeptamerInfo.java

/**
 * Load heptamer info from disk.//from w  w  w. ja v a  2  s  .c o  m
 *
 * @param filename
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
public static HeptamerInfo load(final String filename) throws IOException, ClassNotFoundException {
    GZIPInputStream inputStream = null;
    try {
        inputStream = new GZIPInputStream(new FileInputStream(filename));
        return (HeptamerInfo) BinIO.loadObject(inputStream);
    } finally {
        if (inputStream != null) {
            IOUtils.closeQuietly(inputStream);

        }
    }
}

From source file:com.machinepublishers.jbrowserdriver.ResponseHandler.java

static InputStream handleResponse(StreamConnection conn, InputStream inputStream) throws IOException {
    String url = conn.getURL().toExternalForm();
    byte[] bytes = new byte[0];
    try {//from  www .  jav a2  s. com
        if ("gzip".equalsIgnoreCase(conn.getContentEncoding())) {
            bytes = Util.toBytes(new GZIPInputStream(inputStream));
        } else if ("deflate".equalsIgnoreCase(conn.getContentEncoding())) {
            bytes = Util.toBytes(new InflaterInputStream(inputStream));
        } else {
            bytes = Util.toBytes(inputStream);
        }
        conn.removeContentEncoding();
        conn.setContentLength(bytes.length);

        Settings settings = SettingsManager.settings();
        if (settings != null) {
            String disposition = conn.getHeaderField("Content-Disposition");

            if (settings.saveAttachments() && disposition != null
                    && StatusMonitor.instance().isPrimaryDocument(true, url)) {
                writeContentToDisk(bytes, StreamConnection.attachmentsDir(), url, conn.getContentTypeRaw(),
                        disposition);
            }

            if (settings.saveMedia() && ((StreamConnection) conn).isMedia()) {
                writeContentToDisk(bytes, StreamConnection.mediaDir(), url, conn.getContentTypeRaw(),
                        disposition);
            }
        }
        byte[] newContent = getBody(conn, bytes, url);
        if (newContent != null) {
            bytes = newContent;
        }
    } catch (Throwable t) {
        LogsServer.instance().exception(t);
    } finally {
        Util.close(inputStream);
    }
    conn.setContentLength(bytes.length);
    return new ByteArrayInputStream(bytes);
}

From source file:com.orange.clara.cloud.servicedbdumper.filer.compression.GzipCompressing.java

@Async
public Future<Boolean> gunziptIt(OutputStream outputStream, InputStream inputStream) throws IOException {
    logger.debug("Start uncompressing...");
    GZIPInputStream gzis = new GZIPInputStream(inputStream);
    ByteStreams.copy(gzis, outputStream);

    outputStream.flush();/*from   w w w . java2s  .com*/
    outputStream.close();
    gzis.close();
    inputStream.close();
    logger.debug("Finish uncompressing");
    return new AsyncResult<Boolean>(true);
}

From source file:com.fsck.k9.mail.store.webdav.WebDavHttpClient.java

public static InputStream getUngzippedContent(HttpEntity entity) throws IOException {
    InputStream responseStream = entity.getContent();
    if (responseStream == null)
        return null;
    Header header = entity.getContentEncoding();
    if (header == null)
        return responseStream;
    String contentEncoding = header.getValue();
    if (contentEncoding == null)
        return responseStream;
    if (contentEncoding.contains("gzip")) {
        Log.i(LOG_TAG, "Response is gzipped");
        responseStream = new GZIPInputStream(responseStream);
    }/*from w w  w  . jav  a 2s.  co  m*/
    return responseStream;
}

From source file:com.github.sdbg.debug.core.util.JsonTests.java

public void test_parse1() throws IOException, JSONException {
    InputStream in = JsonTests.class.getResourceAsStream("test1.json.gz");
    GZIPInputStream gzipIn = new GZIPInputStream(in);
    String string = Streams.loadAndClose(new InputStreamReader(gzipIn, "UTF-8"));

    int iterations = 1;

    for (int i = 0; i < iterations; i++) {
        @SuppressWarnings("unused")
        JSONObject obj = new JSONObject(string);
    }//from w  ww.  j a v a 2s  .co  m
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.CompressionUtils.java

/**
 * Get an uncompressed input stream for a given input stream created for a particular location.
 * //from w w w . j  ava2s.co  m
 * @param aLocation a resource location (e.g. a path, url, etc.)
 * @param aStream a raw stream of potentially compressed data.
 * @return stream wrapped with a decompressing stream.
 */
public static InputStream getInputStream(String aLocation, InputStream aStream) throws IOException {
    String lcLocation = aLocation.toLowerCase();
    if (lcLocation.endsWith(GZIP.getExtension())) {
        return new GZIPInputStream(aStream);
    } else if (lcLocation.endsWith(BZIP2.getExtension()) || lcLocation.endsWith(".bzip2")) {
        return new BZip2CompressorInputStream(aStream);
    } else if (lcLocation.endsWith(XZ.getExtension())) {
        return new XZCompressorInputStream(aStream);
    } else {
        return aStream;
    }
}

From source file:com.micro.http.MicroGzipDecompressingEntity.java

public InputStream getContent() throws IOException, IllegalStateException {
    InputStream wrappedin = wrappedEntity.getContent();
    return new GZIPInputStream(wrappedin);
}

From source file:com.machinelinking.util.FileUtil.java

public static BufferedInputStream openDecompressedInputStream(InputStream is, String ext) throws IOException {
    final InputStream decompressInputStream;
    switch (ext) {
    case "gz":
        decompressInputStream = new GZIPInputStream(is);
        break;/*from w w w.j ava2s .c o  m*/
    case "bz2":
        decompressInputStream = new BZip2CompressorInputStream(is);
        break;
    default:
        throw new IllegalArgumentException("Unsupported extension: " + ext);
    }
    return new BufferedInputStream(decompressInputStream);
}

From source file:cn.isif.util_plus.http.client.entity.GZipDecompressingEntity.java

@Override
InputStream decorate(final InputStream wrapped) throws IOException {
    return new GZIPInputStream(wrapped);
}