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 classResourceTools.NonClosingInputStreamInputStream delegating all tasks to a base stream. -
Field Summary
Fields Modifier and Type Field Description static ObjectVIRTUAL_WINDOWS_ROOTVirtual file indicating a file system root on windows. -
Method Summary
Modifier and Type Method Description static voidcreateFolder(org.eclipse.core.resources.IContainer folder)Creates a folder in the workspace if it does not exists already.static URIcreateURI(String address)Correctly escapes spaces in URIs.static booleanexists(Object resource)Check 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 booleanisFile(Object resource)Check if a resource exists and is of type file.static booleanisFolder(Object resource)Check if a resource exists and is of type folder.static booleanisWindows()static Objectresolve(Object location)Resolve to an existing File/IResource/URI/URL.static Objectresolve(Object location, Object parent)Resolve to an existing File/IResource/URI/URL.static StringtoAbsoluteLocation(Object location, Object parent)Resolve a given location to an absolute location URI.static FiletoFile(Object resource)Get the filesystem representation of a given resource.static StringtoProjectRelativeLocation(org.eclipse.core.resources.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 StringtoString(Reader reader)Read characters from aReaderand return its string representation.static StringtoString(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:
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.- Parameters:
resource-FileorIResourceobject- Returns:
truewhen 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-FileorIResourceobject- Returns:
truewhen 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:
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.- Parameters:
resource- resource to convert. Either aFileor 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
-