本文整理了Java中org.mule.util.IOUtils.getResourceAsStream()
方法的一些代码示例,展示了IOUtils.getResourceAsStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.getResourceAsStream()
方法的具体详情如下:
包路径:org.mule.util.IOUtils
类名称:IOUtils
方法名:getResourceAsStream
[英]Attempts to load a resource from the file system, from a URL, or from the classpath, in that order.
[中]尝试按该顺序从文件系统、URL或类路径加载资源。
代码示例来源: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
* @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.modules/mule-module-xml
protected InputStream loadSchemaStream(String schemaLocation) throws IOException
{
return IOUtils.getResourceAsStream(schemaLocation, getClass());
}
代码示例来源:origin: org.mule.modules/mule-module-jbpm
@Override
public void deployProcess(String processDefinitionFile) throws IOException
{
deployProcessFromStream(processDefinitionFile, IOUtils.getResourceAsStream(processDefinitionFile,
getClass()));
}
代码示例来源:origin: org.mule.transports/mule-transport-jbpm
public void deployProcess(String processDefinitionFile) throws IOException
{
deployProcessFromStream(processDefinitionFile, IOUtils.getResourceAsStream(processDefinitionFile,
getClass()));
}
代码示例来源:origin: org.mule/mule-core
protected 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.modules/mule-module-spring-config
protected Resource getResourceByPath(String path)
{
InputStream is = null;
try
{
is = IOUtils.getResourceAsStream(path, getClass());
}
catch (IOException e)
{
logger.error("Unable to load Spring resource " + path + " : " + e.getMessage());
return null;
}
if (is != null)
{
return new InputStreamResource(is);
}
else
{
logger.error("Unable to locate Spring resource " + path);
return null;
}
}
代码示例来源:origin: org.mule.transports/mule-transport-ssl
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/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.modules/mule-module-xml
@Override
public Source resolve(String href, String base) throws javax.xml.transform.TransformerException
{
try
{
InputStream is = IOUtils.getResourceAsStream(href, getClass());
if (is != null)
{
return new StreamSource(is);
}
else if (xslFile != null)
{
// Try to use relative path
int pathPos = xslFile.lastIndexOf('/');
if (pathPos > -1)
{
// Path exists
String path = xslFile.substring(0, pathPos + 1);
return new StreamSource(IOUtils.getResourceAsStream(path + href, getClass()));
}
}
throw new TransformerException("Stylesheet not found: " + href);
}
catch (IOException e)
{
throw new TransformerException(e);
}
}
}
代码示例来源:origin: org.mule/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.modules/mule-module-1to2migration
public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException
{
logger.debug("Trying to resolve XML entity with public ID: " + publicId + " and system ID: "
+ systemId);
InputSource source = null;
currentXsl = null;
if (delegate != null)
{
source = delegate.resolveEntity(publicId, systemId);
}
if ((source == null) && StringUtils.isNotBlank(systemId) && systemId.endsWith(".dtd"))
{
String[] tokens = systemId.split("/");
String dtdFile = tokens[tokens.length - 1];
logger.debug("Looking on classpath for " + SEARCH_PATH + dtdFile);
InputStream is = IOUtils.getResourceAsStream(SEARCH_PATH + dtdFile, getClass(), /* tryAsFile */
true, /* tryAsUrl */false);
if (is != null)
{
source = new InputSource(is);
source.setPublicId(publicId);
source.setSystemId(systemId);
logger.debug("Found on classpath mule DTD: " + systemId);
currentXsl = xsl;
return source;
}
logger.debug("Could not find dtd resource on classpath: " + SEARCH_PATH + dtdFile);
}
return source;
}
代码示例来源:origin: org.mule.modules/mule-module-spring-config
public Object getObject() throws Exception
{
if(data!=null)
{
return data;
}
if(file!=null)
{
if(binary)
{
data = IOUtils.toByteArray(IOUtils.getResourceAsStream(file, getClass()));
}
else
{
data = IOUtils.getResourceAsString(file, getClass());
}
}
else if(ref!=null)
{
data = context.getBean(ref);
}
if(data==null)
{
throw new IllegalArgumentException("Data is null was not found");
}
return data;
}
代码示例来源:origin: org.mule/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");
if (enabledCipherSuitesProperty != null)
{
enabledCipherSuites = StringUtils.splitAndTrim(enabledCipherSuitesProperty, ",");
}
if (enabledProtocolsProperty != null)
{
enabledProtocols = StringUtils.splitAndTrim(enabledProtocolsProperty, ",");
}
}
}
catch (IOException e)
{
logger.warn(String.format("Cannot read file %s, using default configuration", fileName), e);
}
}
代码示例来源:origin: org.mule.transports/mule-transport-servlet
InputStream in = IOUtils.getResourceAsStream(file, getClass(), false, false);
if (in == null)
代码示例来源:origin: org.mule/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)
{
Message error = CoreMessages.cannotLoadFromClasspath(fileName);
throw new IOException(error.toString());
}
return loadProperties(is);
}
代码示例来源:origin: org.mule.modules/mule-module-json
@Override
public void initialise() throws InitialisationException
{
try
{
InputStream inputStream = IOUtils.getResourceAsStream(schemaLocations, getClass());
InputStreamReader reader = new InputStreamReader(inputStream);
// TODO https://github.com/fge/msg-simple/issues/1
// There is way currently to destroy threads created by this component
JsonNode jsonNode = JsonLoader.fromReader(reader);
JsonSchemaFactory schemaFactory = JsonSchemaFactory.byDefault();
jsonSchema = schemaFactory.getJsonSchema(jsonNode);
}
catch (Exception e)
{
Message msg = MessageFactory.createStaticMessage("Unable to load or parse JSON Schema file at: " + schemaLocations);
throw new InitialisationException(msg, e, this);
}
}
代码示例来源:origin: org.mule.modules/mule-module-pgp
InputStream inputStream = IOUtils.getResourceAsStream(getPublicKeyRingFileName(), getClass());
validateNotNull(inputStream, noFileKeyFound(getPublicKeyRingFileName()));
publicKeys = new PGPPublicKeyRingCollection(inputStream, KEY_FINGERPRINT_CALCULATOR);
代码示例来源:origin: org.mule.transports/mule-transport-jetty
@SuppressWarnings("unchecked")
protected void initialiseFromConfigFile() throws InitialisationException
{
if (configFile == null)
{
return;
}
try
{
InputStream is = IOUtils.getResourceAsStream(configFile, getClass());
XmlConfiguration config = new XmlConfiguration(is);
String appHome =
muleContext.getRegistry().lookupObject(MuleProperties.APP_HOME_DIRECTORY_PROPERTY);
if (appHome == null)
{
// Mule IDE sets app.home as part of the launch config it creates
appHome = System.getProperty(MuleProperties.APP_HOME_DIRECTORY_PROPERTY);
}
if (appHome != null)
{
config.getProperties().put(MuleProperties.APP_HOME_DIRECTORY_PROPERTY, appHome);
}
config.configure(httpServer);
}
catch (Exception e)
{
throw new InitialisationException(e, this);
}
}
代码示例来源:origin: org.mule.modules/mule-module-xml
private LSInput obtainInputStream(String type, String namespaceURI, String publicId, String systemId, String baseUri) throws URISyntaxException, IOException
{
String resource = resolveUri(systemId, baseUri);
LocalResourceResolverInput input = new LocalResourceResolverInput();
InputStream stream = IOUtils.getResourceAsStream(resource, getClass());
if (stream == null)
{
return null;
}
input.setPublicId(publicId);
input.setSystemId(systemId);
input.setBaseURI(baseUri);
input.setByteStream(stream);
return input;
}
代码示例来源:origin: org.mule.modules/mule-module-pgp
private void readPrivateKeyBundle()
{
try
{
validateNotNull(getSecretKeyRingFileName(), noSecretKeyDefined());
InputStream secretKeyInputStream = IOUtils.getResourceAsStream(getSecretKeyRingFileName(), getClass());
validateNotNull(secretKeyInputStream, noFileKeyFound(getSecretKeyRingFileName()));
secretKeys = new PGPSecretKeyRingCollection(secretKeyInputStream, KEY_FINGERPRINT_CALCULATOR);
secretKeyInputStream.close();
String secretAliasId = getSecretAliasId();
if (secretAliasId != null)
{
secretKey = secretKeys.getSecretKey(parseSecretAliasId(secretAliasId));
validateNotNull(secretKey, noKeyIdFound(getSecretAliasId()));
}
readSecretKey = true;
} catch (IOException | PGPException e) {
throw new MissingPGPKeyException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!