@@ -87,9 +87,9 @@ public String header(String name) {
87
87
public abstract InputStream bodyStream () throws IOException ;
88
88
89
89
/**
90
- * Gets the {@link GitHubConnectorRequest } for this response.
90
+ * Gets the {@link GitHubConnector } for this response.
91
91
*
92
- * @return the {@link GitHubConnectorRequest } for this response.
92
+ * @return the {@link GitHubConnector } for this response.
93
93
*/
94
94
@ Nonnull
95
95
public GitHubConnectorRequest request () {
@@ -161,7 +161,6 @@ public abstract static class ByteArrayResponse extends GitHubConnectorResponse {
161
161
private boolean inputStreamRead = false ;
162
162
private byte [] inputBytes = null ;
163
163
private boolean isClosed = false ;
164
- private boolean avoidBufferedResponseStream ;
165
164
166
165
/**
167
166
* Constructor for ByteArray Response
@@ -177,7 +176,6 @@ protected ByteArrayResponse(@Nonnull GitHubConnectorRequest request,
177
176
int statusCode ,
178
177
@ Nonnull Map <String , List <String >> headers ) {
179
178
super (request , statusCode , headers );
180
- avoidBufferedResponseStream = request .avoidBufferedResponseStream ();
181
179
}
182
180
183
181
/**
@@ -190,29 +188,27 @@ public InputStream bodyStream() throws IOException {
190
188
throw new IOException ("Response is closed" );
191
189
}
192
190
193
- if (avoidBufferedResponseStream ) {
194
- synchronized (this ) {
195
- if (inputStreamRead ) {
196
- throw new IOException ("Response is already consumed" );
197
- }
198
- inputStreamRead = true ;
199
- return wrapStream (rawBodyStream ());
200
- }
201
- }
202
-
203
191
synchronized (this ) {
192
+ InputStream body ;
204
193
if (!inputStreamRead ) {
205
- InputStream rawStream = rawBodyStream ();
206
- try (InputStream stream = wrapStream (rawStream )) {
207
- if (stream != null ) {
208
- inputBytes = IOUtils .toByteArray (stream );
194
+ body = wrapStream (rawBodyStream ());
195
+ if (!request ().avoidBufferedResponseStream ()) {
196
+ try (InputStream stream = body ) {
197
+ if (stream != null ) {
198
+ inputBytes = IOUtils .toByteArray (stream );
199
+ }
209
200
}
210
201
}
211
202
inputStreamRead = true ;
203
+ if (request ().avoidBufferedResponseStream ()) {
204
+ return body ;
205
+ }
212
206
}
213
207
}
214
208
215
- if (inputBytes == null ) {
209
+ if (request ().avoidBufferedResponseStream ()) {
210
+ throw new IOException ("Response is already consumed" );
211
+ } else if (inputBytes == null ) {
216
212
throw new IOException ("Response body missing, stream null" );
217
213
}
218
214
0 commit comments