com.axibase.tsd.client.GZipWriterInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atsd-api-java Show documentation
Show all versions of atsd-api-java Show documentation
The ATSD Client for Java enables Java developers to easily read
and write statistics and metadata from Axibase Time-Series Database. Build reporting,
analytics, and alerting solutions with minimal effort.
package com.axibase.tsd.client;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import javax.ws.rs.ext.WriterInterceptor;
import javax.ws.rs.ext.WriterInterceptorContext;
@Provider
public class GZipWriterInterceptor implements WriterInterceptor {
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
String acceptEncodings = getAcceptEncodingHeader(context.getHeaders());
if (acceptEncodings.contains("gzip")) {
final OutputStream outputStream = context.getOutputStream();
context.setOutputStream(new GZIPOutputStream(outputStream));
}
context.proceed();
}
private String getAcceptEncodingHeader(MultivaluedMap headers) {
Object value = headers.getFirst(HttpHeaders.ACCEPT_ENCODING);
return value == null ? "" : (String) value;
}
}