mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-02-14 10:41:41 +01:00
Ensure readers/writers are closed.
This commit is contained in:
parent
3940f275c5
commit
c89e6c6957
@ -1,6 +1,7 @@
|
|||||||
package fr.neatmonster.nocheatplus;
|
package fr.neatmonster.nocheatplus;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
@ -186,26 +187,30 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
if (config.getBoolean(ConfPaths.MISCELLANEOUS_CHECKFORUPDATES)){
|
if (config.getBoolean(ConfPaths.MISCELLANEOUS_CHECKFORUPDATES)){
|
||||||
// Is a new update available?
|
// Is a new update available?
|
||||||
|
BufferedReader bufferedReader = null;
|
||||||
|
updateAvailable = false;
|
||||||
try {
|
try {
|
||||||
final int currentVersion = Integer.parseInt(getDescription().getVersion().split("-b")[1]);
|
final int currentVersion = Integer.parseInt(getDescription().getVersion().split("-b")[1]);
|
||||||
final URL url = new URL("http://nocheatplus.org:8080/job/NoCheatPlus/lastSuccessfulBuild/api/json");
|
final URL url = new URL("http://nocheatplus.org:8080/job/NoCheatPlus/lastSuccessfulBuild/api/json");
|
||||||
final URLConnection connection = url.openConnection();
|
final URLConnection connection = url.openConnection();
|
||||||
connection.setReadTimeout(config.getInt(ConfPaths.MISCELLANEOUS_READTIMEOUT, 4) * 1000);
|
connection.setReadTimeout(config.getInt(ConfPaths.MISCELLANEOUS_READTIMEOUT, 4) * 1000);
|
||||||
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
String content = "", line = "";
|
String line, content = "";
|
||||||
while ((line = bufferedReader.readLine()) != null)
|
while ((line = bufferedReader.readLine()) != null)
|
||||||
content += line;
|
content += line;
|
||||||
bufferedReader.close();
|
|
||||||
final int jenkinsVersion = Integer.parseInt(content.split("\"number\":")[1].split(",")[0]);
|
final int jenkinsVersion = Integer.parseInt(content.split("\"number\":")[1].split(",")[0]);
|
||||||
updateAvailable = currentVersion < jenkinsVersion;
|
updateAvailable = currentVersion < jenkinsVersion;
|
||||||
} catch (final Exception e) {}
|
} catch (final Exception e) {}
|
||||||
|
finally{
|
||||||
|
if (bufferedReader != null) try{bufferedReader.close();}catch (IOException e){};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the configuration outdated?
|
// Is the configuration outdated?
|
||||||
try {
|
try {
|
||||||
final int currentVersion = Integer.parseInt(getDescription().getVersion().split("-b")[1]);
|
final int currentVersion = Integer.parseInt(getDescription().getVersion().split("-b")[1]);
|
||||||
final int configurationVersion = Integer.parseInt(config.options().header()
|
final int configurationVersion = Integer.parseInt(
|
||||||
.split("-b")[1].split("\\.")[0]);
|
config.options().header().split("-b")[1].split("\\.")[0]);
|
||||||
if (currentVersion > configurationVersion)
|
if (currentVersion > configurationVersion)
|
||||||
configOutdated = true;
|
configOutdated = true;
|
||||||
} catch (final Exception e) {}
|
} catch (final Exception e) {}
|
||||||
|
@ -541,18 +541,28 @@ public class Metrics {
|
|||||||
|
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
|
|
||||||
|
OutputStreamWriter writer = null;
|
||||||
|
BufferedReader reader = null;
|
||||||
|
String response;
|
||||||
|
try{
|
||||||
// Write the data
|
// Write the data
|
||||||
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
writer = new OutputStreamWriter(connection.getOutputStream());
|
||||||
writer.write(data.toString());
|
writer.write(data.toString());
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
|
||||||
// Now read the response
|
// Now read the response
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
final String response = reader.readLine();
|
response = reader.readLine();
|
||||||
|
}
|
||||||
|
catch (IOException e){
|
||||||
|
response = "ERR (" + e.getClass().getSimpleName() + "): " + e.getMessage();
|
||||||
|
}
|
||||||
|
finally{
|
||||||
// close resources
|
// close resources
|
||||||
writer.close();
|
if (writer != null) try{writer.close();} catch (IOException e){};
|
||||||
reader.close();
|
if (reader != null) try{reader.close();} catch (IOException e){};
|
||||||
|
}
|
||||||
|
|
||||||
if (response == null || response.startsWith("ERR"))
|
if (response == null || response.startsWith("ERR"))
|
||||||
throw new IOException(response); // Throw the exception
|
throw new IOException(response); // Throw the exception
|
||||||
|
Loading…
Reference in New Issue
Block a user