mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor loadClass
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user