artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

OutOfMemoryError with logging enabled #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-http-java-client (e.g. 1.5.0-beta)?

1.8.0-beta

Java environment (e.g. Java 6, Android 2.3, App Engine)?

Android

Describe the problem.

Reported by user here:

http://stackoverflow.com/questions/9941378/how-to-download-a-large-file-using-go
ogle-api-java-client-on-android

copied here:

Recently, I try to use google-api-java-client library to access google 
document. I can use this library to get a list, create new documents, and 
update successfully. However, when I want to download a large file (> 10mb) 
from Google Document, it causes OutOfMemoryError.

03-30 17:57:10.650: E/AndroidRuntime(11022): java.lang.OutOfMemoryError
03-30 17:57:10.650: E/AndroidRuntime(11022):    at 
java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
03-30 17:57:10.650: E/AndroidRuntime(11022):    at 
java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
03-30 17:57:10.650: E/AndroidRuntime(11022):    at 
com.google.api.client.http.AbstractInputStreamContent.copy(AbstractInputStreamCo
ntent.java:213)
03-30 17:57:10.650: E/AndroidRuntime(11022):    at 
com.google.api.client.http.AbstractInputStreamContent.copy(AbstractInputStreamCo
ntent.java:179)
03-30 17:57:10.650: E/AndroidRuntime(11022):    at 
com.google.api.client.http.HttpResponse.getContent(HttpResponse.java:384)
This is my code:

try {
    ...
    HttpRequest request = getRequestFactory().buildGetRequest(link);
    HttpResponse response = request.execute();
    InputStream is = response.getContent();
    ...
} catch (IOException e) {
    e.printStackTrace();
}

The response code is 200, and it can work successfully on small files. Is there 
any method to download a large file using google-api-java-client?

How would you expect it to be fixed?

No OutOfMemoryError.

Original issue reported on code.google.com by yan...@google.com on 7 Apr 2012 at 12:42

GoogleCodeExporter commented 9 years ago
I am not sure if we can fix this for when logging is enabled.
To log the content we have to store it in memory in a ByteArrayOutputStream 
especially because we need to convert it back into an InputStream for content. 
We cannot store only the content limit else when we convert it back into an 
InputStream it will have missing information. Please advice, thank you.

Original comment by rmis...@google.com on 19 Apr 2012 at 11:48

GoogleCodeExporter commented 9 years ago
I'll take it.  We can use FilteredInputStream and FilteredOutputStream.

Original comment by yan...@google.com on 25 Apr 2012 at 10:34

GoogleCodeExporter commented 9 years ago
http://codereview.appspot.com/6123059/

Original comment by yan...@google.com on 26 Apr 2012 at 4:31

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 27 Apr 2012 at 4:13

GoogleCodeExporter commented 9 years ago
Hello. I use this api ver. 1.9.0. but the issue seems not resolved.
Please see followings.

java.lang.OutOfMemoryError
at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
at 
org.apache.harmony.luni.internal.net.www.protocol.http.RetryableOutputStream.wri
te(RetryableOutputStream.java:60)
at 
com.google.api.client.http.AbstractInputStreamContent.copy(AbstractInputStreamCo
ntent.java:213)
at 
com.google.api.client.http.AbstractInputStreamContent.writeTo(AbstractInputStrea
mContent.java:78)
at 
com.google.api.client.http.MultipartRelatedContent.writeTo(MultipartRelatedConte
nt.java:124)
at 
com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:81
)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:842)

this is occurred at...

private final HttpResponse execute(HttpRequest request) throws IOException {
    prepare(request);
    request.setContentLoggingLimit(0);
    return request.execute(); <--HERE
}

above code is almost same to sample code.
am I wrong?

Original comment by soumi.ak...@gmail.com on 30 May 2012 at 2:24