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));
}
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);
}
}
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;
}
}
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();
}
}
}
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);
}
Aggregations