aboutsummaryrefslogtreecommitdiffstats
path: root/pf4j
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2017-07-28 23:42:17 +0300
committerDecebal Suiu <decebal.suiu@gmail.com>2017-07-28 23:42:17 +0300
commitf5f5587e96e2e952793bc589632077c790dd084a (patch)
tree15703c7ddb60624b5a7015ec0ef73de8f1c92e47 /pf4j
parent6e15379429bf23fd1d0ecc674944d09907ed0890 (diff)
downloadpf4j-f5f5587e96e2e952793bc589632077c790dd084a.tar.gz
pf4j-f5f5587e96e2e952793bc589632077c790dd084a.zip
Update some code to Java 7
Diffstat (limited to 'pf4j')
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginStatusProvider.java4
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java38
2 files changed, 14 insertions, 28 deletions
diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginStatusProvider.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginStatusProvider.java
index f5cb514..2c669b1 100644
--- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginStatusProvider.java
+++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginStatusProvider.java
@@ -47,11 +47,11 @@ public class DefaultPluginStatusProvider implements PluginStatusProvider {
private void initialize() {
try {
// create a list with plugin identifiers that should be only accepted by this manager (whitelist from plugins/enabled.txt file)
- enabledPlugins = FileUtils.readLines(pluginsRoot.resolve("enabled.txt").toFile(), true);
+ enabledPlugins = FileUtils.readLines(pluginsRoot.resolve("enabled.txt"), true);
log.info("Enabled plugins: {}", enabledPlugins);
// create a list with plugin identifiers that should not be accepted by this manager (blacklist from plugins/disabled.txt file)
- disabledPlugins = FileUtils.readLines(pluginsRoot.resolve("disabled.txt").toFile(), true);
+ disabledPlugins = FileUtils.readLines(pluginsRoot.resolve("disabled.txt"), true);
log.info("Disabled plugins: {}", disabledPlugins);
} catch (IOException e) {
log.error(e.getMessage(), e);
diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java b/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java
index 550243a..6ce7f42 100644
--- a/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java
+++ b/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java
@@ -19,12 +19,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
-import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -42,44 +41,28 @@ public class FileUtils {
private static final Logger log = LoggerFactory.getLogger(FileUtils.class);
- public static List<String> readLines(File file, boolean ignoreComments) throws IOException {
+ public static List<String> readLines(Path path, boolean ignoreComments) throws IOException {
+ File file = path.toFile();
if (!file.exists() || !file.isFile()) {
return new ArrayList<>();
}
List<String> lines = new ArrayList<>();
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new FileReader(file));
+ try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
if (ignoreComments && !line.startsWith("#") && !lines.contains(line)) {
lines.add(line);
}
}
- } finally {
- if (reader != null) {
- reader.close();
- }
}
return lines;
}
public static void writeLines(Collection<String> lines, File file) throws IOException {
- BufferedWriter writer = null;
- try {
- writer = new BufferedWriter(new FileWriter(file));
- for (String line : lines) {
- writer.write(line);
- writer.newLine();
- }
- } finally {
- if (writer != null) {
- writer.close();
- }
- }
+ Files.write(file.toPath(), lines, StandardCharsets.UTF_8);
}
/**
@@ -136,7 +119,8 @@ public class FileUtils {
}
/**
- * Finds a path with various endings or null if not found
+ * Finds a path with various endings or null if not found.
+ *
* @param basePath the base name
* @param endings a list of endings to search for
* @return new path or null if not found
@@ -153,7 +137,8 @@ public class FileUtils {
}
/**
- * Delete a file (not recursively) and ignore any errors
+ * Delete a file (not recursively) and ignore any errors.
+ *
* @param path the path to delete
*/
public static void optimisticDelete(Path path) {
@@ -205,9 +190,10 @@ public class FileUtils {
}
/**
- * Return true only if path is a zip file
+ * Return true only if path is a zip file.
+ *
* @param path to a file/dir
- * @return true if file with .zip ending
+ * @return true if file with {@code .zip} ending
*/
public static boolean isZipFile(Path path) {
return Files.isRegularFile(path) && path.toString().toLowerCase().endsWith(".zip");