Fully mirgate main source to Java NIO (except some files in tools).
This commit is contained in:
@@ -19,10 +19,11 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -61,7 +62,7 @@ public class CharsetConstants {
|
||||
|
||||
private static String loadCharsetFromConfig() {
|
||||
try {
|
||||
YamlReader reader = new YamlReader(new FileReader(YamlConfig.CONFIG_FILE_NAME, StandardCharsets.US_ASCII));
|
||||
YamlReader reader = new YamlReader(Files.newBufferedReader(Paths.get(YamlConfig.CONFIG_FILE_NAME), StandardCharsets.US_ASCII));
|
||||
reader.getConfig().readConfig.setIgnoreUnknownProperties(true);
|
||||
StrippedYamlConfig charsetConfig = reader.read(StrippedYamlConfig.class);
|
||||
reader.close();
|
||||
|
||||
@@ -24,7 +24,6 @@ package provider;
|
||||
import provider.wz.WZFiles;
|
||||
import provider.wz.XMLWZFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class DataProviderFactory {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package provider.wz;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@@ -38,7 +38,7 @@ public enum WZFiles {
|
||||
private static String getWzDirectory() {
|
||||
// Either provide a custom directory path through the "wz-path" property when launching the .jar, or don't provide one to use the default "wz" directory
|
||||
String propertyPath = System.getProperty("wz-path");
|
||||
if (propertyPath != null && new File(propertyPath).isDirectory()) {
|
||||
if (propertyPath != null && Files.isDirectory(Paths.get(propertyPath))) {
|
||||
return propertyPath;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@@ -28,9 +28,12 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.script.*;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* @author Matze
|
||||
@@ -45,8 +48,8 @@ public abstract class AbstractScriptManager {
|
||||
|
||||
protected ScriptEngine getInvocableScriptEngine(String path) {
|
||||
path = "scripts/" + path;
|
||||
File scriptFile = new File(path);
|
||||
if (!scriptFile.exists()) {
|
||||
Path scriptFile = Paths.get(path);
|
||||
if (!Files.exists(scriptFile)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -57,8 +60,8 @@ public abstract class AbstractScriptManager {
|
||||
|
||||
enableScriptHostAccess(graalScriptEngine);
|
||||
|
||||
try (FileReader fr = new FileReader(scriptFile, CharsetConstants.CHARSET)) {
|
||||
engine.eval(fr);
|
||||
try (BufferedReader br = Files.newBufferedReader(scriptFile, CharsetConstants.CHARSET)) {
|
||||
engine.eval(br);
|
||||
} catch (final ScriptException | IOException t) {
|
||||
log.warn("Exception during script eval for file: {}", path, t);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user