edu.northwestern.at.utils

## Class FileNameUtils

- java.lang.Object
- - edu.northwestern.at.utils.FileNameUtils

-     public class FileNameUtils
      extends java.lang.Object

  File name utilities.

  This static class provides various utility methods for manipulating file and directory names.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `FILE_SEPARATOR` File separator.
    `static MimeTypeMapper` | `mimeTypeMapper` Static mime type mapper.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `changeFileExtension(java.lang.String fileName, java.lang.String newExtension)` Change extension of file name.
    `static java.lang.String` | `createVersionedFileName(java.lang.String fileName)` Create versioned file name.
    `static java.lang.String` | `createVersionedFileName(java.lang.String fileName, int versionNumber, java.lang.String versionFormat)` Create versioned file name.
    `static java.lang.String[]` | `expandFileNameWildcards(java.lang.String[] wildCardNames)` Expand the file name wildcards.
    `static java.lang.String[]` | `expandWildcards(java.lang.String fileSpec)` Expand file name wildcard.
    `static boolean` | `fileExists(java.lang.String fileName)` Checks if a file exists.
    `static java.lang.String` | `fixFileSeparators(java.lang.String fileName)` Fix file separators.
    `static java.lang.String` | `getContentTypeFor(java.lang.String fileName)` Get MIME type for a filename.
    `static java.lang.String` | `getFileExtension(java.lang.String fileName, boolean keepPeriod)` Get file extension from file name.
    `static java.lang.String` | `stripPathName(java.lang.String fileName)` Strips path from a file name.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### mimeTypeMapper

          public static MimeTypeMapper mimeTypeMapper

      Static mime type mapper.

    - #### FILE_SEPARATOR

          public static final java.lang.String FILE_SEPARATOR

      File separator.

  - ### Method Detail

    - #### stripPathName

          public static java.lang.String stripPathName(java.lang.String fileName)

      Strips path from a file name.
      Parameters:
        `fileName` - File name with possible path.
      Returns:
        File name stripped of path.

    - #### changeFileExtension

          public static java.lang.String changeFileExtension(java.lang.String fileName,
                                             java.lang.String newExtension)

      Change extension of file name.
      Parameters:
        `fileName` - The file name whose extension is to be changed.
        `newExtension` - The new file name extension.
      Returns:
        The file name with the extension changed to new extension.

        Null returned if file name or new extension null.

    - #### getFileExtension

          public static java.lang.String getFileExtension(java.lang.String fileName,
                                          boolean keepPeriod)

      Get file extension from file name.
      Parameters:
        `fileName` - The file name whose extension is wanted.
        `keepPeriod` - Keep the period in the extension.
      Returns:
        The extension, if any, with the optional leading period.

    - #### getContentTypeFor

          public static java.lang.String getContentTypeFor(java.lang.String fileName)

      Get MIME type for a filename.
      Parameters:
        `fileName` - Name of file for which mime type is desired.
      Returns:
        The mime type, e.g., "text/plain".

        When the file name's extension is not found in the mime types hash table, a mime type of "application/octet-stream" is returned.

    - #### fileExists

          public static boolean fileExists(java.lang.String fileName)

      Checks if a file exists.
      Parameters:
        `fileName` - The file name to check for existence.
      Returns:
        True if file exists.

    - #### expandWildcards

          public static java.lang.String[] expandWildcards(java.lang.String fileSpec)

      Expand file name wildcard.
      Parameters:
        `fileSpec` - File spec possibly containing "*" wildcard.
      Returns:
        String array of expanded file names. Only file names for existing files are returned, so result may be zero length string array.

    - #### fixFileSeparators

          public static java.lang.String fixFileSeparators(java.lang.String fileName)

      Fix file separators.
      Parameters:
        `fileName` - File name to fix.
      Returns:
        File name with file separators fixed.

        Escapes the file separators if they are "\" characters.

    - #### expandFileNameWildcards

          public static java.lang.String[] expandFileNameWildcards(java.lang.String[] wildCardNames)

      Expand the file name wildcards.
      Parameters:
        `wildCardNames` - File names with possible wildcards.
      Returns:
        String array of expanded file names.

        File names expressed as URLs are left untouched and any wildcard characters they contains are left as-is.

    - #### createVersionedFileName

          public static java.lang.String createVersionedFileName(java.lang.String fileName)

      Create versioned file name.
      Parameters:
        `fileName` - Candidate file name.
      Returns:
        Possibly revised file name with version number added if candidate file name already exists.

    - #### createVersionedFileName

          public static java.lang.String createVersionedFileName(java.lang.String fileName,
                                                 int versionNumber,
                                                 java.lang.String versionFormat)

      Create versioned file name.
      Parameters:
        `fileName` - Candidate file name.
        `versionNumber` - Candidate version number .
        `versionFormat` - PrintF format for version number.
      Returns:
        Possibly revised file name with version number added if candidate file name already exists. The version number is adjusted as necessary.