radai rosenblatt created HTTPCORE-335:
-----------------------------------------

             Summary: add utility method to EntityUtils to allow reading entity 
contents into a user-provided OutputStream
                 Key: HTTPCORE-335
                 URL: https://issues.apache.org/jira/browse/HTTPCORE-335
             Project: HttpComponents HttpCore
          Issue Type: Improvement
          Components: HttpCore
    Affects Versions: 4.2.3
            Reporter: radai rosenblatt


as a user of HttpComponents the most basic way i have to download a large 
binary file using HttpCore would be:

{code}
HttpResponse response = get(url, null, null);
HttpEntity entity = response.getEntity();
byte[] data = EntityUtils.toByteArray(entity);
{code}

while this works, it has the downside of storing what might be a pretty big 
file as a byte[] in memory.
adding an extra method to EntityUtils would allow the same functionality with a 
much smaller memory footprint:

{code}
HttpResponse response = get(url, null, null);
HttpEntity entity = response.getEntity();
//user's responsibility to provide an output stream. commonly a temporary file?
File tmpFile = getMeATmpFile();
FileOutputStream os = new FileOutputStream(tmpFile);
long bytesWritten = EntityUtils.writeOut(entity,os);
//user can now work with entity contents that he has "downloaded" to the temp 
file.
{code}




--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to