Defaults { public static BiFunction<HttpRequestBase, HttpResponse, InputStream> pipeStream() { return (request, response) -> { try { return new ReleasableInputStream(response.getEntity().getContent(), request::releaseConnection); } catch (IOException e) { EntityUtils.consumeQuietly(response.getEntity()); throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }; } private  Defaults(); static Function<Exception, RuntimeException> passthrough(); static BiFunction<HttpRequestBase, HttpResponse, T> asNull(); static BiFunction<HttpRequestBase, HttpResponse, String> asString(); static BiFunction<HttpRequestBase, HttpResponse, String> emptyString(); static BiFunction<HttpRequestBase, HttpResponse, InputStream> emptyStream(); static BiFunction<HttpRequestBase, HttpResponse, InputStream> pipeStream(); static BiFunction<HttpRequestBase, HttpResponse, T> convertResponse(ObjectMapper mapper,
            Class<T> clazz); static BiFunction<HttpRequestBase, HttpResponse, T> convertResponse(ObjectMapper mapper,
            TypeReference<T> typeReference); static BiFunction<HttpRequestBase, HttpResponse, T> convertResponse(ObjectMapper mapper,
            TypeReference<T> typeReference, Function<Exception, T> errorHandler); static BiFunction<HttpRequestBase, HttpResponse, JsonNode> toJson(ObjectMapper mapper); static BiFunction<HttpRequestBase, HttpResponse, S> iterate(Class<T> clazz, ObjectMapper mapper,
            Function<Iterator<T>, S> convert); static ResponseEntity<String> getResponseEntity(HttpStatus status, HttpResponse response);  }
@Test public void shouldPipeInputStream() throws Exception { final BasicHttpResponse response = buildResponse(); response.setEntity(new StringEntity("")); final InputStream value = Defaults.pipeStream().apply(buildRequest(), response); assertEquals("", IOUtils.toString(value, Charset.defaultCharset())); }
@Test public void shouldPipeInputStream_handleIOError() throws Exception { final BasicHttpResponse response = buildResponse(); response.setEntity(new StringEntity("") { @Override public InputStream getContent() throws IOException { throw new IOException("Unexpected exception"); } }); try { Defaults.pipeStream().apply(buildRequest(), response); } catch (TDPException e) { assertEquals(CommonErrorCodes.UNEXPECTED_EXCEPTION, e.getCode()); } }