// Use the excellent content encoding handling that exists in HTTP Client
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new HttpVersion(1, 0), 0, null));
ByteArrayEntity entity = new ByteArrayEntity(content);
entity.setContentEncoding(alg);
response.setEntity(entity);
new ResponseContentEncoding().process(response, null);
return IOUtils.toByteArray(response.getEntity().getContent());
}