Fix whitespace [skip actions]

This commit is contained in:
github-actions
2022-10-13 13:32:10 +00:00
parent d1d39db56c
commit 025e5d3c1c
16 changed files with 481 additions and 481 deletions

View File

@@ -111,93 +111,93 @@ public final class FileUtils {
return SCRIPTS_PATH.resolve(path);
}
public static void write(String dest, byte[] bytes) {
Path path = Path.of(dest);
try {
Files.write(path, bytes);
} catch (IOException e) {
Grasscutter.getLogger().warn("Failed to write file: " + dest);
}
}
public static byte[] read(String dest) {
return read(Path.of(dest));
}
public static void write(String dest, byte[] bytes) {
Path path = Path.of(dest);
public static byte[] read(Path path) {
try {
return Files.readAllBytes(path);
} catch (IOException e) {
Grasscutter.getLogger().warn("Failed to read file: " + path);
}
return new byte[0];
}
try {
Files.write(path, bytes);
} catch (IOException e) {
Grasscutter.getLogger().warn("Failed to write file: " + dest);
}
}
public static InputStream readResourceAsStream(String resourcePath) {
return Grasscutter.class.getResourceAsStream(resourcePath);
}
public static byte[] read(String dest) {
return read(Path.of(dest));
}
public static byte[] readResource(String resourcePath) {
try (InputStream is = Grasscutter.class.getResourceAsStream(resourcePath)) {
return is.readAllBytes();
} catch (Exception exception) {
Grasscutter.getLogger().warn("Failed to read resource: " + resourcePath);
exception.printStackTrace();
}
public static byte[] read(Path path) {
try {
return Files.readAllBytes(path);
} catch (IOException e) {
Grasscutter.getLogger().warn("Failed to read file: " + path);
}
return new byte[0];
}
public static byte[] read(File file) {
return read(file.getPath());
}
return new byte[0];
}
public static void copyResource(String resourcePath, String destination) {
try {
byte[] resource = FileUtils.readResource(resourcePath);
FileUtils.write(destination, resource);
} catch (Exception exception) {
Grasscutter.getLogger().warn("Failed to copy resource: " + resourcePath + "\n" + exception);
}
}
public static String getFilenameWithoutPath(String fileName) {
if (fileName.indexOf(".") > 0) {
return fileName.substring(0, fileName.lastIndexOf("."));
} else {
return fileName;
}
}
public static InputStream readResourceAsStream(String resourcePath) {
return Grasscutter.class.getResourceAsStream(resourcePath);
}
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
public static List<Path> getPathsFromResource(String folder) throws URISyntaxException {
List<Path> result = null;
public static byte[] readResource(String resourcePath) {
try (InputStream is = Grasscutter.class.getResourceAsStream(resourcePath)) {
return is.readAllBytes();
} catch (Exception exception) {
Grasscutter.getLogger().warn("Failed to read resource: " + resourcePath);
exception.printStackTrace();
}
try {
// file walks JAR
result = Files.walk(JAR_FILE_SYSTEM.getPath(folder))
.filter(Files::isRegularFile)
.collect(Collectors.toList());
} catch (Exception e) {
// Eclipse puts resources in its bin folder
File f = new File(System.getProperty("user.dir") + folder);
if (!f.exists() || f.listFiles().length == 0) {
return null;
}
result = Arrays.stream(f.listFiles()).map(File::toPath).toList();
}
return result;
}
return new byte[0];
}
@SuppressWarnings("ResultOfMethodCallIgnored")
public static String readToString(InputStream file) throws IOException {
byte[] content = file.readAllBytes();
public static byte[] read(File file) {
return read(file.getPath());
}
return new String(content, StandardCharsets.UTF_8);
}
public static void copyResource(String resourcePath, String destination) {
try {
byte[] resource = FileUtils.readResource(resourcePath);
FileUtils.write(destination, resource);
} catch (Exception exception) {
Grasscutter.getLogger().warn("Failed to copy resource: " + resourcePath + "\n" + exception);
}
}
public static String getFilenameWithoutPath(String fileName) {
if (fileName.indexOf(".") > 0) {
return fileName.substring(0, fileName.lastIndexOf("."));
} else {
return fileName;
}
}
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
public static List<Path> getPathsFromResource(String folder) throws URISyntaxException {
List<Path> result = null;
try {
// file walks JAR
result = Files.walk(JAR_FILE_SYSTEM.getPath(folder))
.filter(Files::isRegularFile)
.collect(Collectors.toList());
} catch (Exception e) {
// Eclipse puts resources in its bin folder
File f = new File(System.getProperty("user.dir") + folder);
if (!f.exists() || f.listFiles().length == 0) {
return null;
}
result = Arrays.stream(f.listFiles()).map(File::toPath).toList();
}
return result;
}
@SuppressWarnings("ResultOfMethodCallIgnored")
public static String readToString(InputStream file) throws IOException {
byte[] content = file.readAllBytes();
return new String(content, StandardCharsets.UTF_8);
}
}