refactor loadClass

This commit is contained in:
wenshao
2012-07-19 10:59:54 +08:00
parent 3ee01ce1a2
commit 92b106565b
8 changed files with 37 additions and 256 deletions
@@ -136,28 +136,17 @@ public class DruidLoaderUtils {
try {
clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
LOG.error("load class error", e);
}
if (clazz == null) {
loadClass2(className);
}
return clazz;
}
public static Class<?> loadClass2(String className) {
if (className == null) {
return null;
if (clazz != null) {
return clazz;
}
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
// skip
return null;
}
return null;
}
}
@@ -16,6 +16,21 @@ public class IOUtils {
InputStreamReader reader = new InputStreamReader(in);
return read(reader);
}
public static String readFromResource(String resource) throws IOException {
InputStream in = null;
try {
in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
if (in == null) {
return null;
}
String text = IOUtils.read(in);
return text;
} finally {
JdbcUtils.close(in);
}
}
public static String read(Reader reader) {
try {