org.apache.camel.util
Class ResourceHelper

java.lang.Object
  extended by org.apache.camel.util.ResourceHelper

public final class ResourceHelper
extends Object

Helper class for loading resources on the classpath or file system.


Method Summary
static String appendParameters(String uri, Map<String,Object> parameters)
          Appends the parameters to the given uri
static String getScheme(String uri)
          Gets the scheme from the URI (e.g.
static boolean hasScheme(String uri)
          Determines whether the URI has a scheme (e.g.
static boolean isHttpUri(String uri)
          Is the given uri a http uri?
static InputStream resolveMandatoryResourceAsInputStream(ClassResolver classResolver, String uri)
          Resolves the mandatory resource.
static URL resolveMandatoryResourceAsUrl(ClassResolver classResolver, String uri)
          Resolves the mandatory resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hasScheme

public static boolean hasScheme(String uri)
Determines whether the URI has a scheme (e.g. file:, classpath: or http:)

Parameters:
uri - the URI
Returns:
true if the URI starts with a scheme

getScheme

public static String getScheme(String uri)
Gets the scheme from the URI (e.g. file:, classpath: or http:)

Parameters:
uri - the uri
Returns:
the scheme, or null if no scheme

resolveMandatoryResourceAsInputStream

public static InputStream resolveMandatoryResourceAsInputStream(ClassResolver classResolver,
                                                                String uri)
                                                         throws IOException
Resolves the mandatory resource.

If possible recommended to use resolveMandatoryResourceAsUrl(org.apache.camel.spi.ClassResolver, String)

Parameters:
classResolver - the class resolver to load the resource from the classpath
uri - URI of the resource
Returns:
the resource as an InputStream. Remember to close this stream after usage.
Throws:
IOException - is thrown if the resource file could not be found or loaded as InputStream

resolveMandatoryResourceAsUrl

public static URL resolveMandatoryResourceAsUrl(ClassResolver classResolver,
                                                String uri)
                                         throws FileNotFoundException,
                                                MalformedURLException
Resolves the mandatory resource.

Parameters:
classResolver - the class resolver to load the resource from the classpath
uri - uri of the resource
Returns:
the resource as an InputStream. Remember to close this stream after usage.
Throws:
FileNotFoundException - is thrown if the resource file could not be found
MalformedURLException - if the URI is malformed

isHttpUri

public static boolean isHttpUri(String uri)
Is the given uri a http uri?

Parameters:
uri - the uri
Returns:
true if the uri starts with http: or https:

appendParameters

public static String appendParameters(String uri,
                                      Map<String,Object> parameters)
                               throws URISyntaxException
Appends the parameters to the given uri

Parameters:
uri - the uri
parameters - the additional parameters (will clear the map)
Returns:
a new uri with the additional parameters appended
Throws:
URISyntaxException - is thrown if the uri is invalid


Apache CAMEL