Skip to content

Commit c3c037f

Browse files
authored
Merge pull request #225 from jemygraw/master
add bodyStream method for Client in case when SDK used to download bi…
2 parents 417439a + c9e4721 commit c3c037f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/main/java/com/qiniu/http/Response.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import okhttp3.MediaType;
99

1010
import java.io.IOException;
11+
import java.io.InputStream;
1112
import java.util.Locale;
1213

1314
/**
@@ -67,11 +68,11 @@ public static Response create(okhttp3.Response response, String address, double
6768
String error = null;
6869
int code = response.code();
6970
String reqId = null;
71+
reqId = response.header("X-Reqid");
72+
reqId = (reqId == null) ? null : reqId.trim();
7073

7174
byte[] body = null;
7275
if (ctype(response).equals(Client.JsonMime)) {
73-
reqId = response.header("X-Reqid");
74-
reqId = (reqId == null) ? null : reqId.trim();
7576
try {
7677
body = response.body().bytes();
7778
if (response.code() >= 400 && !StringUtils.isNullOrEmpty(reqId) && body != null) {
@@ -94,11 +95,11 @@ static Response createError(okhttp3.Response response, String address, double du
9495
}
9596
int code = response.code();
9697
String reqId = null;
98+
reqId = response.header("X-Reqid");
99+
reqId = (reqId == null) ? null : reqId.trim();
97100

98101
byte[] body = null;
99102
if (ctype(response).equals(Client.JsonMime)) {
100-
reqId = response.header("X-Reqid");
101-
reqId = (reqId == null) ? null : reqId.trim();
102103
try {
103104
body = response.body().bytes();
104105
if (response.code() >= 400 && !StringUtils.isNullOrEmpty(reqId) && body != null) {
@@ -198,6 +199,13 @@ public String bodyString() throws QiniuException {
198199
return StringUtils.utf8String(body());
199200
}
200201

202+
public synchronized InputStream bodyStream() throws QiniuException {
203+
if (this.response == null) {
204+
return null;
205+
}
206+
return this.response.body().byteStream();
207+
}
208+
201209
public String contentType() {
202210
return ctype(response);
203211
}

src/test/java/com/qiniu/storage/BucketTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void testListUseDelimiter() {
5555
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, "test/3/", true);
5656
FileListing l = bucketManager.listFiles(TestConfig.bucket, "test/", null, 10, "/");
5757
assertEquals(3, l.items.length);
58-
assertEquals(1, l.commonPrefixes.length);
58+
assertEquals(2, l.commonPrefixes.length);
5959

6060
} catch (QiniuException e) {
6161
e.printStackTrace();

0 commit comments

Comments
 (0)