Skip to content

Commit 6556a15

Browse files
committed
Android FileUtils fix for null path when listing files
1 parent a1b7d17 commit 6556a15

File tree

1 file changed

+10
-6
lines changed
  • graphics-by-opengl-j2se/src/main/java/com/nucleus/common

1 file changed

+10
-6
lines changed

graphics-by-opengl-j2se/src/main/java/com/nucleus/common/FileUtils.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.nio.file.Paths;
1515
import java.util.ArrayList;
1616
import java.util.Collections;
17+
import java.util.Enumeration;
1718
import java.util.List;
1819
import java.util.stream.Collectors;
1920
import java.util.stream.Stream;
@@ -46,15 +47,15 @@ public static FileUtils getInstance() {
4647
return fileUtils;
4748
}
4849

49-
protected Path getFileSystemPath(String path) throws URISyntaxException, IOException {
50+
protected Path getFileSystemPath(String path) throws URISyntaxException, IOException{
5051
ClassLoader loader = getClass().getClassLoader();
5152
SimpleLogger.d(getClass(), "Getting URI for path: " + path);
52-
URI uri = loader.getResource(path).toURI();
53-
Path resultPath = null;
54-
if (uri.getScheme().contentEquals("jar")) {
55-
resultPath = getJarPath(uri, path);
53+
URL url = loader.getResource(path);
54+
if (url == null) {
55+
return null;
5656
}
57-
resultPath = Paths.get(uri);
57+
URI uri = url.toURI();
58+
Path resultPath = Paths.get(uri);
5859
SimpleLogger.d(getClass(), "Path for uri: " + uri + "\n" + resultPath.toString());
5960
return resultPath;
6061
}
@@ -78,6 +79,9 @@ public ArrayList<String> listResourceFolders(String path) throws IOException, UR
7879
String separator = "" + FileUtils.DIRECTORY_SEPARATOR;
7980
ArrayList<String> folders = new ArrayList<String>();
8081
Path listPath = getFileSystemPath(path);
82+
if (listPath == null) {
83+
return folders;
84+
}
8185
String listPathStr = listPath.toString();
8286
SimpleLogger.d(getClass(), "Listing folders in " + listPathStr);
8387
int offset = listPathStr.endsWith(separator) ? 0 : 1;

0 commit comments

Comments
 (0)