ApacheGatewayConnection implements GatewayConnection { protected static InputStreamEntity zipAndCreateEntity(final InputStream inputStream) throws IOException { byte[] buffer = new byte[4096]; GZIPOutputStream gzos = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { gzos = new GZIPOutputStream(baos); while (inputStream.available() > 0) { int length = inputStream.read(buffer); gzos.write(buffer, 0,length); } } finally { if (gzos != null) { gzos.close(); } } byte[] fooGzippedBytes = baos.toByteArray(); return new InputStreamEntity(new ByteArrayInputStream(fooGzippedBytes), -1); } ApacheGatewayConnection(Endpoint endpoint,
                            FeedParams feedParams,
                            String clusterSpecificRoute,
                            ConnectionParams connectionParams,
                            HttpClientFactory httpClientFactory,
                            String clientId,
                            Clock clock); @Override InputStream write(List<Document> docs); @Override InputStream poll(); @Override Instant lastPollTime(); @Override InputStream drain(); @Override boolean connect(); @Override Instant connectionTime(); @Override Endpoint getEndpoint(); @Override void handshake(); @Override void close();  }
@Test public void testZipAndCreateEntity() throws IOException { String testString = "Hello world"; InputStream stream = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8)); InputStreamEntity inputStreamEntity = ApacheGatewayConnection.zipAndCreateEntity(stream); String rawContent = TestUtils.zipStreamToString(inputStreamEntity.getContent()); assertEquals(testString, rawContent); }