@Override
public void close() throws IOException {
if (bufferedOutput instanceof ByteArrayOutputStream) {
ByteArrayOutputStream compressedContent = new ByteArrayOutputStream();
GZIPOutputStream gzipstream = new GZIPOutputStream(compressedContent);
gzipstream.write(((ByteArrayOutputStream) bufferedOutput).toByteArray());
gzipstream.finish();
byte[] compressedBytes = compressedContent.toByteArray();
response.setContentLength(compressedBytes.length);
response.addHeader("Content-Encoding", "gzip");
output.write(compressedBytes);
} else ((GZIPOutputStream) bufferedOutput).finish();