step2用到的方法
private static String getImplNameFromServices(ClassLoader classLoader,
String factoryName) { // Check for a services definition
String result = null;
BufferedReader reader = null;
String resourceName = "META-INF/services/" + factoryName;
Properties props = null;
InputStream stream = null;
try {
stream = classLoader.getResourceAsStream(resourceName);
if (stream != null) {
// Deal with systems whose native encoding is possibly
// different from the way that the services entry was created
try {
reader =
new BufferedReader(new InputStreamReader(stream,
"UTF-8"));
} catch (UnsupportedEncodingException e) {
reader = new BufferedReader(new InputStreamReader(stream));
}
result = reader.readLine();
reader.close();
reader = null;
stream = null;
}
} catch (IOException e) {
} catch (SecurityException e) {
} finally {
if (reader != null) {
try {
reader.close();
} catch (Throwable t) {
;
}
reader = null;
stream = null;
}
if (stream != null) {
try {
stream.close();
} catch (Throwable t) {
;
}
stream = null;
}
}
return result;
}
我找了很久String resourceName = "META-INF/services/" + factoryName;找不到,这个我觉得应该是通过子类来实例化工厂。
private static String getImplNameFromServices(ClassLoader classLoader,
String factoryName) { // Check for a services definition
String result = null;
BufferedReader reader = null;
String resourceName = "META-INF/services/" + factoryName;
Properties props = null;
InputStream stream = null;
try {
stream = classLoader.getResourceAsStream(resourceName);
if (stream != null) {
// Deal with systems whose native encoding is possibly
// different from the way that the services entry was created
try {
reader =
new BufferedReader(new InputStreamReader(stream,
"UTF-8"));
} catch (UnsupportedEncodingException e) {
reader = new BufferedReader(new InputStreamReader(stream));
}
result = reader.readLine();
reader.close();
reader = null;
stream = null;
}
} catch (IOException e) {
} catch (SecurityException e) {
} finally {
if (reader != null) {
try {
reader.close();
} catch (Throwable t) {
;
}
reader = null;
stream = null;
}
if (stream != null) {
try {
stream.close();
} catch (Throwable t) {
;
}
stream = null;
}
}
return result;
}
我找了很久String resourceName = "META-INF/services/" + factoryName;找不到,这个我觉得应该是通过子类来实例化工厂。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货