InputStreamDelegateEncoder implements Encoder { @Override public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException { if (bodyType.equals(InputStream.class)) { try { template.body(Util.toByteArray((InputStream) object), StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } } else { delegate.encode(object, bodyType, template); } } InputStreamDelegateEncoder(Encoder delegate); @Override void encode(Object object, Type bodyType, RequestTemplate template);  }
@Test public void testEncodesAsInputStream() throws Exception { byte[] object = bytes("data"); inputStreamDelegateEncoder.encode(new ByteArrayInputStream(object), InputStream.class, requestTemplate); assertThat(requestTemplate.body()).isEqualTo(object); }
@Test public void testUsesDelegateWithNonInputStreamBodyType() throws Exception { String data = "data"; inputStreamDelegateEncoder.encode(data, String.class, requestTemplate); verify(delegate).encode(data, String.class, requestTemplate); }