Class FileUtils

java.lang.Object
nl.talsmasoftware.umldoclet.util.FileUtils

public final class FileUtils extends Object
Contains static utility methods for files.
Author:
Sjoerd Talsma
  • Method Details

    • relativePath

      public static String relativePath(File from, File to)
      Returns the relative path from one file to another.
      Parameters:
      from - The source file.
      to - The target file.
      Returns:
      The relative path from the source to the target file.
    • ensureParentDir

      public static File ensureParentDir(File file)
      Ensure that the parent directory exists for the specified file.

      This will attempt to create the parent directory if it does not exist yet.

      Parameters:
      file - The file verify directory existence for.
      Returns:
      The specified file.
      Throws:
      IllegalStateException - in case the parent directory did not yet exist and could not be created either.
    • fileNameOf

      public static String fileNameOf(String path)
      Shortcut implementation that determines the substring after the last Windows or *nix path separator.
      Parameters:
      path - The path to return filename of.
      Returns:
      The part of the specified part after the last slash or backslash.
    • withoutExtension

      public static String withoutExtension(String path)
    • openReaderTo

      public static Reader openReaderTo(String basedir, URI uri, String charsetName) throws IOException
      Opens a reader to the specified URI.

      If the call uri.toURL().openStream() succeeds, a reader is wrapped and returned. Otherwise, if the URI is absolute, an attempt is made to open it as a file. If this also fails, a last effort is made to open the uri relative to the specified basedir directory.

      Parameters:
      basedir - The base directory to use if the URI turns out to be a relative file link.
      uri - The URI to read from.
      charsetName - The character set to use for reading.
      Returns:
      The opened reader.
      Throws:
      IOException - in case the call to uri.toURL().openStream() threw an I/O Exception.
    • hasExtension

      public static boolean hasExtension(Object file, String extension)