public final class ResourceTools
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ResourceTools.NonClosingInputStream
InputStream delegating all tasks to a base stream.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.Object |
VIRTUAL_WINDOWS_ROOT
Virtual file indicating a file system root on windows.
|
Modifier and Type | Method and Description |
---|---|
static void |
createFolder(IContainer folder)
Creates a folder in the workspace if it does not exists already.
|
static java.net.URI |
createURI(java.lang.String address)
Correctly escapes spaces in URIs.
|
static boolean |
exists(java.lang.Object resource)
Check whether a resource exists.
|
static java.io.InputStream |
getInputStream(java.lang.Object location)
Get the content of a resource location as
InputStream . |
static boolean |
isAbsolute(java.lang.String location)
Verifies if a location is provided in absolute form.
|
static boolean |
isFile(java.lang.Object resource)
Check if a resource exists and is of type file.
|
static boolean |
isFolder(java.lang.Object resource)
Check if a resource exists and is of type folder.
|
static boolean |
isWindows() |
static java.lang.Object |
resolve(java.lang.Object location)
Resolve to an existing File/IResource/URI/URL.
|
static java.lang.Object |
resolve(java.lang.Object location,
java.lang.Object parent)
Resolve to an existing File/IResource/URI/URL.
|
static java.lang.String |
toAbsoluteLocation(java.lang.Object location,
java.lang.Object parent)
Resolve a given location to an absolute location URI.
|
static java.io.File |
toFile(java.lang.Object resource)
Get the filesystem representation of a given resource.
|
static java.lang.String |
toProjectRelativeLocation(IResource resource)
Provides the project relative URI for a given workspace resource.
|
static java.lang.String |
toRelativeLocation(java.lang.Object resource,
java.lang.Object parent)
Create a relative path from one resource to another.
|
static java.lang.String |
toString(java.io.InputStream stream)
Convert an input stream to a string.
|
static java.lang.String |
toString(java.lang.Object location)
Reads from a resource into a string.
|
static java.lang.String |
toString(java.io.Reader reader)
Read characters from a
Reader and return its string representation. |
public static final java.lang.Object VIRTUAL_WINDOWS_ROOT
public static java.lang.Object resolve(java.lang.Object location, java.lang.Object parent)
location
- location to resolveparent
- parent location to resolve from (needs to be absolute)null
public static boolean exists(java.lang.Object resource)
resource
- resource to query fortrue
if resource exists or is of type URI or URLpublic static boolean isFile(java.lang.Object resource)
resource
- File
or IResource
objecttrue
when resource is a filepublic static boolean isFolder(java.lang.Object resource)
resource
- File
or IResource
objecttrue
when resource is a folderpublic static java.lang.Object resolve(java.lang.Object location)
location
- location to resolvenull
public static boolean isWindows()
public static java.net.URI createURI(java.lang.String address) throws java.net.MalformedURLException, java.net.URISyntaxException
address
- address to create URI forjava.net.MalformedURLException
java.net.URISyntaxException
public static boolean isAbsolute(java.lang.String location)
location
- location stringtrue
for absolute locationspublic static java.lang.String toProjectRelativeLocation(IResource resource)
resource
- resource to get relative URI for.public static java.lang.String toAbsoluteLocation(java.lang.Object location, java.lang.Object parent)
location
- (relative) locationparent
- parent object to resolve fromnull
public static java.lang.String toRelativeLocation(java.lang.Object resource, java.lang.Object parent)
resource
- resource to create a relative path forparent
- resource to create relative path frompublic static java.io.InputStream getInputStream(java.lang.Object location)
InputStream
.location
- location to read fromInputStream
or null
public static java.lang.String toString(java.lang.Object location)
null
in case of errors and logs the error to the system
logger.location
- location to look upnull
in case of errorpublic static java.lang.String toString(java.io.InputStream stream) throws java.io.IOException
stream
- input string to read fromjava.io.IOException
- thrown on problems with input streampublic static java.lang.String toString(java.io.Reader reader) throws java.io.IOException
Reader
and return its string representation. Can be used to convert an InputStream
to a string.reader
- reader to read fromjava.io.IOException
- when reader is not accessiblepublic static java.io.File toFile(java.lang.Object resource)
resource
- resource to convert. Either a File
or an IResource
public static void createFolder(IContainer folder) throws CoreException
folder
- folder to be createdCoreException
- when folder could not be created