org.eclipse.ease.tools

## Class ResourceTools

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

    public final class ResourceTools
    extends Object

### Method Summary

All Methods Static Methods Concrete Methods
`static boolean` `exists(Object location)` Verifies that a readable source (file/stream) exists at location.
`static IFile` `getActiveFile()` Returns the currently active file in the workbench.
`static InputStream` `getInputStream(Object location)`
`static Object` `getResource(Object location)` Get an existing resource (file/folder/URI).
`static Object` `resolveFile(Object location, Object parent, boolean exists)` Resolve a file from a given input location.
`static Object` `resolveFolder(Object location, Object parent, boolean exists)` Resolve a folder from a given input location.
`static String` `resourceToString(Object location)` Reads from a resource into a string.
`static String` `toAbsoluteLocation(Object location, Object parent)` Resolve a given location to an absolute location URI.
`static IPath` `toPath(String location)` Convert a location to a path in the workspace.
`static String` `toProjectRelativeLocation(Object location, Object parent)`
`static String` `toString(InputStream stream)` Convert an input stream to a string.
`static String` `toString(Reader reader)` Read characters from a `Reader` and return its string representation.
`static URI` `toURI(IPath path)` Converts an `IPath` representing a workspace resource to an `URI`.

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

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

### Method Detail

#### resolveFile

    public static Object resolveFile(Object location,
                                     Object parent,
                                     boolean exists)

Resolve a file from a given input location. Tries to resolve absolute and relative files within the workspace or file system. Relative files will be resolved against a provided parent location.

Parameters:
  `location` - file location to be resolved
  `parent` - location of parent resource
  `exists` - return file only if it exists, if `false` the file is returned whether it exists or not
Returns:
  `IFile`, `File` or `null`

#### resolveFolder

    public static Object resolveFolder(Object location,
                                       Object parent,
                                       boolean exists)

Resolve a folder from a given input location. Tries to resolve absolute and relative folders within the workspace or file system. Relative folders will be resolved against a provided parent location.

Parameters:
  `location` - folder location to be resolved
  `parent` - location of parent resource
  `exists` - return folder only if it exists
Returns:
  `IContainer`, `File` or `null`

#### toProjectRelativeLocation

    public static String toProjectRelativeLocation(Object location,
                                                   Object parent)

#### toAbsoluteLocation

    public static String toAbsoluteLocation(Object location,
                                            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`

#### exists

    public static boolean exists(Object location)

Verifies that a readable source (file/stream) exists at location.

Parameters:
  `location` - location to verify
Returns:
  `true` when location is readable

#### getResource

    public static Object getResource(Object location)

Get an existing resource (file/folder/URI).

Parameters:
  `location` - location to look up
Returns:
  resource, either `File`, `IResource` or `URI`

#### getInputStream

    public static InputStream getInputStream(Object location)

#### resourceToString

    public static String resourceToString(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

#### toURI

    public static URI toURI(IPath path)

Converts an `IPath` representing a workspace resource to an `URI`.

Parameters:
  `path` - The path to convert
Returns:
  The URI representing the provided path

#### toPath

    public static IPath toPath(String location)

Convert a location to a path in the workspace.

Parameters:
  `location` - location to convert (workspace://...)
Returns:

#### toString

    public static String toString(InputStream stream)
                           throws IOException

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

    public static String toString(Reader reader)
                           throws 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:
  `IOException` - when reader is not accessible

#### getActiveFile

    public static IFile getActiveFile()

Returns the currently active file in the workbench. Must be run on UI thread.

Returns:
  Currently active file if successful or `null` in case of error.