Class URIUtil


  • public final class URIUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      URIUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String decode​(java.lang.String source)  
      static java.lang.String encodePath​(java.lang.String path)  
      static int getDefaultPort​(java.lang.String scheme)  
      static boolean isRemote​(java.net.URI uri)
      Answer if the given URL is on the local system or remote
      static java.util.Optional<java.nio.file.Path> pathFromURI​(java.lang.String uriString)
      Attempts to fetch a path on the file system for the given URI string.
      static java.util.Optional<java.nio.file.Path> pathFromURI​(java.net.URI uri)
      Attempts to fetch a path on the file system for the given URI.
      static java.net.URI resolve​(java.net.URI baseURI, java.lang.String reference)
      Resolves a URI reference against a base URI.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • URIUtil

        public URIUtil()
    • Method Detail

      • resolve

        public static java.net.URI resolve​(java.net.URI baseURI,
                                           java.lang.String reference)
                                    throws java.net.URISyntaxException
        Resolves a URI reference against a base URI. Work-around for bugs in java.net.URI (e.g.http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535)
        Parameters:
        baseURI -
        reference -
        Returns:
        the resolved URI
        Throws:
        java.net.URISyntaxException
      • pathFromURI

        public static java.util.Optional<java.nio.file.Path> pathFromURI​(java.lang.String uriString)
        Attempts to fetch a path on the file system for the given URI string. Tries a few more tricks than the standard method of Paths.get(new URI(uriString)) - it can handle plain paths, and also nested URI pseudo-schemes like reference: and jar:. Examples:
        • /path/to/file => /path/to/file
        • reference:file:/path/to/file => /path/to/file
        • jar:file:/path/to/file.jar!/some/contained/element => /path/to/file.jar
        • http://server/path/to/file => null
        Parameters:
        uriString - The URI string for which we are attempting to construct a path.
        Returns:
        The method's best guess as to which file on the local filesystem this URI refers, or an empty Optional if it's invalid or not a local filesystem URI.
      • pathFromURI

        public static java.util.Optional<java.nio.file.Path> pathFromURI​(java.net.URI uri)
        Attempts to fetch a path on the file system for the given URI. Tries a few more tricks than the standard method of Paths.get(uri) - it can handle plain paths, and also nested URI pseudo-schemes like reference: and jar:. Examples:
        • /path/to/file => /path/to/file
        • reference:file:/path/to/file => /path/to/file
        • jar:file:/path/to/file.jar!/some/contained/element => /path/to/file.jar
        • http://server/path/to/file => null
        Parameters:
        uri - The URI for which we are attempting to construct a path.
        Returns:
        The method's best guess as to which file on the local filesystem this URI refers, or an empty Optional if it's invalid or not a local filesystem URI.
      • isRemote

        public static boolean isRemote​(java.net.URI uri)
        Answer if the given URL is on the local system or remote
      • getDefaultPort

        public static int getDefaultPort​(java.lang.String scheme)
      • encodePath

        public static java.lang.String encodePath​(java.lang.String path)
      • decode

        public static java.lang.String decode​(java.lang.String source)