use of okio.GzipSink in project id4i-api_client-java by BlueRainSoftware.
the class GzipRequestInterceptor method gzip.
private RequestBody gzip(final RequestBody body) {
return new RequestBody() {
@Override
public MediaType contentType() {
return body.contentType();
}
@Override
public long contentLength() {
// We don't know the compressed length in advance!
return -1;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
body.writeTo(gzipSink);
gzipSink.close();
}
};
}
use of okio.GzipSink in project mapbox-events-android by mapbox.
the class GzipRequestInterceptor method gzip.
private RequestBody gzip(final RequestBody body) {
return new RequestBody() {
@Override
public MediaType contentType() {
return body.contentType();
}
@Override
public long contentLength() {
// We don't know the compressed length in advance!
return -1;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
body.writeTo(gzipSink);
gzipSink.close();
}
};
}
use of okio.GzipSink in project apm-agent-java by elastic.
the class ApmServerHttpPayloadSender method sendPayload.
@Override
public void sendPayload(final Payload payload) {
logger.debug("Sending payload with {} elements to APM server {}", payload.getPayloadObjects().size(), reporterConfiguration.getServerUrl());
final String path;
if (payload instanceof ErrorPayload) {
path = "/v1/errors";
} else {
path = "/v1/transactions";
}
final Request.Builder builder = new Request.Builder().url(reporterConfiguration.getServerUrl() + path).header("User-Agent", getUserAgent(payload));
if (reporterConfiguration.getSecretToken() != null) {
builder.header("Authorization", "Bearer " + reporterConfiguration.getSecretToken());
}
if (useGzip(payload)) {
builder.header("Content-Encoding", "gzip");
}
Request request = builder.post(new RequestBody() {
@Override
public MediaType contentType() {
return MEDIA_TYPE_JSON;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
if (useGzip(payload)) {
GzipSink gzipSink = new GzipSink(sink);
gzipSink.deflater().setLevel(GZIP_COMPRESSION_LEVEL);
sink = Okio.buffer(gzipSink);
}
payloadSerializer.serializePayload(sink, payload);
sink.close();
payload.recycle();
}
}).build();
try {
Response response = httpClient.newCall(request).execute();
int statusCode = response.code();
logger.debug("APM server responded with status code {}", statusCode);
if (statusCode >= 400) {
droppedTransactions += payload.getPayloadObjects().size();
if (response.body() != null) {
logger.debug(response.body().string());
}
}
response.close();
} catch (IOException e) {
logger.debug("Sending payload to APM server failed", e);
droppedTransactions += payload.getPayloadObjects().size();
}
}
use of okio.GzipSink in project KalturaGeneratedAPIClientsJava by kaltura.
the class GzipInterceptor method gzip.
private RequestBody gzip(final RequestBody body) {
return new RequestBody() {
@Override
public MediaType contentType() {
return body.contentType();
}
@Override
public long contentLength() {
// We don't know the compressed length in advance!
return -1;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
body.writeTo(gzipSink);
gzipSink.close();
}
};
}
use of okio.GzipSink in project xDrip by NightscoutFoundation.
the class GzipRequestInterceptor method gzip.
private RequestBody gzip(final RequestBody body) {
return new RequestBody() {
@Override
public MediaType contentType() {
return body.contentType();
}
@Override
public long contentLength() {
// We don't know the compressed length in advance!
return -1;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
body.writeTo(gzipSink);
gzipSink.close();
}
};
}
Aggregations