Package org.eclipse.ease.tools
Class ResourceTools
java.lang.Object
org.eclipse.ease.tools.ResourceTools
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInputStream delegating all tasks to a base stream. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectVirtual file indicating a file system root on windows. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateFolder(IContainer folder) Creates a folder in the workspace if it does not exists already.static URICorrectly escapes spaces in URIs.static booleanCheck whether a resource exists.static InputStreamgetInputStream(Object location) Get the content of a resource location asInputStream.static booleanisAbsolute(String location) Verifies if a location is provided in absolute form.static booleanCheck if a resource exists and is of type file.static booleanCheck if a resource exists and is of type folder.static booleanstatic ObjectResolve to an existing File/IResource/URI/URL.static ObjectResolve to an existing File/IResource/URI/URL.static StringtoAbsoluteLocation(Object location, Object parent) Resolve a given location to an absolute location URI.static FileGet the filesystem representation of a given resource.static StringtoProjectRelativeLocation(IResource resource) Provides the project relative URI for a given workspace resource.static StringtoRelativeLocation(Object resource, Object parent) Create a relative path from one resource to another.static StringtoString(InputStream stream) Convert an input stream to a string.static StringRead characters from aReaderand return its string representation.static StringReads 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:
trueif 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. -
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. -
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:
MalformedURLExceptionURISyntaxException
-
isAbsolute
Verifies if a location is provided in absolute form.- Parameters:
location- location string- Returns:
truefor 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:
InputStreamornull
-
toString
Reads from a resource into a string. Does not throw any exceptions, instead returnsnullin case of errors and logs the error to the system logger.- Parameters:
location- location to look up- Returns:
- content or
nullin 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 aReaderand return its string representation. Can be used to convert anInputStreamto 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. -
createFolder
Creates 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:
CoreException- when folder could not be created
-