mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-29 23:48:00 +01:00
Don't have to check for stuff if you throw instead
This commit is contained in:
parent
bd010d6d97
commit
993eb7ac37
1 changed files with 9 additions and 9 deletions
|
@ -119,22 +119,18 @@ public class NetClient implements Closeable {
|
||||||
* Gets or obtains a response status code.
|
* Gets or obtains a response status code.
|
||||||
*/
|
*/
|
||||||
public int getResponseCode() throws IOException {
|
public int getResponseCode() throws IOException {
|
||||||
if (getResponse() == null) {
|
return getResponse().getStatusLine().getStatusCode();
|
||||||
return HttpStatus.SC_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.getStatusLine().getStatusCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consumes and returns the entire response body.
|
* Consumes and returns the entire response body.
|
||||||
*/
|
*/
|
||||||
public String getResponseText() throws IOException {
|
public String getResponseText() throws IOException {
|
||||||
if (getResponse() == null || response.getEntity() == null) {
|
if (getResponse().getEntity() == null) {
|
||||||
return "";
|
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();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
int ch;
|
int ch;
|
||||||
|
@ -148,8 +144,12 @@ public class NetClient implements Closeable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
try {
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
EntityUtils.consumeQuietly(response.getEntity());
|
response.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
response = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue