diff --git a/src/main/java/com/qiniu/http/Response.java b/src/main/java/com/qiniu/http/Response.java index a82832286..592663ef9 100644 --- a/src/main/java/com/qiniu/http/Response.java +++ b/src/main/java/com/qiniu/http/Response.java @@ -8,6 +8,7 @@ import okhttp3.MediaType; import java.io.IOException; +import java.io.InputStream; import java.util.Locale; /** @@ -67,11 +68,11 @@ public static Response create(okhttp3.Response response, String address, double String error = null; int code = response.code(); String reqId = null; + reqId = response.header("X-Reqid"); + reqId = (reqId == null) ? null : reqId.trim(); byte[] body = null; if (ctype(response).equals(Client.JsonMime)) { - reqId = response.header("X-Reqid"); - reqId = (reqId == null) ? null : reqId.trim(); try { body = response.body().bytes(); if (response.code() >= 400 && !StringUtils.isNullOrEmpty(reqId) && body != null) { @@ -94,11 +95,11 @@ static Response createError(okhttp3.Response response, String address, double du } int code = response.code(); String reqId = null; + reqId = response.header("X-Reqid"); + reqId = (reqId == null) ? null : reqId.trim(); byte[] body = null; if (ctype(response).equals(Client.JsonMime)) { - reqId = response.header("X-Reqid"); - reqId = (reqId == null) ? null : reqId.trim(); try { body = response.body().bytes(); if (response.code() >= 400 && !StringUtils.isNullOrEmpty(reqId) && body != null) { @@ -198,6 +199,13 @@ public String bodyString() throws QiniuException { return StringUtils.utf8String(body()); } + public synchronized InputStream bodyStream() throws QiniuException { + if (this.response == null) { + return null; + } + return this.response.body().byteStream(); + } + public String contentType() { return ctype(response); } diff --git a/src/test/java/com/qiniu/storage/BucketTest.java b/src/test/java/com/qiniu/storage/BucketTest.java index 522398862..2725dced3 100644 --- a/src/test/java/com/qiniu/storage/BucketTest.java +++ b/src/test/java/com/qiniu/storage/BucketTest.java @@ -55,7 +55,7 @@ public void testListUseDelimiter() { bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, "test/3/", true); FileListing l = bucketManager.listFiles(TestConfig.bucket, "test/", null, 10, "/"); assertEquals(3, l.items.length); - assertEquals(1, l.commonPrefixes.length); + assertEquals(2, l.commonPrefixes.length); } catch (QiniuException e) { e.printStackTrace();