FS utility class cleanup of unused code

This commit is contained in:
Joakim Erdfelt 2014-04-15 10:31:27 -07:00
parent db2c6c20b9
commit 599595f544
1 changed files with 9 additions and 126 deletions

View File

@ -20,131 +20,15 @@ package org.eclipse.jetty.start;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.FileFilter;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.attribute.FileTime; import java.nio.file.attribute.FileTime;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Pattern;
public class FS public class FS
{ {
@Deprecated
public static class AllFilter implements FileFilter
{
public static final AllFilter INSTANCE = new AllFilter();
@Override
public boolean accept(File pathname)
{
return true;
}
}
@Deprecated
public static class DirFilter implements FileFilter
{
public static final DirFilter INSTANCE = new DirFilter();
@Override
public boolean accept(File path)
{
return path.isDirectory();
}
}
@Deprecated
public static class FilenameRegexFilter implements FileFilter
{
private final Pattern pattern;
public FilenameRegexFilter(String regex)
{
pattern = Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
}
@Override
public boolean accept(File path)
{
return path.isFile() && pattern.matcher(path.getName()).matches();
}
}
@Deprecated
public static class FileNamesFilter implements FileFilter
{
private final String filenames[];
public FileNamesFilter(String... names)
{
this.filenames = names;
}
@Override
public boolean accept(File path)
{
if (!path.isFile())
{
return false;
}
for (String name : filenames)
{
if (name.equalsIgnoreCase(path.getName()))
{
return true;
}
}
return false;
}
}
@Deprecated
public static class IniFilter extends FilenameRegexFilter
{
public IniFilter()
{
super("^.*\\.ini$");
}
}
@Deprecated
public static class RelativeRegexFilter implements FileFilter
{
private final File baseDir;
private final Pattern pattern;
public RelativeRegexFilter(File baseDir, Pattern pattern)
{
this.baseDir = baseDir;
this.pattern = pattern;
}
@Override
public boolean accept(File path)
{
// get relative path
String relativePath = FS.toRelativePath(baseDir,path);
// see if it matches
return (pattern.matcher(relativePath).matches());
}
}
@Deprecated
public static class XmlFilter extends FilenameRegexFilter
{
public XmlFilter()
{
super("^.*\\.xml$");
}
}
// Default Link Options
private static final LinkOption[] NO_LINK_OPTIONS = new LinkOption[0];
public static boolean canReadDirectory(File path) public static boolean canReadDirectory(File path)
{ {
return (path.exists() && path.isDirectory() && path.canRead()); return (path.exists() && path.isDirectory() && path.canRead());
@ -152,7 +36,7 @@ public class FS
public static boolean canReadDirectory(Path path) public static boolean canReadDirectory(Path path)
{ {
return Files.exists(path,NO_LINK_OPTIONS) && Files.isDirectory(path,NO_LINK_OPTIONS) && Files.isReadable(path); return Files.exists(path) && Files.isDirectory(path) && Files.isReadable(path);
} }
public static boolean canReadFile(File path) public static boolean canReadFile(File path)
@ -162,7 +46,7 @@ public class FS
public static boolean canReadFile(Path path) public static boolean canReadFile(Path path)
{ {
return Files.exists(path,NO_LINK_OPTIONS) && Files.isRegularFile(path,NO_LINK_OPTIONS) && Files.isReadable(path); return Files.exists(path) && Files.isRegularFile(path) && Files.isReadable(path);
} }
public static boolean canWrite(Path path) public static boolean canWrite(Path path)
@ -190,7 +74,7 @@ public class FS
public static boolean createNewFile(Path path) throws IOException public static boolean createNewFile(Path path) throws IOException
{ {
Path ret = Files.createFile(path); Path ret = Files.createFile(path);
return Files.exists(ret,NO_LINK_OPTIONS); return Files.exists(ret);
} }
/** /**
@ -237,11 +121,11 @@ public class FS
public static void ensureDirectoryWritable(Path dir) throws IOException public static void ensureDirectoryWritable(Path dir) throws IOException
{ {
if (!Files.exists(dir,NO_LINK_OPTIONS)) if (!Files.exists(dir))
{ {
throw new IOException("Path does not exist: " + dir.toAbsolutePath()); throw new IOException("Path does not exist: " + dir.toAbsolutePath());
} }
if (!Files.isDirectory(dir,NO_LINK_OPTIONS)) if (!Files.isDirectory(dir))
{ {
throw new IOException("Directory does not exist: " + dir.toAbsolutePath()); throw new IOException("Directory does not exist: " + dir.toAbsolutePath());
} }
@ -253,7 +137,7 @@ public class FS
public static boolean exists(Path path) public static boolean exists(Path path)
{ {
return Files.exists(path,NO_LINK_OPTIONS); return Files.exists(path);
} }
public static boolean isFile(File file) public static boolean isFile(File file)
@ -267,14 +151,13 @@ public class FS
public static boolean isValidDirectory(Path path) public static boolean isValidDirectory(Path path)
{ {
LinkOption lopts[] = NO_LINK_OPTIONS; if (!Files.exists(path))
if (!Files.exists(path,lopts))
{ {
// doesn't exist, not a valid directory // doesn't exist, not a valid directory
return false; return false;
} }
if (!Files.isDirectory(path,lopts)) if (!Files.isDirectory(path))
{ {
// not a directory (as expected) // not a directory (as expected)
StartLog.warn("Not a directory: " + path); StartLog.warn("Not a directory: " + path);
@ -324,6 +207,6 @@ public class FS
public static Path toRealPath(Path path) throws IOException public static Path toRealPath(Path path) throws IOException
{ {
return path.toRealPath(NO_LINK_OPTIONS); return path.toRealPath();
} }
} }