private static HttpEntity asHttpEntity(byte[] data, Exchange exchange) throws Exception {
AbstractHttpEntity entity;
if (exchange != null && !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) {
String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
InputStream stream = GZIPHelper.compressGzip(contentEncoding, data);
entity = new InputStreamEntity(stream, stream instanceof ByteArrayInputStream
? stream.available() != 0 ? stream.available() : -1 : -1);
} else {
// create the Repeatable HttpEntity
entity = new ByteArrayEntity(data);
}