private static void closeBodyOf(RawHttpResponse<?> response) { if (response != null) { response.getBody().ifPresent(b -> { try { b.close(); } catch (IOException e) { e.printStackTrace(); } }); } }
private static void closeBodyOf(RawHttpResponse<?> response) { if (response != null) { response.getBody().ifPresent(b -> { try { b.close(); } catch (IOException e) { e.printStackTrace(); } }); } }
/** * Ensure that this response is read eagerly, downloading the full body if necessary. * <p> * The returned object can be safely passed around after the connection used to receive * this response has been closed. * * @param keepAlive whether to keep the connection alive. If false, the {@link BodyReader} * associated with this response is closed after by the time this method returns. * @return this response, after eagerly downloading all of its contents. * @throws IOException if an error occurs while reading this response */ public EagerHttpResponse<Response> eagerly(boolean keepAlive) throws IOException { try { return EagerHttpResponse.from(this); } finally { if (!keepAlive) { getBody().ifPresent(b -> { try { b.close(); } catch (IOException e) { e.printStackTrace(); } }); } } }
/** * Ensure that this response is read eagerly, downloading the full body if necessary. * <p> * The returned object can be safely passed around after the connection used to receive * this response has been closed. * * @param keepAlive whether to keep the connection alive. If false, the {@link BodyReader} * associated with this response is closed after by the time this method returns. * @return this response, after eagerly downloading all of its contents. * @throws IOException if an error occurs while reading this response */ public EagerHttpResponse<Response> eagerly(boolean keepAlive) throws IOException { try { return EagerHttpResponse.from(this); } finally { if (!keepAlive) { getBody().ifPresent(b -> { try { b.close(); } catch (IOException e) { e.printStackTrace(); } }); } } }