public final class ResourceTools extends 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 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 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 as
InputStream . |
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 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(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(Object location)
Reads from a resource into a string.
|
static String |
toString(Reader reader)
Read characters from a
Reader and return its string representation. |
public static final Object VIRTUAL_WINDOWS_ROOT
public static Object resolve(Object location, Object parent)
location
- location to resolveparent
- parent location to resolve from (needs to be absolute)null
public static boolean exists(Object resource)
resource
- resource to query fortrue
if resource exists or is of type URI or URLpublic static boolean isFile(Object resource)
public static boolean isFolder(Object resource)
public static Object resolve(Object location)
location
- location to resolvenull
public static URI createURI(String address) throws MalformedURLException, URISyntaxException
address
- address to create URI forMalformedURLException
URISyntaxException
public static boolean isAbsolute(String location)
location
- location stringtrue
for absolute locationspublic static String toProjectRelativeLocation(IResource resource)
resource
- resource to get relative URI for.public static String toAbsoluteLocation(Object location, Object parent)
location
- (relative) locationparent
- parent object to resolve fromnull
public static String toRelativeLocation(Object resource, Object parent)
resource
- resource to create a relative path forparent
- resource to create relative path frompublic static InputStream getInputStream(Object location)
InputStream
.location
- location to read fromInputStream
or null
public static String toString(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 String toString(InputStream stream) throws IOException
stream
- input string to read fromIOException
- thrown on problems with input streampublic static String toString(Reader reader) throws IOException
Reader
and return its string representation. Can be used to convert an InputStream
to a string.reader
- reader to read fromIOException
- when reader is not accessiblepublic static File toFile(Object resource)
public static void createFolder(IContainer folder) throws CoreException
folder
- folder to be createdCoreException
- when folder could not be created