Class Files

java.lang.Object
slash.common.io.Files

public class Files extends Object
Provides file and file name functionality.
Author:
Christian Pesch
  • Constructor Details

    • Files

      public Files()
  • Method Details

    • getExtension

      public static String getExtension(File file)
      Parameters:
      file - the file to find the extension
      Returns:
      the extension of the file, which are the characters starting with the last dot in the file name in lowercase characters
    • getExtension

      public static String getExtension(String name)
      Parameters:
      name - the file name to find the extension
      Returns:
      the extension of a file name, which are the characters starting with the last dot in the file name in lowercase characters
    • getExtension

      public static String getExtension(URL url)
    • getExtension

      public static String getExtension(List<URL> urls)
    • resolveLink

      public static ResolvableLink resolveLink(File file) throws IOException
      Resolves a file that may be an indirection to another file or directory: a Windows shortcut (.lnk) or a macOS Finder alias.
      Parameters:
      file - the file to inspect
      Returns:
      a ResolvableLink for the target, or null if the file is not such an indirection
      Throws:
      IOException - if the file cannot be read
    • removeExtension

      public static String removeExtension(String name)
      Remove the extension of the given file name, if there is any.
      Parameters:
      name - the file name to remove the extension
      Returns:
      the file name without an extension
    • setExtension

      public static String setExtension(String name, String extension)
      Replace the extension of the given file name with the given extension.
      Parameters:
      name - the file name to replace the extension
      extension - the new extension for the file name
      Returns:
      the file name with the given extension
    • extractFileName

      public static String extractFileName(String path)
    • createReadablePath

      public static String createReadablePath(File file)
    • createReadablePath

      public static String createReadablePath(URL url)
    • shortenPath

      public static String shortenPath(String path, int maximumLength)
    • lastPathFragment

      public static String lastPathFragment(String path, int maximumLength)
    • compare

      public static int compare(File f1, File f2)
    • toFile

      public static File toFile(URL url)
    • toUrl

      public static URL toUrl(String urlOrPath) throws MalformedURLException
      Converts a URL or local (possibly relative or space-bearing) path string to a URL, falling back to file semantics when the string is not a valid absolute URI. Replaces the deprecated new URL(String).
      Throws:
      MalformedURLException
    • toUrls

      public static List<URL> toUrls(String... urls)
    • toUrls

      public static List<URL> toUrls(File... files)
    • reverse

      public static List<URL> reverse(List<URL> urls)
    • calculateConvertFileName

      public static String calculateConvertFileName(File file, String extension, int fileNameLength)
    • createTargetFiles

      public static File[] createTargetFiles(File pattern, int fileCount, String extension, int fileNameLength)
    • checkFile

      public static void checkFile(File file) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • checkDirectory

      public static void checkDirectory(File directory) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • writePartialFile

      public static void writePartialFile(InputStream inputStream, long fileSize, File file) throws IOException
      Throws:
      IOException
    • generateChecksum

      public static String generateChecksum(InputStream inputStream) throws IOException
      Throws:
      IOException
    • generateChecksum

      public static String generateChecksum(File file) throws IOException
      Throws:
      IOException
    • getLastModified

      public static CompactCalendar getLastModified(File file)
    • setLastModified

      public static void setLastModified(File file, Long lastModified) throws IOException
      Throws:
      IOException
    • setLastModified

      public static void setLastModified(File file, CompactCalendar lastModified) throws IOException
      Throws:
      IOException
    • collectFiles

      public static List<File> collectFiles(File path, String... extensions)
      Collects files below the given path with the given extension(s). If path is a directory, the collection recursively descends the directory tree. The extension comparison is case-insensitive
      Parameters:
      path - the path to collect files below
      extensions - the case insensitively compare extensions
      Returns:
      the list of files found below the given path and with the given extension(s)
    • collectFiles

      public static List<File> collectFiles(List<File> files)
    • absolutize

      public static File absolutize(File file)
    • findExistingPath

      public static File findExistingPath(File path)
    • recursiveDelete

      public static void recursiveDelete(File path) throws IOException
      Throws:
      IOException
    • asLogString

      public static <T> String asLogString(List<T> list)
      Joins a list into a human-readable, English, uncapped string for log output, e.g. 'a',\n'b' and\n'c'. For user-facing dialog text use the localized, capped formatter in the GUI layer instead.