Interface PathBuilder

  • All Known Implementing Classes:
    SimplePathBuilder

    public interface PathBuilder
    Interface that permits to build absolute paths from relative paths and relative paths from absolute paths.

    This interface supports both File and URL.

    Since:
    15.0
    Version:
    17.0 2020-01-04 14:41:40
    Author:
    Stéphane GALLAND
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    inputoutput
    • Method Detail

      • setCurrentDirectory

        void setCurrentDirectory​(String currentDirectory)
        Set the default/current directory used to make absolute the reltive paths.

        This function tries to build an URL, and if it fails it assumed that the given string is a filename to pass to File.

        Parameters:
        currentDirectory - is the default/current directory used to make absolute the reltive paths.
      • setCurrentDirectory

        void setCurrentDirectory​(File currentDirectory)
        Set the default/current directory used to make absolute the reltive paths.
        Parameters:
        currentDirectory - is the default/current directory used to make absolute the reltive paths.
      • setCurrentDirectory

        void setCurrentDirectory​(URL currentDirectory)
        Set the default/current directory used to make absolute the reltive paths.
        Parameters:
        currentDirectory - is the default/current directory used to make absolute the reltive paths.
      • getCurrentDirectoryFile

        @Pure
        File getCurrentDirectoryFile()
        Replies the default/current directory used to make absolute the reltive paths.

        If the current directory is a File, it is replied. If the current directory is an URL with "file" protocol, its path is replied. In all other cases the user home directory is replied, or the default directory if the user home is unavailable.

        Returns:
        the default/current directory used to make absolute the reltive paths.
        See Also:
        getCurrentDirectoryString(), getCurrentDirectoryURL()
      • getCurrentDirectoryURL

        @Pure
        URL getCurrentDirectoryURL()
        Replies the default/current directory used to make absolute the reltive paths.

        This function replies the URL of the current directory even if the current directory was set with a File.

        Returns:
        the default/current directory used to make absolute the reltive paths.
        See Also:
        getCurrentDirectoryFile(), getCurrentDirectoryString()
      • makeAbsolute

        @Pure
        default URL makeAbsolute​(File filename)
        Make the given filename absolute.
        Parameters:
        filename - the file.
        Returns:
        absolute equivalent name.
      • makeAbsolute

        @Pure
        default URL makeAbsolute​(URL filename)
        Make the given filename absolute.
        Parameters:
        filename - the file.
        Returns:
        absolute equivalent name.
      • makeAbsolute

        @Pure
        default URL makeAbsolute​(String filename)
        Make the given filename absolute.

        If the given filename is an URL, the external form of the URL is replied.

        Parameters:
        filename - the file.
        Returns:
        absolute equivalent name or null if it is impossible to obtain an URL.
      • makeRelative

        @Pure
        default File makeRelative​(File filename)
                           throws IOException
        Make the given filename relative.
        Parameters:
        filename - the file.
        Returns:
        relative equivalent name.
        Throws:
        IOException - in case of error.
      • makeRelative

        @Pure
        default File makeRelative​(URL filename)
                           throws IOException
        Make the given filename relative.
        Parameters:
        filename - the file.
        Returns:
        relative equivalent name.
        Throws:
        IOException - in case of error.
      • makeRelative

        @Pure
        default File makeRelative​(String filename)
                           throws IOException
        Make the given filename relative.

        If the given filename is an URL, the external form of the URL is replied.

        Parameters:
        filename - filename.
        Returns:
        relative equivalent name or null if it is impossible to obtain an File.
        Throws:
        IOException - in case of error.
      • toShorterURL

        @Pure
        default URL toShorterURL​(URL url)
        Try to make the given URL shorter in its form.
        Parameters:
        url - the URL to convert.
        Returns:
        the shorter URL or the url itself.