mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8253799: Make lists of normal filenames
Reviewed-by: alanb, rhalade
This commit is contained in:
parent
7232e3c704
commit
4471789aca
1 changed files with 41 additions and 4 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue