Search in sources :

Example 16 with GZIPInputStream

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

the class JerseyClientIntegrationTest method checkBody.

private void checkBody(HttpExchange httpExchange, boolean gzip) throws IOException {
    assertThat(httpExchange.getRequestHeaders().get(HttpHeaders.CONTENT_TYPE)).containsExactly(APPLICATION_JSON);
    InputStream requestBody = gzip ? new GZIPInputStream(httpExchange.getRequestBody()) : httpExchange.getRequestBody();
    String body = CharStreams.toString(new InputStreamReader(requestBody, StandardCharsets.UTF_8));
    assertThat(JSON_MAPPER.readTree(body)).isEqualTo(JSON_MAPPER.createObjectNode().put("email", "john@doe.me").put("name", "John Doe"));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream)

Example 17 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project jetty.project by eclipse.

the class GzipHandlerTest method testGzipNotMicroChunked.

@Test
public void testGzipNotMicroChunked() throws Exception {
    // generated and parsed test
    HttpTester.Request request = HttpTester.newRequest();
    HttpTester.Response response;
    request.setMethod("GET");
    request.setURI("/ctx/microchunked");
    request.setVersion("HTTP/1.1");
    request.setHeader("Host", "tester");
    request.setHeader("Accept-Encoding", "gzip");
    ByteBuffer rawresponse = _connector.getResponse(request.generate());
    // System.err.println(BufferUtil.toUTF8String(rawresponse));
    response = HttpTester.parseResponse(rawresponse);
    assertThat(response.getStatus(), is(200));
    assertThat(response.get("Transfer-Encoding"), containsString("chunked"));
    assertThat(response.get("Content-Encoding"), containsString("gzip"));
    assertThat(response.get("Vary"), is("Accept-Encoding"));
    InputStream testIn = new GZIPInputStream(new ByteArrayInputStream(response.getContentBytes()));
    ByteArrayOutputStream testOut = new ByteArrayOutputStream();
    IO.copy(testIn, testOut);
    assertEquals(__micro, testOut.toString("UTF8"));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Example 18 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project jetty.project by eclipse.

the class GzipHandlerTest method testGzipHandler.

@Test
public void testGzipHandler() throws Exception {
    // generated and parsed test
    HttpTester.Request request = HttpTester.newRequest();
    HttpTester.Response response;
    request.setMethod("GET");
    request.setURI("/ctx/content?vary=Accept-Encoding,Other");
    request.setVersion("HTTP/1.0");
    request.setHeader("Host", "tester");
    request.setHeader("accept-encoding", "gzip");
    response = HttpTester.parseResponse(_connector.getResponses(request.generate()));
    assertThat(response.getStatus(), is(200));
    assertThat(response.get("Content-Encoding"), Matchers.equalToIgnoringCase("gzip"));
    assertThat(response.get("ETag"), is(__contentETagGzip));
    assertThat(response.getCSV("Vary", false), Matchers.contains("Accept-Encoding", "Other"));
    InputStream testIn = new GZIPInputStream(new ByteArrayInputStream(response.getContentBytes()));
    ByteArrayOutputStream testOut = new ByteArrayOutputStream();
    IO.copy(testIn, testOut);
    assertEquals(__content, testOut.toString("UTF8"));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Example 19 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project jetty.project by eclipse.

the class GzipHandlerTest method testForwardGzipHandler.

@Test
public void testForwardGzipHandler() throws Exception {
    // generated and parsed test
    HttpTester.Request request = HttpTester.newRequest();
    HttpTester.Response response;
    request.setMethod("GET");
    request.setVersion("HTTP/1.0");
    request.setHeader("Host", "tester");
    request.setHeader("accept-encoding", "gzip");
    request.setURI("/ctx/forward");
    response = HttpTester.parseResponse(_connector.getResponses(request.generate()));
    assertThat(response.getStatus(), is(200));
    assertThat(response.get("Content-Encoding"), Matchers.equalToIgnoringCase("gzip"));
    assertThat(response.get("ETag"), is(__contentETagGzip));
    assertThat(response.get("Vary"), is("Accept-Encoding"));
    InputStream testIn = new GZIPInputStream(new ByteArrayInputStream(response.getContentBytes()));
    ByteArrayOutputStream testOut = new ByteArrayOutputStream();
    IO.copy(testIn, testOut);
    assertEquals(__content, testOut.toString("UTF8"));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Example 20 with GZIPInputStream

use of java.util.zip.GZIPInputStream in project jetty.project by eclipse.

the class GZIPContentDecoderTest method testStreamNoBlocks.

@Test
public void testStreamNoBlocks() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream output = new GZIPOutputStream(baos);
    output.close();
    byte[] bytes = baos.toByteArray();
    GZIPInputStream input = new GZIPInputStream(new ByteArrayInputStream(bytes), 1);
    int read = input.read();
    assertEquals(-1, read);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

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