Search in sources :

Example 91 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project commons by twitter.

the class AssetHandlerTest method unzip.

private static String unzip(ByteArrayOutputStream streamData) throws IOException {
    ByteArrayInputStream in = new ByteArrayInputStream(streamData.toByteArray());
    GZIPInputStream unzip = new GZIPInputStream(in);
    return new String(ByteStreams.toByteArray(unzip));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 92 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project syncany by syncany.

the class ApplicationLink method createTransferSettings.

private TransferSettings createTransferSettings(byte[] plaintextPluginSettingsBytes) throws StorageException, IOException {
    // Find plugin ID and settings XML
    int pluginIdentifierLength = Ints.fromByteArray(Arrays.copyOfRange(plaintextPluginSettingsBytes, 0, INTEGER_BYTES));
    String pluginId = new String(Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES, INTEGER_BYTES + pluginIdentifierLength));
    byte[] gzippedPluginSettingsByteArray = Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES + pluginIdentifierLength, plaintextPluginSettingsBytes.length);
    String pluginSettings = IOUtils.toString(new GZIPInputStream(new ByteArrayInputStream(gzippedPluginSettingsByteArray)));
    // Create transfer settings object
    try {
        TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class);
        if (plugin == null) {
            throw new StorageException("Link contains unknown connection type '" + pluginId + "'. Corresponding plugin not found.");
        }
        Class<? extends TransferSettings> pluginTransferSettingsClass = TransferPluginUtil.getTransferSettingsClass(plugin.getClass());
        TransferSettings transferSettings = new Persister().read(pluginTransferSettingsClass, pluginSettings);
        logger.log(Level.INFO, "(Decrypted) link contains: " + pluginId + " -- " + pluginSettings);
        return transferSettings;
    } catch (Exception e) {
        throw new StorageException(e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) ByteArrayInputStream(java.io.ByteArrayInputStream) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) IOException(java.io.IOException)

Example 93 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project cordova-android-chromeview by thedracle.

the class HttpEngine method initContentStream.

private void initContentStream(InputStream transferStream) throws IOException {
    responseTransferIn = transferStream;
    if (transparentGzip && responseHeaders.isContentEncodingGzip()) {
        // If the response was transparently gzipped, remove the gzip header field
        // so clients don't double decompress. http://b/3009828
        //
        // Also remove the Content-Length in this case because it contains the
        // length 528 of the gzipped response. This isn't terribly useful and is
        // dangerous because 529 clients can query the content length, but not
        // the content encoding.
        responseHeaders.stripContentEncoding();
        responseHeaders.stripContentLength();
        responseBodyIn = new GZIPInputStream(transferStream);
    } else {
        responseBodyIn = transferStream;
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream)

Example 94 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project blueprints by tinkerpop.

the class SailLoader method loadFile.

private long loadFile(final File fileOrDirectory, final SailConnection c) throws IOException {
    if (fileOrDirectory.isDirectory()) {
        long count = 0;
        for (File child : fileOrDirectory.listFiles()) {
            count += loadFile(child, c);
        }
        return count;
    } else {
        RDFFormat format;
        long startTime = System.currentTimeMillis();
        if (verbose) {
            LOGGER.info("loading file: " + fileOrDirectory);
        }
        String n = fileOrDirectory.getName();
        InputStream is;
        if (n.endsWith(".gz")) {
            String n0 = n.substring(0, n.lastIndexOf("."));
            format = RDFFormat.forFileName(n0);
            is = new GZIPInputStream(new FileInputStream(fileOrDirectory));
        } else {
            format = RDFFormat.forFileName(n);
            is = new FileInputStream(fileOrDirectory);
        }
        try {
            if (null == format) {
                LOGGER.warning("could not guess format of file: " + n);
                return 0;
            }
            RDFParser p = Rio.createParser(format);
            p.setStopAtFirstError(false);
            SailConnectionAdder adder = new SailConnectionAdder(c);
            p.setRDFHandler(adder);
            try {
                p.parse(is, baseUri);
            } catch (Throwable t) {
                // Attempt to recover.
                t.printStackTrace(System.err);
            } finally {
                is.close();
            }
            long endTime = System.currentTimeMillis();
            if (verbose) {
                LOGGER.info("\tfinished in " + (endTime - startTime) + "ms");
            }
            return adder.count;
        } finally {
            is.close();
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RDFParser(org.openrdf.rio.RDFParser) File(java.io.File) FileInputStream(java.io.FileInputStream) RDFFormat(org.openrdf.rio.RDFFormat)

Example 95 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project v7files by thiloplanz.

the class GzippedContent method getContent.

public Content getContent(ContentStorage storage, Map<String, Object> data) throws IOException {
    byte[] bytes = (byte[]) data.get("zin");
    GZIPInputStream gz = new GZIPInputStream(new ByteArrayInputStream(bytes));
    byte[] unzipped = IOUtils.toByteArray(gz);
    return new InlineContent(unzipped);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

GZIPInputStream (java.util.zip.GZIPInputStream)376 InputStream (java.io.InputStream)144 IOException (java.io.IOException)125 ByteArrayInputStream (java.io.ByteArrayInputStream)120 FileInputStream (java.io.FileInputStream)98 ByteArrayOutputStream (java.io.ByteArrayOutputStream)77 InputStreamReader (java.io.InputStreamReader)57 File (java.io.File)56 BufferedReader (java.io.BufferedReader)45 BufferedInputStream (java.io.BufferedInputStream)41 Test (org.junit.Test)41 FileOutputStream (java.io.FileOutputStream)30 URL (java.net.URL)25 InflaterInputStream (java.util.zip.InflaterInputStream)25 OutputStream (java.io.OutputStream)24 GZIPOutputStream (java.util.zip.GZIPOutputStream)21 ObjectInputStream (java.io.ObjectInputStream)19 HttpURLConnection (java.net.HttpURLConnection)19 URLConnection (java.net.URLConnection)17 HashMap (java.util.HashMap)15