I want to to gzip when size of output stream is greater than 100 bytes . I am trying various approaches but couldn’t get how can I get content-length from output stream .Value from Content-length in httpheader is incorrect
Could you please help me how can I find length of output stream
@Provider
@Compress
public class GzipInterceptor implements WriterInterceptor {
@Context
private HttpHeaders httpHeaders;
@Override
public void aroundWriteTo(WriterInterceptorContext context)
throws IOException, WebApplicationException {
List<String> acceptEncoding = null;
if (httpHeaders != null) {
MultivaluedMap<String, String> requestHeaders = httpHeaders.getRequestHeaders();
acceptEncoding = requestHeaders.get(HttpHeaders.ACCEPT_ENCODING);
}
if (acceptEncoding != null) {
for (String s : acceptEncoding) {
if (s.contains(“gzip”)) {
MultivaluedMap<String, Object> headers = context.getHeaders();
OutputStream os = context.getOutputStream();
if(//content-legth greater than 100 bytes)//I need some help here {
headers.add(HttpHeaders.CONTENT_ENCODING, “”gzip”);
context.setOutputStream(new GZIPOutputStream(os));
}
break;
}
}
}
context.proceed();
}
}
Thanks for your help