CommandHelper { public static StreamingResponseBody toStreaming(final HystrixCommand<InputStream> command) { return outputStream -> { final Observable<InputStream> stream = command.toObservable(); stream.toBlocking().subscribe(inputStream -> { try { IOUtils.copyLarge(inputStream, outputStream); outputStream.flush(); } catch (IOException e) { try { inputStream.close(); } catch (IOException closingException) { LOGGER.warn("could not close command result, a http connection may be leaked !", closingException); } LOGGER.error("Unable to fully copy command result '{}'.", command.getClass(), e); } }, TDPException::rethrowOrWrap); }; } private  CommandHelper(); static StreamingResponseBody toStreaming(final HystrixCommand<InputStream> command); static ResponseEntity<Void> async(final GenericCommand<?> command); static ResponseEntity<StreamingResponseBody> toStreaming(final GenericCommand<InputStream> command); static Publisher<T> toPublisher(final Class<T> clazz, final ObjectMapper mapper,
            final HystrixCommand<InputStream> command); static Stream<T> toStream(Class<T> clazz, ObjectMapper mapper, HystrixCommand<InputStream> command);  }
@Test public void testCommandToStreamingWithHeader() throws Exception { GenericCommand<InputStream> command = new CommandHelperTestCommand(); final ResponseEntity<StreamingResponseBody> responseEntity = CommandHelper.toStreaming(command); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); responseEntity.getBody().writeTo(outputStream); assertEquals("test", new String(outputStream.toByteArray())); assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); assertEquals("custom value", responseEntity.getHeaders().get("custom").get(0)); }
@Test public void testCommandToStreamingWithNoHeader() throws Exception { HystrixCommand<InputStream> command = new CommandHelperTestCommand(); final StreamingResponseBody responseBody = CommandHelper.toStreaming(command); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); responseBody.writeTo(outputStream); assertEquals("test", new String(outputStream.toByteArray())); }