org.mule.util.IOUtils.getResourceAsUrl()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中org.mule.util.IOUtils.getResourceAsUrl()方法的一些代码示例,展示了IOUtils.getResourceAsUrl()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.getResourceAsUrl()方法的具体详情如下:
包路径:org.mule.util.IOUtils
类名称:IOUtils
方法名:getResourceAsUrl

IOUtils.getResourceAsUrl介绍

[英]Attempts to load a resource from the file system or from the classpath, in that order.
[中]尝试按该顺序从文件系统或类路径加载资源。

代码示例

代码示例来源:origin: org.mule/mule-core

/**
 * Attempts to load a resource from the file system or from the classpath, in
 * that order.
 * 
 * @param resourceName The name of the resource to load
 * @param callingClass The Class object of the calling object
 * @return an URL to the resource or null if resource not found
 */
public static URL getResourceAsUrl(final String resourceName, final Class callingClass)
{
  return getResourceAsUrl(resourceName, callingClass, true, true);
}

代码示例来源:origin: org.mule.modules/mule-module-ws

private String getAbsoluteURL(String uri)
{
  if (uri != null)
  {
    URL absoluteURL = IOUtils.getResourceAsUrl(uri, getClass());
    return (absoluteURL == null) ? null : absoluteURL.toString();
  }
  return uri;
}

代码示例来源:origin: org.mule/mule-core

public ConfigResource(String resourceName) throws IOException
{
  this.resourceName = resourceName;
  url = IOUtils.getResourceAsUrl(resourceName, getClass(), true, true);
  if(url == null)
  {
    throw new FileNotFoundException(resourceName);
  }
}

代码示例来源:origin: org.mule.transports/mule-transport-rmi

public void setSecurityPolicy(String path)
{
  // verify securityPolicy existence
  if (path != null)
  {
    URL url = IOUtils.getResourceAsUrl(path, RmiConnector.class);
    if (url == null)
    {
      throw new IllegalArgumentException(
        "Error on initialization, RMI security policy does not exist");
    }
    this.securityPolicy = url.toString();
  }
}

代码示例来源:origin: org.mule/mule-core

/**
 * Attempts to load a resource from the file system, from a URL, or from the
 * classpath, in that order.
 * 
 * @param resourceName The name of the resource to load
 * @param callingClass The Class object of the calling object
 * @param tryAsFile - try to load the resource from the local file system
 * @param tryAsUrl - try to load the resource as a URL
 * @return an InputStream to the resource or null if resource not found
 * @throws java.io.IOException IO error
 */
public static InputStream getResourceAsStream(final String resourceName,
                       final Class callingClass,
                       boolean tryAsFile,
                       boolean tryAsUrl) throws IOException
{
  URL url = getResourceAsUrl(resourceName, callingClass, tryAsFile, tryAsUrl);
  if (url == null)
  {
    return null;
  }
  else
  {
    return url.openStream();
  }
}

代码示例来源:origin: com.mulesoft.munit/mule-munit-support

public static String getResourcePath(String resourceName, Class callingClass, String encoding)
    throws IOException {
  if (resourceName == null) {
    // no name
    return null;
  }
  URL url = IOUtils.getResourceAsUrl(resourceName, callingClass);
  if (url == null) {
    // not found
    return null;
  }
  return normalizeFilePath(url, encoding);
}

代码示例来源:origin: org.mule/mule-core

public static String getResourcePath(String resourceName, Class callingClass, String encoding)
    throws IOException
{
  if (resourceName == null)
  {
    // no name
    return null;
  }
  URL url = IOUtils.getResourceAsUrl(resourceName, callingClass);
  if (url == null)
  {
    // not found
    return null;
  }
  return normalizeFilePath(url, encoding);
}

代码示例来源:origin: org.mule.modules/mule-module-ws

@Override
  public InputStream retrieveWsdlResource(String url) throws WSDLException
  {
    InputStream responseStream = null;
    URL location = IOUtils.getResourceAsUrl(url, getClass());

    if (location == null)
    {
      throw new WSDLException("No resource was found on: %s", url.toString());
    }
    
    try
    {
      URLConnection urlConnection = location.openConnection();
      if (location.getUserInfo() != null)
      {
        urlConnection.setRequestProperty("Authorization", "Basic " + encodeBytes(location.getUserInfo().getBytes()));
      }

      responseStream = urlConnection.getInputStream();

      return responseStream;
    }
    catch (Exception e)
    {
      throw new WSDLException("Exception retrieving WSDL for URL: %s", url.toString(), e);
    }
  }
}

代码示例来源:origin: org.mule.modules/mule-module-ws

@Override
public InputSource getImportInputSource(String parentLocation, String importLocation)
{
  try
  {
    if (isHttpAddress(importLocation))
    {
      latestImportedURL = importLocation;
    }
    else
    {
      URL url = IOUtils.getResourceAsUrl(parentLocation, getClass());
      if (mustResolveRelativePaths(url))
      {
        latestImportedURL = resolveRelativePathInArchives(normalize(getBasePath(url.toString())) + importLocation);
      }
      else
      {
        latestImportedURL = normalize((getBasePath(url.toString()) + importLocation));
      }
    }
    return getInputSource(latestImportedURL);
  }
  catch (Exception e)
  {
    throw new RuntimeException("There has been an error retrieving the following wsdl resource: " + latestImportedURL, e);
  }
}

代码示例来源:origin: org.mule/mule-core

URL configUrl = IOUtils.getResourceAsUrl(DEFAULT_CONFIGURATION, MuleServer.class, true, false);
if (configUrl != null)

代码示例来源:origin: org.mule.modules/mule-module-plexus

public void initialise() throws InitialisationException, RecoverableException
{
  if (configFile == null) {
    return;
  }
  try {
    URL url = IOUtils.getResourceAsUrl(configFile, getClass());
    if (url == null) {
      throw new ConfigurationException(new Message(Messages.CANT_LOAD_X_FROM_CLASSPATH_FILE, configFile));
    }
    container.setConfiguration(url);
    container.start();
  } catch (Exception e) {
    throw new InitialisationException(new Message(Messages.FAILED_TO_CREATE_X_WITH_X,
                           "Plexus container",
                           this.configFile), this);
  }
}

相关文章