Search in sources :

Example 81 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project okhttp by square.

the class URLConnectionTest method clientConfiguredGzipContentEncoding.

@Test
public void clientConfiguredGzipContentEncoding() throws Exception {
    Buffer bodyBytes = gzip("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    server.enqueue(new MockResponse().setBody(bodyBytes).addHeader("Content-Encoding: gzip"));
    URLConnection connection = urlFactory.open(server.url("/").url());
    connection.addRequestProperty("Accept-Encoding", "gzip");
    InputStream gunzippedIn = new GZIPInputStream(connection.getInputStream());
    assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", readAscii(gunzippedIn, Integer.MAX_VALUE));
    assertEquals(bodyBytes.size(), connection.getContentLength());
    RecordedRequest request = server.takeRequest();
    assertEquals("gzip", request.getHeader("Accept-Encoding"));
}
Also used : Buffer(okio.Buffer) GZIPInputStream(java.util.zip.GZIPInputStream) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) HttpURLConnection(java.net.HttpURLConnection) OkHttpURLConnection(okhttp3.internal.huc.OkHttpURLConnection) URLConnection(java.net.URLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Test(org.junit.Test)

Example 82 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project okio by square.

the class LargeStreamsTest method gzipSink.

@Test
public void gzipSink() throws Exception {
    Pipe pipe = new Pipe(1024 * 1024);
    GzipSink gzipSink = new GzipSink(pipe.sink());
    // Disable compression to speed up a slow test. Improved from 141s to 35s on one machine.
    gzipSink.deflater().setLevel(Deflater.NO_COMPRESSION);
    Future<Long> future = readAllAndCloseAsync(randomSource(FOUR_GIB_PLUS_ONE), gzipSink);
    HashingSink hashingSink = HashingSink.sha256(Okio.blackhole());
    GZIPInputStream gzipIn = new GZIPInputStream(Okio.buffer(pipe.source()).inputStream());
    readAllAndClose(Okio.source(gzipIn), hashingSink);
    assertEquals(FOUR_GIB_PLUS_ONE, (long) future.get());
    assertEquals(SHA256_RANDOM_FOUR_GIB_PLUS_1, hashingSink.hash());
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Test(org.junit.Test)

Example 83 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project CoreNLP by stanfordnlp.

the class GenericAnnotationSerializer method read.

@Override
public Pair<Annotation, InputStream> read(InputStream is) throws IOException, ClassNotFoundException, ClassCastException {
    ObjectInputStream objectInput;
    if (is instanceof ObjectInputStream) {
        objectInput = (ObjectInputStream) is;
    } else {
        objectInput = new ObjectInputStream(compress ? new GZIPInputStream(is) : is);
    }
    Object annotation = objectInput.readObject();
    if (annotation == null)
        return null;
    if (!(annotation instanceof Annotation)) {
        throw new ClassCastException("ERROR: Serialized data does not contain an Annotation!");
    }
    return Pair.makePair((Annotation) annotation, (InputStream) objectInput);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream)

Example 84 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project CoreNLP by stanfordnlp.

the class AbstractSequenceClassifier method loadClassifier.

/**
   * Loads a classifier from the file, classpath resource, or URL specified by loadPath. If loadPath ends in
   * .gz, uses a GZIPInputStream.
   */
public void loadClassifier(String loadPath, Properties props) throws ClassCastException, IOException, ClassNotFoundException {
    InputStream is = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(loadPath);
    Timing t = new Timing();
    loadClassifier(is, props);
    is.close();
    t.done(log, "Loading classifier from " + loadPath);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream)

Example 85 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project CoreNLP by stanfordnlp.

the class AbstractSequenceClassifier method loadJarClassifier.

/**
   * This function will load a classifier that is stored inside a jar file (if
   * it is so stored). The classifier should be specified as its full path
   * in a jar. If the classifier is not stored in the jar file or this is not run
   * from inside a jar file, then this function will throw a RuntimeException.
   *
   * @param modelName
   *          The name of the model file. Iff it ends in .gz, then it is assumed
   *          to be gzip compressed.
   * @param props
   *          A Properties object which can override certain properties in the
   *          serialized file, such as the DocumentReaderAndWriter. You can pass
   *          in {@code null} to override nothing.
   */
// todo [john bauer 2015]: This method may not be necessary.  Perhaps use the IOUtils equivalents
public void loadJarClassifier(String modelName, Properties props) {
    Timing t = new Timing();
    try {
        InputStream is = getClass().getResourceAsStream(modelName);
        if (modelName.endsWith(".gz")) {
            is = new GZIPInputStream(is);
        }
        is = new BufferedInputStream(is);
        loadClassifier(is, props);
        is.close();
        t.done(log, "Loading CLASSPATH classifier " + modelName);
    } catch (Exception e) {
        String msg = "Error loading classifier from jar file (most likely you are not running this code from a jar file or the named classifier is not stored in the jar file)";
        throw new RuntimeException(msg, e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException)

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