net.sf.provisioner.utils
Class PathHelper
java.lang.Object
net.sf.provisioner.utils.PathHelper
public class PathHelper
- extends java.lang.Object
Helper class for loading files. Makes an attempt at interpreting
String paths into URLs, local jars, local files, or
ClassLoader resources.
- Version:
- $Revision: 1.1.2.1 $
- Author:
- Gordon Pearson
Method Summary |
static java.io.InputStream |
pathToStream(java.lang.String path)
Attempts to convert a path to an InputStream. |
static java.net.URL |
pathToURL(java.lang.String path)
Attempts to convert a path to a URL. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PathHelper
public PathHelper()
pathToStream
public static java.io.InputStream pathToStream(java.lang.String path)
throws java.io.IOException,
java.net.MalformedURLException
- Attempts to convert a path to an InputStream. In order, attempts to:
- open the path as a URL, if it contains protocol information (e.g.
ftp:)
- open the path as a jarfile in the local filesystem if it includes
"!/".
- open the path as a local file.
- open the path as a resource using a ClasLoader.
- Parameters:
path
- a URI, local filesystem reference, or resource reference.
- Returns:
- an InputStream to
path
's content, or
null if the path doesn't point to something.
- Throws:
java.io.IOException
java.net.MalformedURLException
- if the path contains a protocol, but
is not a valid URL.
pathToURL
public static java.net.URL pathToURL(java.lang.String path)
throws java.io.IOException,
java.net.MalformedURLException
- Attempts to convert a path to a URL. In order, checks if :
- path contains protocol information (e.g. ftp:)
- path contains "!/" and is a jarfile in the local filesystem.
- path is a local file.
- Parameters:
path
- a URL string, local filesystem reference, or resource
reference.
- Returns:
- a URL or null if the path cannot be converted.
- Throws:
java.io.IOException
java.net.MalformedURLException
- if the path contains a protocol, but
is not a valid URL.
Copyright © 2007-2008. All Rights Reserved.