Skip to content

Commit

Permalink
Modifications to handle os-independent file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-baumgartner committed Feb 7, 2018
1 parent 663a6d1 commit 1be175e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/edu/ucdenver/ccp/common/io/ClassPathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public static File copyClasspathResourceToFile(String resourcePath, File file) t
if (stream == null) {
String modifiedPath;
logger.warn("Invalid resource path on classpath: " + resourcePath);
if (resourcePath.startsWith("/")) {
if (resourcePath.startsWith(File.separator)) {
modifiedPath = resourcePath.substring(1);
} else {
modifiedPath = "/" + resourcePath;
modifiedPath = File.separator + resourcePath;
}
logger.warn("Trying path variant: " + modifiedPath);
stream = ClassPathUtil.class.getResourceAsStream(modifiedPath);
Expand All @@ -152,7 +152,7 @@ public static File copyClasspathResourceToDirectory(Class<?> clazz, String resou
}

public static File copyClasspathResourceToDirectory(String resourcePath, File directory) throws IOException {
String resourceName = resourcePath.substring(resourcePath.lastIndexOf(StringConstants.FORWARD_SLASH) + 1);
String resourceName = resourcePath.substring(resourcePath.lastIndexOf(File.separator) + 1);
return copyClasspathResourceToFile(resourcePath, new File(directory, resourceName));
}

Expand Down Expand Up @@ -204,7 +204,7 @@ public static List<String> listResourceDirectory(Class<?> clazz, String resource
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
String name = entries.nextElement().getName();
if (name.startsWith(resourceName) && !name.endsWith("/")) {
if (name.startsWith(resourceName) && !name.endsWith(File.separator)) {
logger.debug("ClassPathUtil adding from jar:" + name);
resourceNames.add(name);
}
Expand Down

0 comments on commit 1be175e

Please sign in to comment.