mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2025-02-15 05:17:56 +00:00
Condense HttpUtil
This commit is contained in:
parent
89c4ce24ef
commit
8e306a92e3
1 changed files with 1 additions and 13 deletions
|
@ -10,30 +10,18 @@ import java.net.URL;
|
||||||
public class HttpUtil {
|
public class HttpUtil {
|
||||||
|
|
||||||
public static String readUrl(String urlString) {
|
public static String readUrl(String urlString) {
|
||||||
BufferedReader reader = null;
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(urlString).openStream()))){
|
||||||
try {
|
|
||||||
URL url = new URL(urlString);
|
|
||||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
int read;
|
int read;
|
||||||
char[] chars = new char[1024];
|
char[] chars = new char[1024];
|
||||||
while ((read = reader.read(chars)) != -1) {
|
while ((read = reader.read(chars)) != -1) {
|
||||||
buffer.append(chars, 0, read);
|
buffer.append(chars, 0, read);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (Settings.DEBUG) {
|
if (Settings.DEBUG) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue