In Spring's ByteArrayHttpMessageConverter
, you can find the method readInternal
which converts the contents of a request into the desired format (in this case byte[]
).
The code (Spring 4.0.0.RELEASE):
long contentLength = inputMessage.getHeaders().getContentLength();
ByteArrayOutputStream bos = new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE);
StreamUtils.copy(inputMessage.getBody(), bos);
return bos.toByteArray();
The second line says: *If the request payload isn't empty take it's content length, and set the capacity of the ByteArrayOutputStream
with that. Else if the content length is < 0, then set it to StreamUtils.BUFFER_SIZE (= 4096).*
Im not really sure why it is implemented this way, but that's how it actually works.