com.h3c.util

## Class FilePathUtils

- java.lang.Object
- - com.h3c.util.FilePathUtils

-     public final class FilePathUtils
      extends Object

  Set of static utilities for file path manipulation.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FilePathUtils()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `addSeparator(String path, char fps)` Return the path with the specified file separator added at the end, or the original path if it already has a trailing path separator.
    `static String` | `childPath(String parentPath, String path, char fps)` Return the next child path segment given the model path and base parent path.
    `static String` | `combinePath(String path, String name, char fps)` Return the path that results when the child name is catenated to the parent path and separated using the given file path separator.
    `static String` | `drive(String path)` Return the drive designation extracted from the specified path.
    `static String` | `extension(String name)` Return the extension of the given file leaf name, i.e.
    `static String` | `extension(String name, char fps)` Return the extension of the given file name, i.e.
    `static String` | `filename(String path, char fps)` Returns the full name of the file only, without the directory path information
    `static String` | `fullPath(String path)` Return the full path stripped of the mount-point drive letter.
    `static String` | `leafName(String path, char fps)` Return the leaf name (aka basename) segment of the path.
    `static String` | `mountPoint(String path, char fps)` Return the mount point portion of the specified path, i.e.
    `static String` | `normalizedPath(String path)` Return the specified path with all backward slash separators replaced by forward slash separators.
    `static String` | `normalizedPath(String path, boolean isDir)` Return the specified path with all backward slash separators replaced by forward slash separators.
    `static String` | `parentPath(String path, char fps)` Return the parent path of the specified path.
    `static String` | `prefixFilename(String path, char fps)` Returns the name of the file without the extension
    `static String` | `relativePath(String parentPath, String path, char fps)` Return the relative path using the supplied parent path.
    `static String` | `sansExtension(String name, char fps)` Return the path sans the extension of the given file leaf name, i.e.
    `static String` | `tmp()` Get the path to the system temporary directory.
    `static String` | `trimSeparator(String path, char fps)` Return the path with the specified file separator trimmed from the end, or the original path if it already lacks a trailing path separator.

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

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

- - ### Constructor Detail

    - #### FilePathUtils

          public FilePathUtils()

  - ### Method Detail

    - #### tmp

          public static String tmp()

      Get the path to the system temporary directory.
      Returns:
        temporary files directory path

    - #### normalizedPath

          public static String normalizedPath(String path,
                              boolean isDir)

      Return the specified path with all backward slash separators replaced by forward slash separators. In case there are no backward slashes and hence no replacements are needed, the original path will be returned.
      Parameters:
        `path` - path to be normalized
        `isDir` - boolean indicating that the path is that of a directory
      Returns:
        original path with all backward slash separators replaced by forward slash separators, or if the original path if no replacements were necessary

    - #### normalizedPath

          public static String normalizedPath(String path)

      Return the specified path with all backward slash separators replaced by forward slash separators. In case there are no backward slashes and hence no replacements are needed, the original path will be returned.
      Parameters:
        `path` - path to be normalized
      Returns:
        original path with all backward slash separators replaced by forward slash separators, or if the original path if no replacements were necessary

    - #### parentPath

          public static String parentPath(String path,
                          char fps)

      Return the parent path of the specified path.
      Parameters:
        `path` - path from which to extract the parent path
        `fps` - character representing the file path separator
      Returns:
        path shortened by one path segment

    - #### relativePath

          public static String relativePath(String parentPath,
                            String path,
                            char fps)

      Return the relative path using the supplied parent path.
      Parameters:
        `parentPath` - parent path to which the path is relative; this path is assumed to be normalized
        `path` - normalized path to be made relative
        `fps` - character representing the file path separator
      Returns:
        relative path to the parent path, sans the leading path separator

    - #### leafName

          public static String leafName(String path,
                        char fps)

      Return the leaf name (aka basename) segment of the path.
      Parameters:
        `path` - path from which to extract the leaf name
        `fps` - character representing the file path separator
      Returns:
        leaf name of the path, including the trailing path separator, if there is one

    - #### childPath

          public static String childPath(String parentPath,
                         String path,
                         char fps)

      Return the next child path segment given the model path and base parent path.
      Parameters:
        `parentPath` - parent path to use as a base
        `path` - model path from which to extract the next child using the parent path
        `fps` - character representing the file path separator
      Returns:
        child path segment relative to the given parent path

    - #### addSeparator

          public static String addSeparator(String path,
                            char fps)

      Return the path with the specified file separator added at the end, or the original path if it already has a trailing path separator.
      Parameters:
        `path` - path to which the separator should be added
        `fps` - file path separator to use if needed, which is if the parent path already does not end with a trailing path separator
      Returns:
        path with trailing path separator

    - #### trimSeparator

          public static String trimSeparator(String path,
                             char fps)

      Return the path with the specified file separator trimmed from the end, or the original path if it already lacks a trailing path separator.
      Parameters:
        `path` - path from which the separator should be trimed
        `fps` - file path separator to use if needed, which is if the path ends with a trailing path separator
      Returns:
        path without trailing path separator

    - #### combinePath

          public static String combinePath(String path,
                           String name,
                           char fps)

      Return the path that results when the child name is catenated to the parent path and separated using the given file path separator.
      Parameters:
        `path` - parent path to use as the first part of the result
        `name` - child name to append to the parent path
        `fps` - file path separator to use if needed, which is if the path already does not end with a trailing path separator
      Returns:
        combined path

    - #### mountPoint

          public static String mountPoint(String path,
                          char fps)

      Return the mount point portion of the specified path, i.e. the portion of path up to and including the first file path separator.
      Parameters:
        `path` - file path from which to extract the mount-point
        `fps` - file path separator to use for extraction of mount point
      Returns:
        mount point segment of the given path

    - #### fullPath

          public static String fullPath(String path)

      Return the full path stripped of the mount-point drive letter.
      Parameters:
        `path` - path from which to strip-off drive letter portion.
      Returns:
        path with drive letter stripped off

    - #### drive

          public static String drive(String path)

      Return the drive designation extracted from the specified path.
      Parameters:
        `path` - path from which to extract drive information
      Returns:
        drive designation

    - #### sansExtension

          public static String sansExtension(String name,
                             char fps)

      Return the path sans the extension of the given file leaf name, i.e. the portion following the last occurrence of the extension separator '.'.

      Assumes a leaf file name is supplied. Returns an empty string if there is no extension found.

      Parameters:
        `name` - file name from which to extract the extension
        `fps` - file path separator
      Returns:
        extension portion of the file name or empty string if none

    - #### extension

          public static String extension(String name,
                         char fps)

      Return the extension of the given file name, i.e. the portion following the last occurrence of the extension separator '.'.

      Returns an empty string if there is no extension found.

      Parameters:
        `name` - file name from which to extract the extension
        `fps` - file path separator
      Returns:
        extension portion of the file name or empty string if none

    - #### extension

          public static String extension(String name)

      Return the extension of the given file leaf name, i.e. the portion following the last occurrence of the extension separator '.'.

      Assumes a leaf file name is supplied. Returns an empty string if there is no extension found.

      Parameters:
        `name` - file name from which to extract the extension
      Returns:
        extension portion of the file name or empty string if none

    - #### prefixFilename

          public static String prefixFilename(String path,
                              char fps)

      Returns the name of the file without the extension
      Parameters:
        `path` - full name of the file or path
        `fps` - file path separator
      Returns:
        the given file name/path without the extension

    - #### filename

          public static String filename(String path,
                        char fps)

      Returns the full name of the file only, without the directory path information
      Parameters:
        `path` - full name of the file or path
        `fps` - file path separator
      Returns:
        the leaf file name, without the directory path

Copyright © 2014. All Rights Reserved.