8253799: Make lists of normal filenames

Reviewed-by: alanb, rhalade
This commit is contained in:
Brian Burkhalter 2020-10-28 00:21:29 +00:00 committed by Henry Jen
parent 7232e3c704
commit 4471789aca

View file

@ -500,6 +500,9 @@ public class File
public File getParentFile() {
String p = this.getParent();
if (p == null) return null;
if (getClass() != File.class) {
p = fs.normalize(p);
}
return new File(p, this.prefixLength);
}
@ -572,6 +575,9 @@ public class File
*/
public File getAbsoluteFile() {
String absPath = getAbsolutePath();
if (getClass() != File.class) {
absPath = fs.normalize(absPath);
}
return new File(absPath, fs.prefixLength(absPath));
}
@ -643,6 +649,9 @@ public class File
*/
public File getCanonicalFile() throws IOException {
String canonPath = getCanonicalPath();
if (getClass() != File.class) {
canonPath = fs.normalize(canonPath);
}
return new File(canonPath, fs.prefixLength(canonPath));
}
@ -1135,6 +1144,34 @@ public class File
return fs.list(this);
}
/**
* Returns an array of strings naming the files and directories in the
* directory denoted by this abstract pathname. The strings are
* ensured to represent normalized paths.
*
* @return An array of strings naming the files and directories in the
* directory denoted by this abstract pathname. The array will be
* empty if the directory is empty. Returns {@code null} if
* this abstract pathname does not denote a directory, or if an
* I/O error occurs.
*
* @throws SecurityException
* If a security manager exists and its {@link
* SecurityManager#checkRead(String)} method denies read access to
* the directory
*/
private final String[] normalizedList() {
String[] s = list();
if (getClass() != File.class) {
String[] normalized = new String[s.length];
for (int i = 0; i < s.length; i++) {
normalized[i] = fs.normalize(s[i]);
}
s = normalized;
}
return s;
}
/**
* Returns an array of strings naming the files and directories in the
* directory denoted by this abstract pathname that satisfy the specified
@ -1165,7 +1202,7 @@ public class File
* @see java.nio.file.Files#newDirectoryStream(Path,String)
*/
public String[] list(FilenameFilter filter) {
String names[] = list();
String names[] = normalizedList();
if ((names == null) || (filter == null)) {
return names;
}
@ -1217,7 +1254,7 @@ public class File
* @since 1.2
*/
public File[] listFiles() {
String[] ss = list();
String[] ss = normalizedList();
if (ss == null) return null;
int n = ss.length;
File[] fs = new File[n];
@ -1258,7 +1295,7 @@ public class File
* @see java.nio.file.Files#newDirectoryStream(Path,String)
*/
public File[] listFiles(FilenameFilter filter) {
String ss[] = list();
String ss[] = normalizedList();
if (ss == null) return null;
ArrayList<File> files = new ArrayList<>();
for (String s : ss)
@ -1296,7 +1333,7 @@ public class File
* @see java.nio.file.Files#newDirectoryStream(Path,java.nio.file.DirectoryStream.Filter)
*/
public File[] listFiles(FileFilter filter) {
String ss[] = list();
String ss[] = normalizedList();
if (ss == null) return null;
ArrayList<File> files = new ArrayList<>();
for (String s : ss) {