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 org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ public class CharsetConstants {
|
|||||||
|
|
||||||
private static String loadCharsetFromConfig() {
|
private static String loadCharsetFromConfig() {
|
||||||
try {
|
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);
|
reader.getConfig().readConfig.setIgnoreUnknownProperties(true);
|
||||||
StrippedYamlConfig charsetConfig = reader.read(StrippedYamlConfig.class);
|
StrippedYamlConfig charsetConfig = reader.read(StrippedYamlConfig.class);
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ package provider;
|
|||||||
import provider.wz.WZFiles;
|
import provider.wz.WZFiles;
|
||||||
import provider.wz.XMLWZFile;
|
import provider.wz.XMLWZFile;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class DataProviderFactory {
|
public class DataProviderFactory {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package provider.wz;
|
package provider.wz;
|
||||||
|
|
||||||
import java.io.File;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ public enum WZFiles {
|
|||||||
private static String getWzDirectory() {
|
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
|
// 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");
|
String propertyPath = System.getProperty("wz-path");
|
||||||
if (propertyPath != null && new File(propertyPath).isDirectory()) {
|
if (propertyPath != null && Files.isDirectory(Paths.get(propertyPath))) {
|
||||||
return propertyPath;
|
return propertyPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import javax.xml.parsers.DocumentBuilder;
|
|||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|||||||
@@ -28,9 +28,12 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.script.*;
|
import javax.script.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Matze
|
* @author Matze
|
||||||
@@ -45,8 +48,8 @@ public abstract class AbstractScriptManager {
|
|||||||
|
|
||||||
protected ScriptEngine getInvocableScriptEngine(String path) {
|
protected ScriptEngine getInvocableScriptEngine(String path) {
|
||||||
path = "scripts/" + path;
|
path = "scripts/" + path;
|
||||||
File scriptFile = new File(path);
|
Path scriptFile = Paths.get(path);
|
||||||
if (!scriptFile.exists()) {
|
if (!Files.exists(scriptFile)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +60,8 @@ public abstract class AbstractScriptManager {
|
|||||||
|
|
||||||
enableScriptHostAccess(graalScriptEngine);
|
enableScriptHostAccess(graalScriptEngine);
|
||||||
|
|
||||||
try (FileReader fr = new FileReader(scriptFile, CharsetConstants.CHARSET)) {
|
try (BufferedReader br = Files.newBufferedReader(scriptFile, CharsetConstants.CHARSET)) {
|
||||||
engine.eval(fr);
|
engine.eval(br);
|
||||||
} catch (final ScriptException | IOException t) {
|
} catch (final ScriptException | IOException t) {
|
||||||
log.warn("Exception during script eval for file: {}", path, t);
|
log.warn("Exception during script eval for file: {}", path, t);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user