org.eclipse.ease.tools

## Class ResourceTools

- java.lang.Object
- - org.eclipse.ease.tools.ResourceTools

    public final class ResourceTools
    extends java.lang.Object

### Nested Class Summary

Nested Classes
`static class` `ResourceTools.NonClosingInputStream` InputStream delegating all tasks to a base stream.

### Field Summary

Fields
`static java.lang.Object` `VIRTUAL_WINDOWS_ROOT` Virtual file indicating a file system root on windows.

### Method Summary

All Methods Static Methods Concrete Methods
`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.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### VIRTUAL_WINDOWS_ROOT

    public static final java.lang.Object VIRTUAL_WINDOWS_ROOT

Virtual file indicating a file system root on windows. Needed as windows does not have a real root file object.

### Method Detail

#### resolve

    public static java.lang.Object resolve(java.lang.Object location,
                                           java.lang.Object parent)

Resolve to an existing File/IResource/URI/URL. For relative locations the parent object location is taken into account.

Parameters:
  `location` - location to resolve
  `parent` - parent location to resolve from (needs to be absolute)
Returns:
  resource or `null`

#### exists

    public static boolean exists(java.lang.Object resource)

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

    public static boolean isFile(java.lang.Object resource)

Check if a resource exists and is of type file. Does not resolve the resource.

Parameters:
  `resource` - `File` or `IResource` object
Returns:
  `true` when resource is a file

#### isFolder

    public static boolean isFolder(java.lang.Object resource)

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` or `IResource` object
Returns:
  `true` when resource is a folder

#### resolve

    public static java.lang.Object resolve(java.lang.Object location)

Resolve to an existing File/IResource/URI/URL.

Parameters:
  `location` - location to resolve
Returns:
  resource or `null`

#### isWindows

    public static boolean isWindows()

#### createURI

    public static java.net.URI createURI(java.lang.String address)
                                  throws java.net.MalformedURLException,
                                         java.net.URISyntaxException

Correctly escapes spaces in URIs.

Parameters:
  `address` - address to create URI for
Returns:
  URI
Throws:
  `java.net.MalformedURLException`
  `java.net.URISyntaxException`

#### isAbsolute

    public static boolean isAbsolute(java.lang.String location)

Verifies if a location is provided in absolute form.

Parameters:
  `location` - location string
Returns:
  `true` for absolute locations

#### toProjectRelativeLocation

    public static java.lang.String toProjectRelativeLocation(IResource resource)

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

    public static java.lang.String toAbsoluteLocation(java.lang.Object location,
                                                      java.lang.Object parent)

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) location
  `parent` - parent object to resolve from
Returns:
  resolved location string or `null`

#### toRelativeLocation

    public static java.lang.String toRelativeLocation(java.lang.Object resource,
                                                      java.lang.Object parent)

Create a relative path from one resource to another.

Parameters:
  `resource` - resource to create a relative path for
  `parent` - resource to create relative path from
Returns:
  relative path for resource

#### getInputStream

    public static java.io.InputStream getInputStream(java.lang.Object location)

Get the content of a resource location as `InputStream`.

Parameters:
  `location` - location to read from
Returns:
  `InputStream` or `null`

#### toString

    public static java.lang.String toString(java.lang.Object location)

Reads from a resource into a string. Does not throw any exceptions, instead returns `null` 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

    public static java.lang.String toString(java.io.InputStream stream)
                                     throws java.io.IOException

Convert an input stream to a string.

Parameters:
  `stream` - input string to read from
Returns:
  string containing stream data
Throws:
  `java.io.IOException` - thrown on problems with input stream

#### toString

    public static java.lang.String toString(java.io.Reader reader)
                                     throws java.io.IOException

Read characters from a `Reader` and return its string representation. Can be used to convert an `InputStream` to a string.

Parameters:
  `reader` - reader to read from
Returns:
  string content of reader
Throws:
  `java.io.IOException` - when reader is not accessible

#### toFile

    public static java.io.File toFile(java.lang.Object resource)

Get the filesystem representation of a given resource. Does not try to resolve the resource.

Parameters:
  `resource` - resource to convert. Either a `File` or an `IResource`
Returns:
  file or folder in the local file system

#### createFolder

    public static void createFolder(IContainer folder)
                             throws CoreException

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