contentLength support for Resource decoding

Expose the known content length, if known, in the InputStreamResource returned by ResourceHttpMessageConverter or
ResourceDecoder.

See gh-24292
This commit is contained in:
Oleh Faizulin
2020-01-04 09:54:53 +02:00
committed by Rossen Stoyanchev
parent e3e7d90415
commit e96b71acf3
4 changed files with 30 additions and 0 deletions

View File

@@ -105,4 +105,22 @@ class ResourceDecoderTests extends AbstractDecoderTests<ResourceDecoder> {
Collections.singletonMap(ResourceDecoder.FILENAME_HINT, "testFile"));
}
@Test
public void decodeInputStreamResource() {
Flux<DataBuffer> input = Flux.concat(dataBuffer(this.fooBytes), dataBuffer(this.barBytes));
testDecodeAll(input, InputStreamResource.class, step -> step
.consumeNextWith(resource -> {
try {
byte[] bytes = StreamUtils.copyToByteArray(resource.getInputStream());
assertThat(new String(bytes)).isEqualTo("foobar");
assertThat(resource.contentLength()).isEqualTo(fooBytes.length + barBytes.length);
}
catch (IOException ex) {
throw new AssertionError(ex.getMessage(), ex);
}
})
.expectComplete()
.verify());
}
}