Search in sources :

Example 1 with GzipSink

use of okio.GzipSink in project zipkin by openzipkin.

the class ZipkinRuleTest method gzippedSpans.

@Test
public void gzippedSpans() throws IOException {
    byte[] spansInJson = Codec.JSON.writeSpans(TRACE);
    Buffer sink = new Buffer();
    GzipSink gzipSink = new GzipSink(sink);
    gzipSink.write(new Buffer().write(spansInJson), spansInJson.length);
    gzipSink.close();
    ByteString gzippedJson = sink.readByteString();
    client.newCall(new Request.Builder().url(zipkin.httpUrl() + "/api/v1/spans").addHeader("Content-Encoding", "gzip").post(RequestBody.create(MediaType.parse("application/json"), gzippedJson)).build()).execute();
    assertThat(zipkin.getTraces()).containsOnly(TRACE);
    assertThat(zipkin.collectorMetrics().bytes()).isEqualTo(spansInJson.length);
}
Also used : Buffer(okio.Buffer) ByteString(okio.ByteString) GzipSink(okio.GzipSink) Test(org.junit.Test)

Example 2 with GzipSink

use of okio.GzipSink in project okhttp by square.

the class OkApacheClientTest method gzip.

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

Example 3 with GzipSink

use of okio.GzipSink in project okhttp by square.

the class ResponseCacheTest 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 4 with GzipSink

use of okio.GzipSink in project okhttp by square.

the class HttpOverHttp2Test method gzip.

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

Example 5 with GzipSink

use of okio.GzipSink in project okhttp by square.

the class Http2Test method gzip.

private static Buffer gzip(byte[] data) throws IOException {
    Buffer buffer = new Buffer();
    Okio.buffer(new GzipSink(buffer)).write(data).close();
    return buffer;
}
Also used : Buffer(okio.Buffer) GzipSink(okio.GzipSink)

Aggregations

GzipSink (okio.GzipSink)24 BufferedSink (okio.BufferedSink)18 Buffer (okio.Buffer)13 RequestBody (okhttp3.RequestBody)5 ByteString (okio.ByteString)3 RequestBody (com.squareup.okhttp.RequestBody)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 Test (org.junit.Test)2 ErrorPayload (co.elastic.apm.impl.error.ErrorPayload)1 File (java.io.File)1 IOException (java.io.IOException)1 TreeSet (java.util.TreeSet)1 OkHttpClient (okhttp3.OkHttpClient)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 BufferedSource (okio.BufferedSource)1 Sink (okio.Sink)1