Read and closes the ErrorStream / InputStream of the HttpURLConnection to allow Java reusing the open socket. @param connection the connection to consume the input
(HttpURLConnection connection)
| 166 | * @param connection the connection to consume the input |
| 167 | */ |
| 168 | private static void consume(HttpURLConnection connection) { |
| 169 | try (InputStream errorStream = connection.getErrorStream()) { |
| 170 | if (errorStream != null) { |
| 171 | Read.toByteArray(errorStream); |
| 172 | } else { |
| 173 | try (InputStream inputStream = connection.getInputStream()) { |
| 174 | if (inputStream != null) { |
| 175 | Read.toByteArray(inputStream); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } catch (IOException ignore) { |
| 180 | // swallow |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | private HttpURLConnection connectToUrl(URL url) throws IOException { |
| 185 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
no test coverage detected