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

View File

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