Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpResponse.download(OutputStream) #81

Closed
wonderfly opened this issue Jan 9, 2015 · 2 comments

Comments

@wonderfly
Copy link
Contributor

commented Jan 9, 2015

From yan...@google.com on April 07, 2012 05:34:29

External references, such as a standards document, or specification? http://stackoverflow.com/questions/9941378/how-to-download-a-large-file-using-google-api-java-client-on-android http://javadoc.google-http-java-client.googlecode.com/hg/1.8.3-beta/com/google/api/client/http/HttpResponse.html Java environments (e.g. Java 6, Android 2.3, App Engine, or All)? All Please describe the feature requested. Here's an idea: suppose you want to just download the content of a response into a file, e.g. if you are downloading an image. A good way to do it is to use AbstractInputStreamContent.copy as in this example:

HttpTransport transport = new NetHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory();
HttpRequest request =
    requestFactory.buildGetRequest(new GenericUrl(
        " https://www.google.com/images/srpr/logo3w.png")); OutputStream outputStream =
    new FileOutputStream(new File("/tmp/logo3w.png"));
HttpResponse response = request.execute();
InputStream inputStream = response.getContent();
AbstractInputStreamContent.copy(inputStream, outputStream, true);

Unfortunately, AbstractInputStreamContent.copy is hard to discover. Perhaps we can make it easier to find by adding an HttpResponse.download(OutputStream) method, so now the last 2 lines would now be:

response.download(outputStream);

We could also potentially add something similar in JsonHttpRequest and JsonHttpClient.

Original issue: http://code.google.com/p/google-http-java-client/issues/detail?id=81

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From rmis...@google.com on April 09, 2012 05:56:34

This idea sounds good to me.
Sent out http://codereview.appspot.com/5985069/

Status: Started

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From rmis...@google.com on April 11, 2012 07:57:06

Status: Fixed

@wonderfly wonderfly closed this Jan 9, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.