private XPathFactory loadFromServicesFile(String uri,String resourceName,InputStream in){
  if (debug)   debugPrintln("Reading " + resourceName);
  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;
  XPathFactory resultFactory=null;
  while (true) {
    try {
      factoryClassName=rd.readLine();
    }
 catch (    IOException x) {
      break;
    }
    if (factoryClassName != null) {
      int hashIndex=factoryClassName.indexOf('#');
      if (hashIndex != -1) {
        factoryClassName=factoryClassName.substring(0,hashIndex);
      }
      factoryClassName=factoryClassName.trim();
      if (factoryClassName.length() == 0) {
        continue;
      }
      try {
        XPathFactory foundFactory=createInstance(factoryClassName);
        if (foundFactory.isObjectModelSupported(uri)) {
          resultFactory=foundFactory;
          break;
        }
      }
 catch (      Exception ignored) {
      }
    }
 else {
      break;
    }
  }
  IoUtils.closeQuietly(rd);
  return resultFactory;
}

private XPathFactory loadFromServicesFile ( String uri , String resourceName , InputStream in ) { if ( debug ) debugPrintln ( "Reading " + resourceName ) ; 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 ; XPathFactory resultFactory = null ; while ( true ) { try { factoryClassName = rd . readLine ( ) ; } catch ( IOException x ) { break ; } if ( factoryClassName != null ) { int hashIndex = factoryClassName . indexOf ( '#' ) ; if ( hashIndex != - 1 ) { factoryClassName = factoryClassName . substring ( 0 , hashIndex ) ; } factoryClassName = factoryClassName . trim ( ) ; if ( factoryClassName . length ( ) == 0 ) { continue ; } try { XPathFactory foundFactory = createInstance ( factoryClassName ) ; if ( foundFactory . isObjectModelSupported ( uri ) ) { resultFactory = foundFactory ; break ; } } catch ( Exception ignored ) { } } else { break ; } } IoUtils . closeQuietly ( rd ) ; return resultFactory ; }
searches for a xpathfactory for a given uri in a meta - inf / services file .
