Class ResourceTools

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

public final class ResourceTools extends Object
  • Field Details

    • VIRTUAL_WINDOWS_ROOT

      public static final 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 Details

    • resolve

      public static Object resolve(Object location, 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(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(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(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 Object resolve(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 URI createURI(String address) throws MalformedURLException, URISyntaxException
      Correctly escapes spaces in URIs.
      Parameters:
      address - address to create URI for
      Returns:
      URI
      Throws:
      MalformedURLException
      URISyntaxException
    • isAbsolute

      public static boolean isAbsolute(String location)
      Verifies if a location is provided in absolute form.
      Parameters:
      location - location string
      Returns:
      true for absolute locations
    • toProjectRelativeLocation

      public static String toProjectRelativeLocation(org.eclipse.core.resources.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 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
    • toRelativeLocation

      public static String toRelativeLocation(Object resource, 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 InputStream getInputStream(Object location)
      Get the content of a resource location as InputStream.
      Parameters:
      location - location to read from
      Returns:
      InputStream or null
    • toString

      public static String toString(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 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
    • toFile

      public static File toFile(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(org.eclipse.core.resources.IContainer folder) throws org.eclipse.core.runtime.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:
      org.eclipse.core.runtime.CoreException - when folder could not be created