Skip to content

Commit b651f5c

Browse files
authored
Update GitHubConnectorResponse.bodyStream() implementation
1 parent d47b1cf commit b651f5c

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/main/java/org/kohsuke/github/connector/GitHubConnectorResponse.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,29 +190,27 @@ public InputStream bodyStream() throws IOException {
190190
throw new IOException("Response is closed");
191191
}
192192

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-
203193
synchronized (this) {
194+
InputStream body;
204195
if (!inputStreamRead) {
205-
InputStream rawStream = rawBodyStream();
206-
try (InputStream stream = wrapStream(rawStream)) {
207-
if (stream != null) {
208-
inputBytes = IOUtils.toByteArray(stream);
196+
body = wrapStream(rawBodyStream());
197+
if (!avoidBufferedResponseStream) {
198+
try (InputStream stream = rawStream) {
199+
if (stream != null) {
200+
inputBytes = IOUtils.toByteArray(stream);
201+
}
209202
}
210203
}
211204
inputStreamRead = true;
205+
if (avoidBufferedResponseStream) {
206+
return body;
207+
}
212208
}
213209
}
214210

215-
if (inputBytes == null) {
211+
if (avoidBufferedResponseStream) {
212+
throw new IOException("Response is already consumed");
213+
} else if (inputBytes == null) {
216214
throw new IOException("Response body missing, stream null");
217215
}
218216

0 commit comments

Comments
 (0)