/**
 * The MIT License
 *
 * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.
 * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package unirest;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;

public class BinaryResponse extends ResponseBase<InputStream> {

    private Optional<HttpEntity> body;

    protected BinaryResponse(HttpResponse response) {
        super(response);
        body = Optional.ofNullable(response.getEntity());
    }

    @Override
    public InputStream getRawBody() {
        return body.map(this::tryGet)
                .orElse(new ByteArrayInputStream(new byte[0]));
    }

    @Override
    public InputStream getBody() {
        return getRawBody();
    }

    private InputStream tryGet(HttpEntity e) {
        try {
            return e.getContent();
        } catch (IOException e1) {
            throw new UnirestException(e1);
        }
    }
}

@@ -1346,22 +1346,24 @@
 ttp.Http
-Entity
+Response
 ;%0Aimport
@@ -1379,28 +1379,32 @@
 he.http.
-HttpResponse
+util.EntityUtils
 ;%0A%0Aimpor
@@ -1509,23 +1509,22 @@
 a.util.O
-ptional
+bjects
 ;%0A%0Apubli
@@ -1599,28 +1599,19 @@
 ate 
-Optional%3CHttpEntity%3E
+InputStream
  bod
@@ -1712,197 +1712,183 @@
 y = 
-Optional.ofNullable(response.getEntity());%0A    %7D%0A%0A    @Override%0A    public InputStream
+new ByteArrayInputStream(getBody(response));%0A    %7D%0A%0A    private byte%5B%5D
  get
-Raw
 Body(
-) %7B%0A        return body.map(this::tryGet)%0A                .orElse(new ByteArrayInputStream(
+HttpResponse response) %7B%0A        if (Objects.isNull(response.getEntity())) %7B%0A            return 
 new 
@@ -1898,197 +1898,97 @@
 e%5B0%5D
-))
 ;%0A    
-%7D%0A%0A
     
-@Override%0A    public InputStream getBody() %7B%0A        return getRawBody();%0A    %7D%0A%0A    private InputStream tryGet(HttpEntity e) %7B%0A        try %7B%0A            return e.getContent(
+%7D%0A        try %7B%0A            return EntityUtils.toByteArray(response.getEntity()
 );%0A 
@@ -2016,17 +2016,16 @@
 eption e
-1
 ) %7B%0A    
@@ -2060,17 +2060,16 @@
 eption(e
-1
 );%0A     
@@ -2078,11 +2078,168 @@
  %7D%0A    %7D
+%0A%0A    @Override%0A    public InputStream getRawBody() %7B%0A        return body;%0A    %7D%0A%0A    @Override%0A    public InputStream getBody() %7B%0A        return body;%0A    %7D
 %0A%7D%0A

copy the stream in the constructor