use of java.util.zip.GZIPInputStream in project airpal by airbnb.
the class ResultsPreviewResource method getS3Preview.
private Response getS3Preview(URI fileURI, int numLines) {
val filename = getFilename(fileURI);
val outputKey = getOutputKey(filename);
// download ~100 kb (depending on your definition) of the file
val request = new GetObjectRequest(outputBucket, outputKey).withRange(0, 100 * 1024);
val object = s3Client.getObject(request);
ObjectMetadata objectMetadata = object.getObjectMetadata();
boolean gzip = "gzip".equalsIgnoreCase(objectMetadata.getContentEncoding());
try (InputStream input = object.getObjectContent()) {
InputStreamReader reader;
if (gzip) {
reader = new InputStreamReader(new GZIPInputStream(input));
} else {
reader = new InputStreamReader(input);
}
return getPreviewFromCSV(new CSVReader(reader), numLines);
} catch (IOException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of java.util.zip.GZIPInputStream in project fastjson by alibaba.
the class Issue859 method test_for_issue.
public void test_for_issue() throws Exception {
InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");
GZIPInputStream gzipInputStream = new GZIPInputStream(is);
String text = org.apache.commons.io.IOUtils.toString(gzipInputStream);
long startMillis = System.currentTimeMillis();
for (int i = 0; i < 1; ++i) {
JSON.parseObject(text);
}
// new Gson().fromJson(text, java.util.HashMap.class);
//new ObjectMapper().readValue(text, java.util.HashMap.class);
long costMillis = System.currentTimeMillis() - startMillis;
System.out.println("cost : " + costMillis);
}
use of java.util.zip.GZIPInputStream in project jmonkeyengine by jMonkeyEngine.
the class GZIPSerializer method readObject.
@SuppressWarnings("unchecked")
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
try {
GZIPCompressedMessage result = new GZIPCompressedMessage();
byte[] byteArray = new byte[data.remaining()];
data.get(byteArray);
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] tmp = new byte[9012];
int read;
while (in.available() > 0 && ((read = in.read(tmp)) > 0)) {
out.write(tmp, 0, read);
}
result.setMessage((Message) Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray())));
return (T) result;
} catch (Exception e) {
e.printStackTrace();
throw new IOException(e.toString());
}
}
use of java.util.zip.GZIPInputStream in project hudson-2.x by hudson.
the class AnnotatedLargeText method createAnnotator.
private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException {
try {
String base64 = req != null ? req.getHeader("X-ConsoleAnnotator") : null;
if (base64 != null) {
Cipher sym = Secret.getCipher("AES");
sym.init(Cipher.DECRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())), sym)), Hudson.getInstance().pluginManager.uberClassLoader);
long timestamp = ois.readLong();
if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis() - timestamp))
// don't deserialize something too old to prevent a replay attack
return (ConsoleAnnotator) ois.readObject();
}
} catch (GeneralSecurityException e) {
throw new IOException2(e);
} catch (ClassNotFoundException e) {
throw new IOException2(e);
}
// start from scratch
return ConsoleAnnotator.initial(context == null ? null : context.getClass());
}
use of java.util.zip.GZIPInputStream in project SmartAndroidSource by jaychou2012.
the class AbstractAjaxCallback method copy.
private void copy(InputStream is, OutputStream os, String encoding, int max) throws IOException {
if ("gzip".equalsIgnoreCase(encoding)) {
is = new GZIPInputStream(is);
}
Object o = null;
if (progress != null) {
o = progress.get();
}
Progress p = null;
if (o != null) {
p = new Progress(o);
}
AQUtility.copy(is, os, max, p);
}
Aggregations