提交 b53221d0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Reading a resource from the classpath didn't work if there was a leading slash…

Reading a resource from the classpath didn't work if there was a leading slash (classpath:/org/...). Now resources can be loaded with or without leading slash.
上级 753aa65c
......@@ -366,7 +366,10 @@ public class FileSystemDisk extends FileSystem {
// if the : is in position 1, a windows file access is assumed: C:.. or D:
if (fileName.startsWith(CLASSPATH_PREFIX)) {
fileName = fileName.substring(CLASSPATH_PREFIX.length());
InputStream in = getClass().getClassLoader().getResourceAsStream(fileName);
if (!fileName.startsWith("/")) {
fileName = "/" + fileName;
}
InputStream in = getClass().getResourceAsStream(fileName);
if (in == null) {
throw new FileNotFoundException("resource " + fileName);
}
......
......@@ -44,6 +44,7 @@ public class TestFileSystem extends TestBase {
}
public void test() throws Exception {
testClasspath();
FileSystemCrypt.register();
// DebugFileSystem.register().setTrace(true);
// testFileSystem("crypt:aes:x:" + getBaseDir() + "/fs");
......@@ -82,6 +83,23 @@ public class TestFileSystem extends TestBase {
}
}
private void testClasspath() throws IOException {
String resource = "org/h2/test/testSimple.in.txt";
InputStream in;
in = getClass().getResourceAsStream("/" + resource);
assertTrue(in != null);
in.close();
in = getClass().getClassLoader().getResourceAsStream(resource);
assertTrue(in != null);
in.close();
in = IOUtils.openFileInputStream("classpath:" + resource);
assertTrue(in != null);
in.close();
in = IOUtils.openFileInputStream("classpath:/" + resource);
assertTrue(in != null);
in.close();
}
private void testSplitDatabaseInZip() throws SQLException {
String dir = getBaseDir() + "/fs";
IOUtils.deleteRecursive(dir, false);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论