加载设置文件

@param urlResource 配置文件URL
@return 加载是否成功
766417
public boolean load(UrlResource urlResource) {
		if (urlResource == null) {
			throw new NullPointerException("Null setting url define!");
		}
		log.debug("Load setting file [{}]", urlResource);
		InputStream settingStream = null;
		try {
			settingStream = urlResource.getStream();
			load(settingStream);
		} catch (Exception e) {
			log.error(e, "Load setting error!");
			return false;
		} finally {
			IoUtil.close(settingStream);
		}
		return true;
	}
246562
public SourceUnit addSource(URL url) {
        return addSource(new SourceUnit(url, configuration, classLoader, getErrorCollector()));
    }
113867
@Override
    public T addAsLibrary(String resourceName) throws IllegalArgumentException {
        Validate.notNull(resourceName, "ResourceName must be specified");
        File file = fileFromResource(resourceName);
        return addAsLibrary(file, new BasicPath(resourceName));
    }
598758
public static AbstractResource getRawResourceFrom(final String location) throws IOException {
        if (StringUtils.isBlank(location)) {
            throw new IllegalArgumentException("Provided location does not exist and is empty");
        }
        if (location.toLowerCase().startsWith(HTTP_URL_PREFIX)) {
            return new UrlResource(location);
        }
        if (location.toLowerCase().startsWith(CLASSPATH_URL_PREFIX)) {
            return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()));
        }
        return new FileSystemResource(StringUtils.remove(location, FILE_URL_PREFIX));
    }
1282955
protected void addPackageResources(Package aPackage, Map<String, ClassResource> urlSet, ClassLoader[] classLoaders) {
        String packageName = aPackage.getName();
        String relativePath = getPackageRelativePath(packageName);
        List<URL> resources = getResources(relativePath, classLoaders);
        for (URL resource : resources) {
            String key = getJavaResourceKey(resource);
            urlSet.put(key, new ClassResource(packageName, resource));
        }
    }
1244874
private String loadDrlFile(final Reader drl) throws IOException {
        final StringBuilder buf = new StringBuilder();
        final BufferedReader input = new BufferedReader( drl );
        String line;
        while ( (line = input.readLine()) != null ) {
            buf.append( line );
            buf.append( nl );
        }
        return buf.toString();
    }
627473
public static List<File> localFilesFromUrlClassLoader(final URLClassLoader urlClassLoader) {
        checkNotNull("urlClassLoader", urlClassLoader);

        final List<File> files = new ArrayList<>();

        final URL[] urls = urlClassLoader.getURLs();
        for (final URL url : urls) {
            if ("file".equals(url.getProtocol())) {
                files.add(asFile(url));
            }
        }

        return files;

    }
1326230
def _loadThreePartSource(self, sourceFName, sourceLines):
        
        lineno = 1
        for ln in sourceLines:
            lineno += 1
            try:
                stem, pubType, source = ln.split("\t", 2)
                stem = stem.strip()[-9:]
                self._addPub(stem, source)
                if pubType=="C":
                    self.confstems[stem] = 1
            except ValueError:
                sys.stderr.write("sourcematchers.py: %s (%d): skipping source line: %s"%(sourceFName,lineno,ln))
459820
private static InputStream inputStreamFromFile(URL resourceUrl)
      throws IOException, URISyntaxException {
    File resourceFile = new File(resourceUrl.toURI());
    return new FileInputStream(resourceFile);
  }
1146189
public void loadTldsFromJar(URL url, String resourcePath, List loadedLocations, JspXmlExtConfig webAppConfig) {
        if(com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable(Level.FINE)){
                logger.logp(Level.FINE, CLASS_NAME, "loadTldsFromJar", "url ["+url+"]"+"resourcePath ["+resourcePath+"] loadedLocations ["+loadedLocations+"] webAppConfig ["+webAppConfig+"]" );
        }
        JarFile jarFile = null;
        InputStream stream = null;
        String name = null;
        try {
            JarURLConnection conn = (JarURLConnection)url.openConnection();
            conn.setUseCaches(false);
            jarFile = conn.getJarFile();

            String originatorId = jarFile.getName();
            originatorId = originatorId.substring(0, originatorId.indexOf(".jar"));
            if (originatorId.indexOf(File.separatorChar) != -1)
                originatorId = originatorId.substring(originatorId.lastIndexOf(File.separatorChar)+1);
            originatorId = NameMangler.mangleString(originatorId);

            Enumeration entries = jarFile.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = (JarEntry) entries.nextElement();
                name = entry.getName();
                if (name.startsWith("META-INF/") &&
                    name.endsWith(".tld") &&
                    loadedLocations.contains(resourcePath + "/" + name) == false) {
                    stream = jarFile.getInputStream(entry);
                    JspInputSource tldInputSource = getInputSource(container, name, null, url);
                    //TagLibraryInfoImpl tli = loadSerializedTld(tldInputSource, inputSource);

                    //if (tli == null) {
                    try {
                        TagLibraryInfoImpl tli = tldParser.parseTLD(tldInputSource, stream, originatorId);
                        
                        //516822 - If no URI is defined in the tag, we still want to load it in case it has listeners
                        //use the resourcePath + "/" + name as the key
                        String uri = null;
                        if (tli.getReliableURN() != null && tli.getReliableURN().trim().equals("") == false) {
                            uri = tli.getReliableURN();
                        } else {
                            uri = resourcePath + "/" + name;
                        }
                        
                        //if (tli.getReliableURN() != null && tli.getReliableURN().trim().equals("") == false) {
                            tli.setURI(uri);
                            if(com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable(Level.FINE)){
                                logger.logp(Level.FINE, CLASS_NAME, "loadTldsFromJar", "webAppConfig is "+webAppConfig);
                            }
                            if(com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable(Level.FINE) && webAppConfig!=null){
                                logger.logp(Level.FINE, CLASS_NAME, "loadTldsFromJar", "tli URN is "+ uri+
                                                                                                                                           " :webAppConfig.getTagLibMap() is "+webAppConfig.getTagLibMap()+
                                                                                                                                           " :webAppConfig.getTagLibMap().containsKey(uri) is "+webAppConfig.getTagLibMap().containsKey(uri)+
                                                                                                                                           " :containsKey(uri) is "+containsKey(uri) );
                            }
                            if ((webAppConfig!=null && webAppConfig.getTagLibMap().containsKey(uri)==false)
                                    || (webAppConfig==null && containsKey(uri) == false)) {
                                if(com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable(Level.FINE)){
                                    logger.logp(Level.FINE, CLASS_NAME, "loadTldsFromJar", "jar tld loaded for {0}", uri);
                                }
                                put(uri, tli);
                                //serializeTld(tldInputSource, tli);
                                eventListenerList.addAll(tldParser.getEventListenerList());
                                tagListForInjection.addAll(tldParser.getParsedTagsList());
                                if(com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable(Level.FINE)){
                                    logger.logp(Level.FINE, CLASS_NAME, "loadTldsFromJar", "tldParser.getEventListenerList() ["+ tldParser.getEventListenerList()+"]");
                                }
                            }
                        //}
                    }
                    catch (JspCoreException e) {
                        if(com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable(Level.WARNING)){
                            logger.logp(Level.WARNING, CLASS_NAME, "loadTldsFromJar", "jsp error failed to load tld in jar. uri = ["+resourcePath+"]", e);
                        }
                    }
                    //}

                    stream.close();
                    stream = null;
                }
            }
        }
        catch (Exception e) {
            if(com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable(Level.WARNING)){
                logger.logp(Level.WARNING, CLASS_NAME, "loadTldsFromJar", "jsp error failed to load tld in jar. uri = ["+resourcePath+"]", e);
            }
        }
        finally {
            if (stream != null) {
                try {
                    stream.close();
                }
                catch (Throwable t) {}
            }
            if (jarFile != null) {
                try {
                    jarFile.close();
                }
                catch (Throwable t) {}
            }
        }
    }
571243
public void addPackageFromDrl(final Reader reader,
                                  final Resource sourceResource) throws DroolsParserException,
            IOException {
        this.resource = sourceResource;
        final DrlParser parser = new DrlParser(configuration.getLanguageLevel());
        final PackageDescr pkg = parser.parse(sourceResource, reader);
        this.results.addAll(parser.getErrors());
        if (pkg == null) {
            addBuilderResult(new ParserError(sourceResource, "Parser returned a null Package", 0, 0));
        }

        if (!parser.hasErrors()) {
            addPackage(pkg);
        }
        this.resource = null;
    }
142012
public static URL[] findResourceBases(String baseResource, ClassLoader loader)
   {
      ArrayList<URL> list = new ArrayList<URL>();
      try
      {
         Enumeration<URL> urls = loader.getResources(baseResource);
         while (urls.hasMoreElements())
         {
            URL url = urls.nextElement();
            list.add(findResourceBase(url, baseResource));
         }
      }
      catch (IOException e)
      {
         throw new RuntimeException(e);
      }
      return list.toArray(new URL[list.size()]);
   }
508836
public AbstractFileResolvingResource getResource(HttpServletRequest request) throws MalformedURLException {
        String servletPath;
        String pathInfo;
        boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null;

        if (included) {
            servletPath = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
            pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);

            if (servletPath == null && pathInfo == null) {
                servletPath = request.getServletPath();
                pathInfo = request.getPathInfo();
            }
        } else {
            servletPath = request.getServletPath();
            pathInfo = request.getPathInfo();
        }

        String pathInContext = addPaths(servletPath, pathInfo);
        return getResource(pathInContext);
    }
320479
public ByteSource buildWrappedByteSource(URL url, int startIndex, int numberResults)
      throws IOException, XMLStreamException, TransformerException {
    Preconditions.checkArgument(startIndex >= 0, "startIndex must not be negative");
    Preconditions.checkArgument(numberResults > 0, "numberResults must be positive");

    StringWriter stringWriter = new StringWriter();

    XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(url.openStream());
    XMLEventWriter xmlEventWriter = xmlOutputFactory.createXMLEventWriter(stringWriter);

    int index = 0;
    boolean included = false;

    while (xmlEventReader.hasNext()) {
      XMLEvent event = xmlEventReader.nextEvent();

      if (event.isStartElement()) {
        String name = ((StartElement) event).getName().getLocalPart();
        if (name.equals(TAG_MUTATE_RESPONSE)) {
          // Write the <mutateResponse> tag.
          xmlEventWriter.add(event);
          continue;
        } else if (name.equals(TAG_RVAL) && ++index > startIndex) {
          // Included the eligible <rval> tags and sub tags by setting the 'included' flag.
          included = true;
        }
      } else if (event.isEndElement()) {
        String name = ((EndElement) event).getName().getLocalPart();
        if (name.equals(TAG_MUTATE_RESPONSE)) {
          // Write the </mutateResponse> tag.
          xmlEventWriter.add(event);
          break;
        } else if (included && name.equals(TAG_RVAL) && index == startIndex + numberResults) {
          // Write the last </rval> tag and append a </mutateResponse> tag, if this has written
          // the specified number of results.
          xmlEventWriter.add(event);
          xmlEventWriter.add(xmlEventFactory.createEndElement("", "", TAG_MUTATE_RESPONSE));
          break;
        }
      }

      if (included) {
        // Write the included tags and events.
        xmlEventWriter.add(event);
      }
    }
    xmlEventReader.close();
    xmlEventWriter.close();

    InputStream truncatedInputStream =
        ByteSource.wrap(stringWriter.toString().getBytes(UTF_8)).openStream();

    // Pass the input stream through a Transformer that removes the XML
    // declaration.
    Transformer transformer = transformerSupplier.get();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    StreamResult streamResult = new StreamResult(outputStream);
    Source xmlSource = new StreamSource(truncatedInputStream);
    transformer.transform(xmlSource, streamResult);

    return ByteSource.wrap(outputStream.toByteArray());
  }
1099564
public static synchronized void loadLibrary(File jar) throws NoAvailableBackendException {
        try {
            /*We are using reflection here to circumvent encapsulation; addURL is not public*/
            java.net.URLClassLoader loader = (java.net.URLClassLoader) ClassLoader.getSystemClassLoader();
            java.net.URL url = jar.toURI().toURL();
            /*Disallow if already loaded*/
            for (java.net.URL it : java.util.Arrays.asList(loader.getURLs())) {
                if (it.equals(url)) {
                    return;
                }
            }
            java.lang.reflect.Method method =
                            java.net.URLClassLoader.class.getDeclaredMethod("addURL", new Class[] {java.net.URL.class});
            method.setAccessible(true); /*promote the method to public access*/
            method.invoke(loader, new Object[] {url});
        } catch (final java.lang.NoSuchMethodException | java.lang.IllegalAccessException
                        | java.net.MalformedURLException | java.lang.reflect.InvocationTargetException e) {
            throw new NoAvailableBackendException(e);
        }
    }
1330518
public ApplicationResource addCssUrl(final String url) {
		if (Util.empty(url)) {
			throw new IllegalArgumentException("A URL must be provided.");
		}
		ApplicationResource res = new ApplicationResource(url);
		addCssResource(res);
		return res;
	}
1333013
private void loadResourceFile(URL configurationResourceUrl, Properties hotRodConfiguration) {
		if ( configurationResourceUrl != null ) {
			try ( InputStream openStream = configurationResourceUrl.openStream() ) {
				hotRodConfiguration.load( openStream );
			}
			catch (IOException e) {
				throw log.failedLoadingHotRodConfigurationProperties( e );
			}
		}
	}