Skip to content

Commit 0597b74

Browse files
author
Yaniv Inbar
committed
http: avoid having to call LowLevelHttpResponse.getContent() twice
https://codereview.appspot.com/13074043/
1 parent ab1a65d commit 0597b74

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

google-http-client-android/src/main/java/com/google/api/client/extensions/android/json/AndroidJsonFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static AndroidJsonFactory getDefaultInstance() {
6464
}
6565

6666
/** Holder for the result of {@link #getDefaultInstance()}. */
67+
@Beta
6768
static class InstanceHolder {
6869
static final AndroidJsonFactory INSTANCE = new AndroidJsonFactory();
6970
}

google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.api.client.util.StringUtils;
2525

2626
import java.io.IOException;
27+
import java.io.InputStream;
2728
import java.util.concurrent.Callable;
2829
import java.util.concurrent.Executor;
2930
import java.util.concurrent.Executors;
@@ -968,8 +969,11 @@ public HttpResponse execute() throws IOException {
968969
response = new HttpResponse(this, lowLevelHttpResponse);
969970
responseConstructed = true;
970971
} finally {
971-
if (!responseConstructed && lowLevelHttpResponse.getContent() != null) {
972-
lowLevelHttpResponse.getContent().close();
972+
if (!responseConstructed) {
973+
InputStream lowLevelContent = lowLevelHttpResponse.getContent();
974+
if (lowLevelContent != null) {
975+
lowLevelContent.close();
976+
}
973977
}
974978
}
975979
} catch (IOException e) {

0 commit comments

Comments
 (0)