Content Server - Get Content Stream with REST API fails with "Stream has been closed".

We are getting Status 200 message while trying to retrieve the document content but when we try to read the stream we are receiving Stream has been closed error message but the same works fine when we get the content response type as string.

Able to get the content if we use the below code:
ResponseEntity contentStream = restTemplate.exchange("http://r00purn0c.bnymellon.net:8080/OTCS/cs/api/v2/nodes/{OpenTextDocumentId}/content",HttpMethod.GET, httpEntity, String.class);

if (contentStream.getStatusCode().equals(HttpStatus.OK)) {
inputStream = new ByteArrayInputStream(contentStream.getBody().getBytes());
}
We are unable to get the stream if we use the below code:
ResponseEntity contentStream = restTemplate.exchange("http://r00purn0c.bnymellon.net:8080/OTCS/cs/api/v2/nodes/{OpenTextDocumentId}/content",HttpMethod.GET, httpEntity, InputStreamResource.class);

if (contentStream.getStatusCode().equals(HttpStatus.OK)) {
inputStream = contentStream.getBody().getInputStream());
}

Please provide the best way to retrieve the document content response from open text.

Tagged: