From 993eb7ac37a9940b9a3e04f73403c5f851370895 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 30 Jul 2018 10:34:54 +0200 Subject: [PATCH] Don't have to check for stuff if you throw instead --- .../voxelmodpack/hdskins/skins/NetClient.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/skins/NetClient.java b/src/hdskins/java/com/voxelmodpack/hdskins/skins/NetClient.java index c53db20c..a982f647 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/skins/NetClient.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/skins/NetClient.java @@ -119,22 +119,18 @@ public class NetClient implements Closeable { * Gets or obtains a response status code. */ public int getResponseCode() throws IOException { - if (getResponse() == null) { - return HttpStatus.SC_NOT_FOUND; - } - - return response.getStatusLine().getStatusCode(); + return getResponse().getStatusLine().getStatusCode(); } /** * Consumes and returns the entire response body. */ public String getResponseText() throws IOException { - if (getResponse() == null || response.getEntity() == null) { + if (getResponse().getEntity() == null) { return ""; } - try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(getResponse().getEntity().getContent()))) { StringBuilder builder = new StringBuilder(); int ch; @@ -148,8 +144,12 @@ public class NetClient implements Closeable { @Override public void close() throws IOException { - if (response != null) { - EntityUtils.consumeQuietly(response.getEntity()); + try { + if (response != null) { + response.close(); + } + } finally { + response = null; } } }