Package org.eclipse.ease.tools
Class ResourceTools
java.lang.Object
org.eclipse.ease.tools.ResourceTools
public final class ResourceTools extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResourceTools.NonClosingInputStream
InputStream delegating all tasks to a base stream. -
Field Summary
Fields Modifier and Type Field Description static Object
VIRTUAL_WINDOWS_ROOT
Virtual file indicating a file system root on windows. -
Method Summary
Modifier and Type Method Description static void
createFolder(org.eclipse.core.resources.IContainer folder)
Creates a folder in the workspace if it does not exists already.static URI
createURI(String address)
Correctly escapes spaces in URIs.static boolean
exists(Object resource)
Check whether a resource exists.static InputStream
getInputStream(Object location)
Get the content of a resource location asInputStream
.static boolean
isAbsolute(String location)
Verifies if a location is provided in absolute form.static boolean
isFile(Object resource)
Check if a resource exists and is of type file.static boolean
isFolder(Object resource)
Check if a resource exists and is of type folder.static boolean
isWindows()
static Object
resolve(Object location)
Resolve to an existing File/IResource/URI/URL.static Object
resolve(Object location, Object parent)
Resolve to an existing File/IResource/URI/URL.static String
toAbsoluteLocation(Object location, Object parent)
Resolve a given location to an absolute location URI.static File
toFile(Object resource)
Get the filesystem representation of a given resource.static String
toProjectRelativeLocation(org.eclipse.core.resources.IResource resource)
Provides the project relative URI for a given workspace resource.static String
toRelativeLocation(Object resource, Object parent)
Create a relative path from one resource to another.static String
toString(InputStream stream)
Convert an input stream to a string.static String
toString(Reader reader)
Read characters from aReader
and return its string representation.static String
toString(Object location)
Reads from a resource into a string.
-
Field Details
-
VIRTUAL_WINDOWS_ROOT
Virtual file indicating a file system root on windows. Needed as windows does not have a real root file object.
-
-
Method Details
-
resolve
Resolve to an existing File/IResource/URI/URL. For relative locations the parent object location is taken into account.- Parameters:
location
- location to resolveparent
- parent location to resolve from (needs to be absolute)- Returns:
- resource or
null
-
exists
Check whether a resource exists. Works only for IResource, File, URI, URL objects. Does not try to resolve the given location.- Parameters:
resource
- resource to query for- Returns:
true
if resource exists or is of type URI or URL
-
isFile
Check if a resource exists and is of type file. Does not resolve the resource.- Parameters:
resource
-File
orIResource
object- Returns:
true
when resource is a file
-
isFolder
Check if a resource exists and is of type folder. For the eclipse workspace this check is also true for the workspace root and project locations. Does not resolve the resource.- Parameters:
resource
-File
orIResource
object- Returns:
true
when resource is a folder
-
resolve
Resolve to an existing File/IResource/URI/URL.- Parameters:
location
- location to resolve- Returns:
- resource or
null
-
isWindows
public static boolean isWindows() -
createURI
Correctly escapes spaces in URIs.- Parameters:
address
- address to create URI for- Returns:
- URI
- Throws:
MalformedURLException
URISyntaxException
-
isAbsolute
Verifies if a location is provided in absolute form.- Parameters:
location
- location string- Returns:
true
for absolute locations
-
toProjectRelativeLocation
Provides the project relative URI for a given workspace resource. The provided location will be of type 'project://...'.- Parameters:
resource
- resource to get relative URI for.- Returns:
- project relative location
-
toAbsoluteLocation
Resolve a given location to an absolute location URI. When location is not a string, we create an absolute string representation of the given location.- Parameters:
location
- (relative) locationparent
- parent object to resolve from- Returns:
- resolved location string or
null
-
toRelativeLocation
Create a relative path from one resource to another.- Parameters:
resource
- resource to create a relative path forparent
- resource to create relative path from- Returns:
- relative path for resource
-
getInputStream
Get the content of a resource location asInputStream
.- Parameters:
location
- location to read from- Returns:
InputStream
ornull
-
toString
Reads from a resource into a string. Does not throw any exceptions, instead returnsnull
in case of errors and logs the error to the system logger.- Parameters:
location
- location to look up- Returns:
- content or
null
in case of error
-
toString
Convert an input stream to a string.- Parameters:
stream
- input string to read from- Returns:
- string containing stream data
- Throws:
IOException
- thrown on problems with input stream
-
toString
Read characters from aReader
and return its string representation. Can be used to convert anInputStream
to a string.- Parameters:
reader
- reader to read from- Returns:
- string content of reader
- Throws:
IOException
- when reader is not accessible
-
toFile
Get the filesystem representation of a given resource. Does not try to resolve the resource.- Parameters:
resource
- resource to convert. Either aFile
or anIResource
- Returns:
- file or folder in the local file system
-
createFolder
public static void createFolder(org.eclipse.core.resources.IContainer folder) throws org.eclipse.core.runtime.CoreExceptionCreates a folder in the workspace if it does not exists already. Also creates any parent folder needed. If the project is also missing it will not be created.- Parameters:
folder
- folder to be created- Throws:
org.eclipse.core.runtime.CoreException
- when folder could not be created
-