From d3ea113a92439aacd69d61445dbfcf8b14e483a3 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Fri, 10 Jun 2011 12:02:13 +0000 Subject: [PATCH] try multiple classloaders when trying to load resources git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@564 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 5 +++++ .../jackcess/Database.java | 22 +++++++++++++++++-- .../jackcess/GeneralLegacyIndexCodes.java | 3 +-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 882fc2e..39758a1 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -4,6 +4,11 @@ Tim McCune + + + Try multiple classloaders when loading resources as streams. + + Refactor table loading to use indexes. Do not load all table names at diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 96d7aaa..a856b02 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -657,8 +657,7 @@ public class Database FileChannel channel = openChannel(mdbFile, false); channel.truncate(0); - transferFrom(channel, Thread.currentThread().getContextClassLoader() - .getResourceAsStream(fileFormat._emptyFile)); + transferFrom(channel, getResourceAsStream(fileFormat._emptyFile)); return new Database(channel, autoSync, fileFormat, charset, timeZone, null); } @@ -1911,6 +1910,25 @@ public class Database return pwdMask; } + static InputStream getResourceAsStream(String resourceName) + throws IOException + { + InputStream stream = Database.class.getClassLoader() + .getResourceAsStream(resourceName); + + if(stream == null) { + + stream = Thread.currentThread().getContextClassLoader() + .getResourceAsStream(resourceName); + + if(stream == null) { + throw new IOException("Could not load jackcess resource " + + resourceName); + } + } + + return stream; + } /** * Utility class for storing table page number and actual name. diff --git a/src/java/com/healthmarketscience/jackcess/GeneralLegacyIndexCodes.java b/src/java/com/healthmarketscience/jackcess/GeneralLegacyIndexCodes.java index 6206ba2..e6d204c 100644 --- a/src/java/com/healthmarketscience/jackcess/GeneralLegacyIndexCodes.java +++ b/src/java/com/healthmarketscience/jackcess/GeneralLegacyIndexCodes.java @@ -326,8 +326,7 @@ public class GeneralLegacyIndexCodes { reader = new BufferedReader( new InputStreamReader( - Thread.currentThread().getContextClassLoader() - .getResourceAsStream(codesFilePath), "US-ASCII")); + Database.getResourceAsStream(codesFilePath), "US-ASCII")); int start = asUnsignedChar(firstChar); int end = asUnsignedChar(lastChar); -- 2.39.5