Class ResourceUtil

java.lang.Object
com.alipay.sofa.common.utils.ResourceUtil

public class ResourceUtil extends Object
Since:
1.0.17
Author:
qilong.zql, Juergen Hoeller
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    URL protocol for a file in the file system: "file"
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static File
    getFile(URL resourceUrl)
    Resolve the given resource URL to a java.io.File, i.e.
    static File
    getFile(URL resourceUrl, String description)
    Resolve the given resource URL to a java.io.File, i.e.
    static URI
    toURI(String location)
    Create a URI instance for the given location String, replacing spaces with "%20" URI encoding first.
    static URI
    toURI(URL url)
    Create a URI instance for the given URL, replacing spaces with "%20" URI encoding first.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • URL_PROTOCOL_FILE

      public static final String URL_PROTOCOL_FILE
      URL protocol for a file in the file system: "file"
      See Also:
  • Constructor Details

    • ResourceUtil

      public ResourceUtil()
  • Method Details

    • getFile

      public static File getFile(URL resourceUrl) throws FileNotFoundException
      Resolve the given resource URL to a java.io.File, i.e. to a file in the file system.
      Parameters:
      resourceUrl - the resource URL to resolve
      Returns:
      a corresponding File object
      Throws:
      FileNotFoundException - if the URL cannot be resolved to a file in the file system
    • getFile

      public static File getFile(URL resourceUrl, String description) throws FileNotFoundException
      Resolve the given resource URL to a java.io.File, i.e. to a file in the file system.
      Parameters:
      resourceUrl - the resource URL to resolve
      description - a description of the original resource that the URL was created for (for example, a class path location)
      Returns:
      a corresponding File object
      Throws:
      FileNotFoundException - if the URL cannot be resolved to a file in the file system
    • toURI

      public static URI toURI(URL url) throws URISyntaxException
      Create a URI instance for the given URL, replacing spaces with "%20" URI encoding first.
      Parameters:
      url - the URL to convert into a URI instance
      Returns:
      the URI instance
      Throws:
      URISyntaxException - if the URL wasn't a valid URI
      See Also:
    • toURI

      public static URI toURI(String location) throws URISyntaxException
      Create a URI instance for the given location String, replacing spaces with "%20" URI encoding first.
      Parameters:
      location - the location String to convert into a URI instance
      Returns:
      the URI instance
      Throws:
      URISyntaxException - if the location wasn't a valid URI