byte[] () { try (ByteArrayOutputStream gZippedBody = new ByteArrayOutputStream()) { GZIPOutputStream gZipper = new GZIPOutputStream(gZippedBody); gZipper.write(myContent.getBytes(myCharset)); gZippedBody.flush(); gZipper.close(); return gZippedBody.toByteArray(); } catch (IOException e) { throw new HttpRequestBodyGzipException(e); } }