Class URIUtils


  • public final class URIUtils
    extends Object
    General URI manipulation utilities.
    Author:
    avpinchuk
    • Method Detail

      • openStream

        public static InputStream openStream​(URI uri)
                                      throws IOException
        Opens a connection to the uri and returns an InputStream for reading from that connection.

        If uri represents an HTTP(S) resource and contains the user info part, set the Authorization header with Basic authentication credentials.

        Parameters:
        uri - the URI to returns InputStream from.
        Returns:
        An input stream for reading from the URI.
        Throws:
        IOException - if an I/O exception occurs.
        ClassCastException - if the uri is not a file and does not represent HTTP(S) resource.
      • convertToFile

        public static File convertToFile​(URI uri)
                                  throws IOException
        Downloads uri to a temporary file.
        Parameters:
        uri - the URI to download.
        Returns:
        The temporary file.
        Throws:
        IOException - if an I/O exception occurs.
        ClassCastException - if the uri is not a file and does not represent HTTP(S) resource.
      • exists

        public static boolean exists​(URI uri)
                              throws IOException
        Tests whether resource represented by uri exists.
        Parameters:
        uri - the URI to test.
        Returns:
        true if a resource exists; false otherwise.
        Throws:
        IOException - if an I/O error occurs.
        ClassCastException - if the uri is not a file and does not represent HTTP(S) resource.
      • hasFileScheme

        public static boolean hasFileScheme​(URI uri)
        Tests whether uri has the file scheme.
        Parameters:
        uri - the URI to test.
        Returns:
        true if uri has the file scheme; false otherwise.