From dc3362ba3c1dded62f8434d1418f0c6bbcc8ef17 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 15 Apr 2014 12:22:53 -0700 Subject: [PATCH] Removing deprecated methods --- .../main/java/org/eclipse/jetty/start/FS.java | 56 ------------------- .../org/eclipse/jetty/start/StartIni.java | 10 +--- .../org/eclipse/jetty/start/TextFile.java | 42 +++++++------- .../jetty/start/ConfigurationAssert.java | 2 +- .../java/org/eclipse/jetty/start/FSTest.java | 6 +- 5 files changed, 26 insertions(+), 90 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java index 29ee31def20..9b55b45c0ae 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java @@ -29,21 +29,11 @@ import java.util.Locale; public class FS { - public static boolean canReadDirectory(File path) - { - return (path.exists() && path.isDirectory() && path.canRead()); - } - public static boolean canReadDirectory(Path path) { return Files.exists(path) && Files.isDirectory(path) && Files.isReadable(path); } - public static boolean canReadFile(File path) - { - return (path.exists() && path.isFile() && path.canRead()); - } - public static boolean canReadFile(Path path) { return Files.exists(path) && Files.isRegularFile(path) && Files.isReadable(path); @@ -77,22 +67,6 @@ public class FS return Files.exists(ret); } - /** - * @deprecated use {@link #ensureDirectoryExists(Path)} instead - */ - @Deprecated - public static void ensureDirectoryExists(File dir) throws IOException - { - if (dir.exists()) - { - return; - } - if (!dir.mkdirs()) - { - throw new IOException("Unable to create directory: " + dir.getAbsolutePath()); - } - } - public static void ensureDirectoryExists(Path dir) throws IOException { if (exists(dir)) @@ -103,22 +77,6 @@ public class FS Files.createDirectories(dir); } - /** - * @deprecated use {@link #ensureDirectoryWritable(Path)} instead - */ - @Deprecated - public static void ensureDirectoryWritable(File dir) throws IOException - { - if (!dir.exists()) - { - throw new IOException("Directory does not exist: " + dir.getAbsolutePath()); - } - if (!dir.canWrite()) - { - throw new IOException("Unable to write to directory: " + dir.getAbsolutePath()); - } - } - public static void ensureDirectoryWritable(Path dir) throws IOException { if (!Files.exists(dir)) @@ -140,15 +98,6 @@ public class FS return Files.exists(path); } - public static boolean isFile(File file) - { - if (file == null) - { - return false; - } - return file.exists() && file.isFile(); - } - public static boolean isValidDirectory(Path path) { if (!Files.exists(path)) @@ -194,11 +143,6 @@ public class FS return FileSystems.getDefault().getPath(FS.separators(path)); } - public static String toRelativePath(File baseDir, File path) - { - return baseDir.toURI().relativize(path.toURI()).toASCIIString(); - } - public static void touch(Path path) throws IOException { FileTime now = FileTime.fromMillis(System.currentTimeMillis()); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java index 79b079cd712..524f958bd42 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java @@ -18,7 +18,6 @@ package org.eclipse.jetty.start; -import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -29,16 +28,11 @@ public class StartIni extends TextFile { private Path basedir; - public StartIni(File file) throws IOException + public StartIni(Path file) throws IOException { super(file); } - public StartIni(Path path) throws IOException - { - this(path.toFile()); - } - @Override public void addUniqueLine(String line) { @@ -70,7 +64,7 @@ public class StartIni extends TextFile @Override public void init() { - basedir = getFile().getParentFile().toPath().toAbsolutePath(); + basedir = getFile().getParent().toAbsolutePath(); } public Path getBaseDir() diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java index fccc76209a9..862422f94f7 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java @@ -19,10 +19,11 @@ package org.eclipse.jetty.start; import java.io.BufferedReader; -import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -36,40 +37,37 @@ import java.util.regex.Pattern; */ public class TextFile implements Iterable { - private final File file; + private final Path file; private final List lines = new ArrayList<>(); - public TextFile(File file) throws FileNotFoundException, IOException + public TextFile(Path file) throws FileNotFoundException, IOException { this.file = file; init(); if (!FS.canReadFile(file)) { - StartLog.debug("Skipping read of missing file: %s",file.getAbsolutePath()); + StartLog.debug("Skipping read of missing file: %s",file.toAbsolutePath()); return; } - try (FileReader reader = new FileReader(file)) + try (BufferedReader buf = Files.newBufferedReader(file,StandardCharsets.UTF_8)) { - try (BufferedReader buf = new BufferedReader(reader)) + String line; + while ((line = buf.readLine()) != null) { - String line; - while ((line = buf.readLine()) != null) + if (line.length() == 0) { - if (line.length() == 0) - { - continue; - } - - if (line.charAt(0) == '#') - { - continue; - } - - // TODO - bad form calling derived method from base class constructor - process(line.trim()); + continue; } + + if (line.charAt(0) == '#') + { + continue; + } + + // TODO - bad form calling derived method from base class constructor + process(line.trim()); } } } @@ -84,7 +82,7 @@ public class TextFile implements Iterable lines.add(line); } - public File getFile() + public Path getFile() { return file; } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java index 36c11743cb6..ced1889b5c8 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java @@ -53,7 +53,7 @@ public class ConfigurationAssert { File testResourcesDir = MavenTestingUtils.getTestResourcesDir(); File file = MavenTestingUtils.getTestResourceFile(filename); - TextFile textFile = new TextFile(file); + TextFile textFile = new TextFile(file.toPath()); // Validate XMLs (order is important) List expectedXmls = new ArrayList<>(); diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/FSTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/FSTest.java index e44fb5cbe65..4061851b187 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/FSTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/FSTest.java @@ -31,21 +31,21 @@ public class FSTest public void testCanReadDirectory() { File targetDir = MavenTestingUtils.getTargetDir(); - Assert.assertTrue("Can read dir: " + targetDir,FS.canReadDirectory(targetDir)); + Assert.assertTrue("Can read dir: " + targetDir,FS.canReadDirectory(targetDir.toPath())); } @Test public void testCanReadDirectory_NotDir() { File bogusFile = MavenTestingUtils.getTestResourceFile("bogus.xml"); - Assert.assertFalse("Can read dir: " + bogusFile,FS.canReadDirectory(bogusFile)); + Assert.assertFalse("Can read dir: " + bogusFile,FS.canReadDirectory(bogusFile.toPath())); } @Test public void testCanReadFile() { File pom = MavenTestingUtils.getProjectFile("pom.xml"); - Assert.assertTrue("Can read file: " + pom,FS.canReadFile(pom)); + Assert.assertTrue("Can read file: " + pom,FS.canReadFile(pom.toPath())); } /**