mirror of https://github.com/LOOHP/Limbo.git
Fixed resource not closing
This commit is contained in:
parent
8d2b7ea0cb
commit
6013235c73
|
|
@ -24,9 +24,11 @@ public class FileConfiguration {
|
|||
private Map<String, Object> mapping;
|
||||
private String header;
|
||||
|
||||
public FileConfiguration(File file) throws FileNotFoundException {
|
||||
public FileConfiguration(File file) throws IOException {
|
||||
if (file.exists()) {
|
||||
reloadConfig(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
|
||||
InputStreamReader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
|
||||
reloadConfig(reader);
|
||||
reader.close();
|
||||
} else {
|
||||
mapping = new LinkedHashMap<>();
|
||||
}
|
||||
|
|
@ -113,7 +115,10 @@ public class FileConfiguration {
|
|||
pw.flush();
|
||||
pw.close();
|
||||
|
||||
return writer.toString();
|
||||
String str = writer.toString();
|
||||
writer.close();
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public void saveConfig(File file) throws IOException {
|
||||
|
|
|
|||
|
|
@ -47,17 +47,23 @@ public class ServerProperties {
|
|||
this.file = file;
|
||||
|
||||
Properties def = new Properties();
|
||||
def.load(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("server.properties"), StandardCharsets.UTF_8));
|
||||
InputStreamReader defStream = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("server.properties"), StandardCharsets.UTF_8);
|
||||
def.load(defStream);
|
||||
defStream.close();
|
||||
|
||||
Properties prop = new Properties();
|
||||
prop.load(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
|
||||
InputStreamReader stream = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
|
||||
prop.load(stream);
|
||||
stream.close();
|
||||
|
||||
for (Entry<Object, Object> entry : def.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
String value = entry.getValue().toString();
|
||||
prop.putIfAbsent(key, value);
|
||||
}
|
||||
prop.store(new PrintWriter(file, StandardCharsets.UTF_8), COMMENT);
|
||||
PrintWriter pw = new PrintWriter(file, StandardCharsets.UTF_8);
|
||||
prop.store(pw, COMMENT);
|
||||
pw.close();
|
||||
|
||||
protocol = Limbo.getInstance().serverImplmentationProtocol;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import java.awt.GraphicsEnvironment;
|
|||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
|
@ -14,6 +14,7 @@ import java.lang.reflect.Method;
|
|||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -190,7 +191,9 @@ public class Limbo {
|
|||
|
||||
console.sendMessage("Loading packet id mappings from mapping.json ...");
|
||||
|
||||
JSONObject json = (JSONObject) new JSONParser().parse(new FileReader(mappingFile));
|
||||
InputStreamReader reader = new InputStreamReader(new FileInputStream(mappingFile), StandardCharsets.UTF_8);
|
||||
JSONObject json = (JSONObject) new JSONParser().parse(reader);
|
||||
reader.close();
|
||||
|
||||
String classPrefix = Packet.class.getName().substring(0, Packet.class.getName().lastIndexOf(".") + 1);
|
||||
int mappingsCount = 0;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.loohp.limbo.Metrics;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -60,9 +59,9 @@ public class Metrics {
|
|||
* @param serverUUID The uuid of the server.
|
||||
* @param logFailedRequests Whether failed requests should be logged or not.
|
||||
* @param logger The logger for the failed requests.
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public Metrics() throws FileNotFoundException {
|
||||
public Metrics() throws IOException {
|
||||
name = "Limbo";
|
||||
|
||||
// Get the config file
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.loohp.limbo.Permissions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -23,7 +23,7 @@ public class PermissionsManager {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadDefaultPermissionFile(File file) throws FileNotFoundException {
|
||||
public void loadDefaultPermissionFile(File file) throws IOException {
|
||||
FileConfiguration config = new FileConfiguration(file);
|
||||
permissions.put("default", new ArrayList<>());
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.loohp.limbo.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
|
@ -36,8 +38,8 @@ public class DimensionRegistry {
|
|||
|
||||
this.reg = file;
|
||||
|
||||
try {
|
||||
JSONObject json = (JSONObject) new JSONParser().parse(new FileReader(reg));
|
||||
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(reg), StandardCharsets.UTF_8)) {
|
||||
JSONObject json = (JSONObject) new JSONParser().parse(reader);
|
||||
CompoundTag tag = CustomNBTUtils.getCompoundTagFromJson((JSONObject) json.get("value"));
|
||||
defaultTag = tag;
|
||||
codec = defaultTag.clone();
|
||||
|
|
|
|||
Loading…
Reference in New Issue