Search in sources :

Example 31 with GZIPInputStream

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();
    }
}
Also used : lombok.val(lombok.val) GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 32 with GZIPInputStream

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);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream)

Example 33 with GZIPInputStream

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());
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPCompressedMessage(com.jme3.network.message.GZIPCompressedMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Example 34 with GZIPInputStream

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());
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) CipherInputStream(javax.crypto.CipherInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GeneralSecurityException(java.security.GeneralSecurityException) Cipher(javax.crypto.Cipher) ObjectInputStreamEx(hudson.remoting.ObjectInputStreamEx) IOException2(hudson.util.IOException2) ObjectInputStream(java.io.ObjectInputStream)

Example 35 with GZIPInputStream

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);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) JSONObject(org.json.JSONObject)

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