Class FormatExtensions

Object
FormatExtensions

public class FormatExtensions extends Object
File extensions for various formats.
Author:
Owen Feehan
  • Method Details

    • allImageExtensions

      public static String[] allImageExtensions()
      The extensions of all image file formats as enumerated in ImageFileFormat.

      Note that some formats may have more than one extension e.g. tif and tiff.

      Returns:
      an array of extensions for all the image file formats.
    • matches

      public static boolean matches(String filePath, String extensionWithoutLeadingPeriod)
      Does a filePath match an extension?
      Parameters:
      filePath - file-path to match, case irrelevant
      extensionWithoutLeadingPeriod - the extension to match (in lower-case, without a leading period)
      Returns:
      true if the filePath ends with the expected extension
    • changeExtension

      public static Path changeExtension(Path path, NonImageFileFormat formatToChangeFrom, FileFormat formatToAssign) throws OperationFailedException
      Change the extension in a path.
      Parameters:
      path - the path to change if the extension matches
      formatToChangeFrom - the format to change from (a match occurs against the associated extension)
      formatToAssign - the format to assign (the default extension is assigned)
      Returns:
      a path with the extension changed
      Throws:
      OperationFailedException - if the unchanged path does not match formatToChangeFrom.
    • removeAnyLeadingPeriod

      public static String removeAnyLeadingPeriod(String str)
      Removes a single leading period from a string, if one exists.
      Parameters:
      str - a string that may or may not have a leading period.
      Returns:
      a string with the leading period remove, if it exists.
    • normalizeToLowerCase

      public static String normalizeToLowerCase(String extension)
      Normalize an extension to lower-case.

      This function exists to achieve normalization in a consistent way across many calls.

      Parameters:
      extension - the extension to normalize.
      Returns:
      a lower-case version of extension.