mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-07 17:28:03 +08:00
Closed some ConfigReaders appropriately
This commit is contained in:
parent
55e123f309
commit
6b7e9c1132
@ -152,7 +152,9 @@ public class SettingsTable extends Table {
|
|||||||
@Override
|
@Override
|
||||||
public Config processResults(ResultSet set) throws SQLException {
|
public Config processResults(ResultSet set) throws SQLException {
|
||||||
if (set.next()) {
|
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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ public class ConfigReader implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() {
|
||||||
scanner.close();
|
scanner.close();
|
||||||
closed = true;
|
closed = true;
|
||||||
}
|
}
|
||||||
|
@ -185,8 +185,8 @@ public class NetworkSettingManager implements SubSystem {
|
|||||||
|
|
||||||
Database database = dbSystem.getDatabase();
|
Database database = dbSystem.getDatabase();
|
||||||
|
|
||||||
try {
|
try (ConfigReader reader = new ConfigReader(file.toPath())) {
|
||||||
Config config = new ConfigReader(file.toPath()).read();
|
Config config = reader.read();
|
||||||
database.save().saveConfig(serverUUID, config);
|
database.save().saveConfig(serverUUID, config);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
|
@ -105,8 +105,8 @@ public class ServerSettingsManager implements SubSystem {
|
|||||||
|
|
||||||
Database database = dbSystem.getDatabase();
|
Database database = dbSystem.getDatabase();
|
||||||
|
|
||||||
try {
|
try (ConfigReader reader = new ConfigReader(file.toPath())) {
|
||||||
Config config = new ConfigReader(file.toPath()).read();
|
Config config = reader.read();
|
||||||
database.save().saveConfig(serverInfo.getServerUUID(), config);
|
database.save().saveConfig(serverInfo.getServerUUID(), config);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
|
@ -26,8 +26,6 @@ import org.junit.runner.RunWith;
|
|||||||
import org.junitpioneer.jupiter.TempDirectory;
|
import org.junitpioneer.jupiter.TempDirectory;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.UncheckedIOException;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@ -50,8 +48,6 @@ class ConfigChangeTest {
|
|||||||
private Config prepareConfig(String withValue) {
|
private Config prepareConfig(String withValue) {
|
||||||
try (ConfigReader reader = new ConfigReader(new Scanner(withValue))) {
|
try (ConfigReader reader = new ConfigReader(new Scanner(withValue))) {
|
||||||
return new Config(temporaryFolder.resolve("config.yml").toFile(), reader.read());
|
return new Config(temporaryFolder.resolve("config.yml").toFile(), reader.read());
|
||||||
} catch (IOException e) {
|
|
||||||
throw new UncheckedIOException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user