Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/main/java/com/qiniu/http/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import okhttp3.MediaType;

import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/qiniu/storage/BucketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down