|
24 | 24 |
|
25 | 25 | import java.io.File; |
26 | 26 | import java.io.IOException; |
| 27 | +import java.net.URI; |
| 28 | +import java.net.URISyntaxException; |
27 | 29 | import java.net.URL; |
28 | 30 | import java.util.*; |
29 | 31 | import java.util.regex.Matcher; |
@@ -73,26 +75,33 @@ private static void getResources( |
73 | 75 | final String protocol = containerUrl.getProtocol(); |
74 | 76 | switch (protocol) { |
75 | 77 | case "file": |
76 | | - final File fileContainer = new File(containerUrl.getPath()); |
77 | | - Preconditions.checkState( |
78 | | - fileContainer.exists() && fileContainer.isDirectory(), |
79 | | - "Specified file container " + containerUrl + " is not a directory or not a file"); |
80 | | - getResourcesFromDirectory(fileContainer, fileContainer, pattern, buffer); |
| 78 | + try { |
| 79 | + final File fileContainer = new File(containerUrl.toURI()); |
| 80 | + Preconditions.checkState( |
| 81 | + fileContainer.exists() && fileContainer.isDirectory(), |
| 82 | + "Specified file container " + containerUrl + " is not a directory or not a file"); |
| 83 | + getResourcesFromDirectory(fileContainer, fileContainer, pattern, buffer); |
| 84 | + } catch (URISyntaxException e) { |
| 85 | + throw new GlutenException(e); |
| 86 | + } |
81 | 87 | break; |
82 | 88 | case "jar": |
83 | | - final String jarContainerPath = containerUrl.getPath(); |
84 | | - final Pattern jarContainerPattern = Pattern.compile("file:([^!]+)!/(.+)"); |
85 | | - final Matcher m = jarContainerPattern.matcher(jarContainerPath); |
86 | | - if (!m.matches()) { |
87 | | - throw new GlutenException("Illegal Jar container URL: " + containerUrl); |
| 89 | + try { |
| 90 | + final String jarContainerPath = containerUrl.getPath(); |
| 91 | + final Pattern jarContainerPattern = Pattern.compile("file:([^!]+)!/(.+)"); |
| 92 | + final Matcher m = jarContainerPattern.matcher(jarContainerPath); |
| 93 | + if (!m.matches()) { |
| 94 | + throw new GlutenException("Illegal Jar container URL: " + containerUrl); |
| 95 | + } |
| 96 | + final File jarFile = new File(new URI("file://" + m.group(1))); |
| 97 | + Preconditions.checkState( |
| 98 | + jarFile.exists() && jarFile.isFile(), |
| 99 | + "Specified Jar container " + containerUrl + " is not a Jar file"); |
| 100 | + final String dir = m.group(2); |
| 101 | + getResourcesFromJarFile(jarFile, dir, pattern, buffer); |
| 102 | + } catch (URISyntaxException e) { |
| 103 | + throw new GlutenException(e); |
88 | 104 | } |
89 | | - final String jarPath = m.group(1); |
90 | | - final File jarFile = new File(jarPath); |
91 | | - Preconditions.checkState( |
92 | | - jarFile.exists() && jarFile.isFile(), |
93 | | - "Specified Jar container " + containerUrl + " is not a Jar file"); |
94 | | - final String dir = m.group(2); |
95 | | - getResourcesFromJarFile(jarFile, dir, pattern, buffer); |
96 | 105 | break; |
97 | 106 | default: |
98 | 107 | throw new GlutenException("Unrecognizable resource protocol: " + protocol); |
|
0 commit comments