Fixes a bug caused by the version file not being properly closed

This commit is contained in:
Kristian Knarvik 2020-09-20 17:36:10 +02:00
parent 5058383f93
commit 6c0e352649
2 changed files with 5 additions and 6 deletions

View File

@ -48,7 +48,7 @@ public class ServerVersionContainer {
/**
* Resets the state of the server version container
*/
public void reset() {
void reset() {
this.vanillaVersion = null;
this.snapshotVersion = null;
this.bungeeVersion = null;
@ -92,7 +92,7 @@ public class ServerVersionContainer {
/**
* Tries to save the state of this server version container
*/
public void saveState() {
void saveState() {
File saveFile = new File(versionFile);
PrintWriter file;
try {
@ -116,12 +116,10 @@ public class ServerVersionContainer {
* Loads the object state from the save file
*/
private void loadState() {
BufferedReader reader;
if (!new File(versionFile).exists()) {
return;
}
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(versionFile)));
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(versionFile)))) {
String currentData = CommonFunctions.readBufferedReader(reader);
for (String line : currentData.split("\n")) {
parseSaveLine(line);

View File

@ -131,7 +131,7 @@ public final class CommonFunctions {
* @param destination <p>Target destination</p>
* @throws IOException <p>If we can't start a file stream</p>
*/
public static void copyFolder(GUI serverLauncherGui, File source, File destination) throws IOException {
private static void copyFolder(GUI serverLauncherGui, File source, File destination) throws IOException {
if (!source.isDirectory()) {
copyFile(serverLauncherGui, source, destination);
} else {
@ -200,6 +200,7 @@ public final class CommonFunctions {
while (reader.ready() && (line = reader.readLine()) != null) {
text.append(line).append("\n");
}
reader.close();
return text.toString().trim();
}