org.mule.runtime.core.api.util.IOUtils.getResourceAsStream()方法的使用及代码示例

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

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

IOUtils.getResourceAsStream介绍

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

代码示例

代码示例来源:origin: mulesoft/mule

protected InputStream loadResource(String resourceName) throws IOException {
 return IOUtils.getResourceAsStream(resourceName, getClass());
}

代码示例来源:origin: mulesoft/mule

private Collection<? extends CRL> loadCRL(String crlPath) throws CertificateException, IOException, CRLException {
 Collection<? extends CRL> crlList = null;
 if (crlPath != null) {
  InputStream in = null;
  try {
   in = IOUtils.getResourceAsStream(crlPath, getClass());
   crlList = CertificateFactory.getInstance("X.509").generateCRLs(in);
  } finally {
   if (in != null) {
    in.close();
   }
  }
 }
 return crlList;
}

代码示例来源:origin: mulesoft/mule

@Test
public void testLoadingResourcesAsStream() throws Exception {
 InputStream is = IOUtils.getResourceAsStream("log4j2-test.xml", getClass(), false, false);
 assertNotNull(is);
 is = IOUtils.getResourceAsStream("does-not-exist.properties", getClass(), false, false);
 assertNull(is);
}

代码示例来源:origin: org.mule.runtime/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
 * @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) throws IOException {
 return getResourceAsStream(resourceName, callingClass, true, true);
}

代码示例来源:origin: org.mule.runtime/mule-module-tls

private Collection<? extends CRL> loadCRL(String crlPath) throws CertificateException, IOException, CRLException {
 Collection<? extends CRL> crlList = null;
 if (crlPath != null) {
  InputStream in = null;
  try {
   in = IOUtils.getResourceAsStream(crlPath, getClass());
   crlList = CertificateFactory.getInstance("X.509").generateCRLs(in);
  } finally {
   if (in != null) {
    in.close();
   }
  }
 }
 return crlList;
}

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

private KeyStore loadKeyStore() throws GeneralSecurityException, IOException {
 KeyStore tempKeyStore = KeyStore.getInstance(keystoreType);
 InputStream is = IOUtils.getResourceAsStream(keyStoreName, getClass());
 if (null == is) {
  throw new FileNotFoundException(cannotLoadFromClasspath("Keystore: " + keyStoreName).getMessage());
 }
 tempKeyStore.load(is, keyStorePassword.toCharArray());
 return tempKeyStore;
}

代码示例来源:origin: org.mule.runtime/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
 * @return the requested resource as a string
 * @throws java.io.IOException IO error
 */
public static String getResourceAsString(final String resourceName, final Class callingClass) throws IOException {
 try (InputStream is = getResourceAsStream(resourceName, callingClass)) {
  if (is != null) {
   return toString(is);
  } else {
   throw new IOException("Unable to load resource " + resourceName);
  }
 }
}

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

private KeyStore createTrustStore() throws CreateException {
 trustStorePassword = null == trustStorePassword ? "" : trustStorePassword;
 KeyStore trustStore;
 try {
  trustStore = KeyStore.getInstance(trustStoreType);
  InputStream is = IOUtils.getResourceAsStream(trustStoreName, getClass());
  if (null == is) {
   throw new FileNotFoundException(
                   "Failed to load truststore from classpath or local file: " + trustStoreName);
  }
  trustStore.load(is, trustStorePassword.toCharArray());
 } catch (Exception e) {
  throw new CreateException(
               failedToLoad("TrustStore: " + trustStoreName), e, this);
 }
 return trustStore;
}

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

public void load(String fileName) {
 try {
  InputStream config = IOUtils.getResourceAsStream(fileName, TlsProperties.class);
  if (config == null) {
   logger.warn(String.format("File %s not found, using default configuration.", fileName));
  } else {
   logger.info(String.format("Loading configuration file: %s", fileName));
   Properties properties = loadProperties(config);
   String enabledCipherSuitesProperty = properties.getProperty("enabledCipherSuites");
   String enabledProtocolsProperty = properties.getProperty("enabledProtocols");
   String defaultProtocolProperty = properties.getProperty("defaultProtocol");
   if (enabledCipherSuitesProperty != null) {
    enabledCipherSuites = StringUtils.splitAndTrim(enabledCipherSuitesProperty, ",");
   }
   if (enabledProtocolsProperty != null) {
    enabledProtocols = StringUtils.splitAndTrim(enabledProtocolsProperty, ",");
   }
   if (defaultProtocolProperty != null) {
    defaultProtocol = defaultProtocolProperty.trim();
   }
  }
 } catch (IOException e) {
  logger.warn(String.format("Cannot read file %s, using default configuration", fileName), e);
 }
}

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

/**
 * Read in the properties from a properties file. The file may be on the file system or the classpath.
 *
 * @param fileName - The name of the properties file
 * @param callingClass - The Class which is calling this method. This is used to determine the classpath.
 * @return a java.util.Properties object containing the properties.
 */
public static synchronized Properties loadProperties(String fileName, final Class<?> callingClass) throws IOException {
 InputStream is = IOUtils.getResourceAsStream(fileName, callingClass, /* tryAsFile */true, /* tryAsUrl */false);
 if (is == null) {
  I18nMessage error = CoreMessages.cannotLoadFromClasspath(fileName);
  throw new IOException(error.toString());
 }
 return loadProperties(is);
}

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

@Test
public void testLoadingResourcesAsStream() throws Exception {
 InputStream is = IOUtils.getResourceAsStream("log4j2-test.xml", getClass(), false, false);
 assertNotNull(is);
 is = IOUtils.getResourceAsStream("does-not-exist.properties", getClass(), false, false);
 assertNull(is);
}

相关文章