Search in sources :

Example 11 with GzipSink

use of okio.GzipSink in project zipkin by openzipkin.

the class ZipkinServerIntegrationTest method writeSpans_gzipEncoded.

public void writeSpans_gzipEncoded() throws Exception {
    byte[] body = Codec.JSON.writeSpans(TRACE);
    Buffer sink = new Buffer();
    GzipSink gzipSink = new GzipSink(sink);
    gzipSink.write(new Buffer().write(body), body.length);
    gzipSink.close();
    byte[] gzippedBody = sink.readByteArray();
    mockMvc.perform(post("/api/v1/spans").content(gzippedBody).header("Content-Encoding", "gzip")).andExpect(status().isAccepted());
}
Also used : Buffer(okio.Buffer) GzipSink(okio.GzipSink)

Example 12 with GzipSink

use of okio.GzipSink in project okhttp by square.

the class Benchmark method newResponse.

private MockResponse newResponse() throws IOException {
    byte[] bytes = new byte[bodyByteCount];
    random.nextBytes(bytes);
    Buffer body = new Buffer().write(bytes);
    MockResponse result = new MockResponse();
    if (gzip) {
        Buffer gzipBody = new Buffer();
        GzipSink gzipSink = new GzipSink(gzipBody);
        gzipSink.write(body, body.size());
        gzipSink.close();
        body = gzipBody;
        result.addHeader("Content-Encoding: gzip");
    }
    if (chunked) {
        result.setChunkedBody(body, 1024);
    } else {
        result.setBody(body);
    }
    for (int i = 0; i < headerCount; i++) {
        result.addHeader(randomString(12), randomString(20));
    }
    return result;
}
Also used : Buffer(okio.Buffer) MockResponse(okhttp3.mockwebserver.MockResponse) GzipSink(okio.GzipSink)

Example 13 with GzipSink

use of okio.GzipSink in project okhttp by square.

the class CacheTest method gzip.

/** Returns a gzipped copy of {@code bytes}. */
public Buffer gzip(String data) throws IOException {
    Buffer result = new Buffer();
    BufferedSink sink = Okio.buffer(new GzipSink(result));
    sink.writeUtf8(data);
    sink.close();
    return result;
}
Also used : Buffer(okio.Buffer) GzipSink(okio.GzipSink) BufferedSink(okio.BufferedSink)

Example 14 with GzipSink

use of okio.GzipSink in project okhttp by square.

the class InterceptorTest method gzip.

private Buffer gzip(String data) throws IOException {
    Buffer result = new Buffer();
    BufferedSink sink = Okio.buffer(new GzipSink(result));
    sink.writeUtf8(data);
    sink.close();
    return result;
}
Also used : Buffer(okio.Buffer) GzipSink(okio.GzipSink) BufferedSink(okio.BufferedSink)

Aggregations

GzipSink (okio.GzipSink)14 Buffer (okio.Buffer)12 BufferedSink (okio.BufferedSink)9 ByteString (okio.ByteString)2 File (java.io.File)1 TreeSet (java.util.TreeSet)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 RequestBody (okhttp3.RequestBody)1 Response (okhttp3.Response)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 BufferedSource (okio.BufferedSource)1 Sink (okio.Sink)1 Test (org.junit.Test)1