8
8
import okhttp3 .MediaType ;
9
9
10
10
import java .io .IOException ;
11
+ import java .io .InputStream ;
11
12
import java .util .Locale ;
12
13
13
14
/**
@@ -67,11 +68,11 @@ public static Response create(okhttp3.Response response, String address, double
67
68
String error = null ;
68
69
int code = response .code ();
69
70
String reqId = null ;
71
+ reqId = response .header ("X-Reqid" );
72
+ reqId = (reqId == null ) ? null : reqId .trim ();
70
73
71
74
byte [] body = null ;
72
75
if (ctype (response ).equals (Client .JsonMime )) {
73
- reqId = response .header ("X-Reqid" );
74
- reqId = (reqId == null ) ? null : reqId .trim ();
75
76
try {
76
77
body = response .body ().bytes ();
77
78
if (response .code () >= 400 && !StringUtils .isNullOrEmpty (reqId ) && body != null ) {
@@ -94,11 +95,11 @@ static Response createError(okhttp3.Response response, String address, double du
94
95
}
95
96
int code = response .code ();
96
97
String reqId = null ;
98
+ reqId = response .header ("X-Reqid" );
99
+ reqId = (reqId == null ) ? null : reqId .trim ();
97
100
98
101
byte [] body = null ;
99
102
if (ctype (response ).equals (Client .JsonMime )) {
100
- reqId = response .header ("X-Reqid" );
101
- reqId = (reqId == null ) ? null : reqId .trim ();
102
103
try {
103
104
body = response .body ().bytes ();
104
105
if (response .code () >= 400 && !StringUtils .isNullOrEmpty (reqId ) && body != null ) {
@@ -198,6 +199,13 @@ public String bodyString() throws QiniuException {
198
199
return StringUtils .utf8String (body ());
199
200
}
200
201
202
+ public synchronized InputStream bodyStream () throws QiniuException {
203
+ if (this .response == null ) {
204
+ return null ;
205
+ }
206
+ return this .response .body ().byteStream ();
207
+ }
208
+
201
209
public String contentType () {
202
210
return ctype (response );
203
211
}
0 commit comments