2828import org .json .simple .JSONValue ;
2929
3030import java .io .BufferedReader ;
31+ import java .io .ByteArrayInputStream ;
3132import java .io .Closeable ;
3233import java .io .IOException ;
3334import java .io .InputStream ;
3435import java .io .InputStreamReader ;
3536import java .io .Reader ;
37+ import java .io .StringReader ;
3638import java .net .URI ;
3739import java .net .URISyntaxException ;
3840import java .nio .charset .StandardCharsets ;
@@ -274,11 +276,23 @@ public Long getContentLength()
274276
275277 public InputStream getInputStream () throws IOException
276278 {
279+ if (_responseText != null )
280+ {
281+ // We've already consumed the input stream and stashed the result, so use that instead of going back
282+ // to the stream
283+ return new ByteArrayInputStream (_responseText .getBytes (StandardCharsets .UTF_8 ));
284+ }
277285 return _httpResponse .getEntity ().getContent ();
278286 }
279287
280288 public Reader getReader () throws IOException
281289 {
290+ if (_responseText != null )
291+ {
292+ // We've already consumed the input stream and stashed the result, so use that instead of going back
293+ // to the stream
294+ return new StringReader (_responseText );
295+ }
282296 return new BufferedReader (new InputStreamReader (getInputStream (), StandardCharsets .UTF_8 ));
283297 }
284298
@@ -295,6 +309,7 @@ public String getText() throws IOException
295309 }
296310
297311 // Caller is responsible for closing the response
312+ @ Override
298313 public void close () throws IOException
299314 {
300315 _httpResponse .close ();
0 commit comments