in jaxp-api-1.3/src/main/java/javax/xml/validation/SchemaFactoryFinder.java [363:438]
private SchemaFactory loadFromServicesFile(String schemaLanguage, String resourceName, InputStream in) {
if (debug) debugPrintln("Reading "+resourceName );
// Read the service provider name in UTF-8 as specified in
// the jar spec. Unfortunately this fails in Microsoft
// VJ++, which does not implement the UTF-8
// encoding. Theoretically, we should simply let it fail in
// that case, since the JVM is obviously broken if it
// doesn't support such a basic standard. But since there
// are still some users attempting to use VJ++ for
// development, we have dropped in a fallback which makes a
// second attempt using the platform's default encoding. In
// VJ++ this is apparently ASCII, which is a subset of
// UTF-8... and since the strings we'll be reading here are
// also primarily limited to the 7-bit ASCII range (at
// least, in English versions), this should work well
// enough to keep us on the air until we're ready to
// officially decommit from VJ++. [Edited comment from
// jkesselm]
BufferedReader rd;
try {
rd = new BufferedReader(new InputStreamReader(in, "UTF-8"), DEFAULT_LINE_LENGTH);
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(in), DEFAULT_LINE_LENGTH);
}
String factoryClassName = null;
SchemaFactory resultFactory = null;
// See spec for provider-configuration files: http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Provider%20Configuration%20File
while (true) {
try {
factoryClassName = rd.readLine();
} catch (IOException x) {
// No provider found
break;
}
if (factoryClassName != null) {
// Ignore comments in the provider-configuration file
int hashIndex = factoryClassName.indexOf('#');
if (hashIndex != -1) {
factoryClassName = factoryClassName.substring(0, hashIndex);
}
// Ignore leading and trailing whitespace
factoryClassName = factoryClassName.trim();
// If there's no text left or if this was a blank line, go to the next one.
if (factoryClassName.length() == 0) {
continue;
}
try {
// Found the right SchemaFactory if its isSchemaLanguageSupported(schemaLanguage) method returns true.
SchemaFactory foundFactory = (SchemaFactory) createInstance(factoryClassName);
if (foundFactory.isSchemaLanguageSupported(schemaLanguage)) {
resultFactory = foundFactory;
break;
}
}
catch (Exception e) {}
}
else {
break;
}
}
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
return resultFactory;
}