Closed some ConfigReaders appropriately

This commit is contained in:
Rsl1122 2019-01-06 12:32:06 +02:00
parent 55e123f309
commit 6b7e9c1132
5 changed files with 8 additions and 10 deletions

View File

@ -152,7 +152,9 @@ public class SettingsTable extends Table {
@Override
public Config processResults(ResultSet set) throws SQLException {
if (set.next()) {
return new ConfigReader(new Scanner(set.getString(Col.CONFIG_CONTENT.get()))).read();
try (ConfigReader reader = new ConfigReader(new Scanner(set.getString(Col.CONFIG_CONTENT.get())))) {
return reader.read();
}
} else {
return null;
}

View File

@ -243,7 +243,7 @@ public class ConfigReader implements Closeable {
}
@Override
public void close() throws IOException {
public void close() {
scanner.close();
closed = true;
}

View File

@ -185,8 +185,8 @@ public class NetworkSettingManager implements SubSystem {
Database database = dbSystem.getDatabase();
try {
Config config = new ConfigReader(file.toPath()).read();
try (ConfigReader reader = new ConfigReader(file.toPath())) {
Config config = reader.read();
database.save().saveConfig(serverUUID, config);
} catch (IOException e) {
throw new UncheckedIOException(e);

View File

@ -105,8 +105,8 @@ public class ServerSettingsManager implements SubSystem {
Database database = dbSystem.getDatabase();
try {
Config config = new ConfigReader(file.toPath()).read();
try (ConfigReader reader = new ConfigReader(file.toPath())) {
Config config = reader.read();
database.save().saveConfig(serverInfo.getServerUUID(), config);
} catch (IOException e) {
throw new UncheckedIOException(e);

View File

@ -26,8 +26,6 @@ import org.junit.runner.RunWith;
import org.junitpioneer.jupiter.TempDirectory;
import org.mockito.junit.jupiter.MockitoExtension;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.Scanner;
@ -50,8 +48,6 @@ class ConfigChangeTest {
private Config prepareConfig(String withValue) {
try (ConfigReader reader = new ConfigReader(new Scanner(withValue))) {
return new Config(temporaryFolder.resolve("config.yml").toFile(), reader.read());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}