September 2019
Intermediate to advanced
816 pages
18h 47m
English
Handling a body response as InputStream can be accomplished using BodyHandlers.ofInputStream(), as shown in the following snippet of code:
HttpResponse<InputStream> responseOfInputStream = client.send( request, HttpResponse.BodyHandlers.ofInputStream());System.out.println("\nHttpResponse.BodyHandlers.ofInputStream():");System.out.println("Status code: " + responseOfInputStream.statusCode());byte[] allBytes;try (InputStream fromIs = responseOfInputStream.body()) { allBytes = fromIs.readAllBytes();}System.out.println("Body: " + new String(allBytes, StandardCharsets.UTF_8));
Read now
Unlock full access