Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow loading included schemas on the class-path
- Loading branch information
Showing
4 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/io/xlate/edi/internal/schema/ClasspathURLStreamHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.xlate.edi.internal.schema; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.net.URLStreamHandler; | ||
|
||
class ClasspathURLStreamHandler extends URLStreamHandler { | ||
/** The classloader to find resources from. */ | ||
private final ClassLoader classLoader; | ||
|
||
public ClasspathURLStreamHandler(ClassLoader classLoader) { | ||
this.classLoader = classLoader; | ||
} | ||
|
||
@Override | ||
protected URLConnection openConnection(URL u) throws IOException { | ||
final String resourcePath = u.getPath(); | ||
final URL resourceUrl = classLoader.getResource(resourcePath); | ||
|
||
if (resourceUrl == null) { | ||
throw new FileNotFoundException("Class-path resource not found: " + resourcePath); | ||
} | ||
|
||
return resourceUrl.openConnection(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters