Skip to content

Commit

Permalink
Close input stream resources (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed Jan 2, 2024
1 parent db1a32b commit 44d6d6b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions metafacture-io/src/main/java/org/metafacture/io/HttpOpener.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,21 +286,21 @@ public void setBody(final String body) {

@Override
public void process(final String input) {
try {
final String requestUrl = getInput(input, url);
final String requestBody = getInput(input,
body == null && method.getRequestHasBody() ? INPUT_DESIGNATOR : body);
final String requestUrl = getInput(input, url);
final String requestBody = getInput(input,
body == null && method.getRequestHasBody() ? INPUT_DESIGNATOR : body);

try {
final URL urlToOpen = new URL(requestUrl);
final HttpURLConnection connection = requestBody != null ?
doOutput(urlToOpen, requestBody) : doRedirects(urlToOpen);

final InputStream inputStream = getInputStream(connection);
final String charset = getContentCharset(connection);

getReceiver().process(new InputStreamReader(
"gzip".equalsIgnoreCase(connection.getContentEncoding()) ?
new GZIPInputStream(inputStream) : inputStream, charset));
final Reader reader = new InputStreamReader(
"gzip".equalsIgnoreCase(connection.getContentEncoding()) ?
new GZIPInputStream(inputStream) : inputStream, charset);
getReceiver().process(reader);
}
catch (final IOException e) {
throw new MetafactureException(e);
Expand Down

0 comments on commit 44d6d6b

Please sign in to comment.