org.apache.commons.io

## Enum FileSystem

- java.lang.Object
- - java.lang.Enum<FileSystem>
  - - org.apache.commons.io.FileSystem

- All Implemented Interfaces:
    Serializable, Comparable<FileSystem>

      public enum FileSystem
      extends Enum<FileSystem>

  Abstracts an OS' file system details, currently supporting the single use case of converting a file name String to a legal file name with `toLegalFileName(String, char)`.

  The starting point of any operation is `getCurrent()` which gets you the enum for the file system that matches the OS hosting the running JVM.

  Since:
    2.7

- - ### Enum Constant Summary

    Enum Constants
    Enum Constant and Description
    `GENERIC` Generic file system.
    `LINUX` Linux file system.
    `MAC_OSX` MacOS file system.
    `WINDOWS` Windows file system.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static FileSystem` | `getCurrent()` Gets the current file system.
    `char[]` | `getIllegalFileNameChars()` Gets a cloned copy of the illegal characters for this file system.
    `int` | `getMaxFileNameLength()` Gets the maximum length for file names.
    `int` | `getMaxPathLength()` Gets the maximum length of the path to a file.
    `String[]` | `getReservedFileNames()` Gets a cloned copy of the reserved file names.
    `boolean` | `isCasePreserving()` Whether this file system preserves case.
    `boolean` | `isCaseSensitive()` Whether this file system is case-sensitive.
    `boolean` | `isLegalFileName(CharSequence candidate)` Checks if a candidate file name (without a path) such as `"filename.ext"` or `"filename"` is a potentially legal file name.
    `boolean` | `isReservedFileName(CharSequence candidate)` Returns whether the given string is a reserved file name.
    `String` | `toLegalFileName(String candidate, char replacement)` Converts a candidate file name (without a path) like `"filename.ext"` or `"filename"` to a legal file name.
    `static FileSystem` | `valueOf(String name)` Returns the enum constant of this type with the specified name.
    `static FileSystem[]` | `values()` Returns an array containing the constants of this enum type, in the order they are declared.

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

      `clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

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

      `getClass, notify, notifyAll, wait, wait, wait`

- - ### Enum Constant Detail

    - #### GENERIC

          public static final FileSystem GENERIC

      Generic file system.

    - #### LINUX

          public static final FileSystem LINUX

      Linux file system.

    - #### MAC_OSX

          public static final FileSystem MAC_OSX

      MacOS file system.

    - #### WINDOWS

          public static final FileSystem WINDOWS

      Windows file system.

  - ### Method Detail

    - #### values

          public static FileSystem[] values()

      Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:

          for (FileSystem c : FileSystem.values())
              System.out.println(c);

      Returns:
        an array containing the constants of this enum type, in the order they are declared

    - #### valueOf

          public static FileSystem valueOf(String name)

      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
        `name` - the name of the enum constant to be returned.
      Returns:
        the enum constant with the specified name
      Throws:
        `IllegalArgumentException` - if this enum type has no constant with the specified name
        `NullPointerException` - if the argument is null

    - #### getCurrent

          public static FileSystem getCurrent()

      Gets the current file system.
      Returns:
        the current file system

    - #### getIllegalFileNameChars

          public char[] getIllegalFileNameChars()

      Gets a cloned copy of the illegal characters for this file system.
      Returns:
        the illegal characters for this file system.

    - #### getMaxFileNameLength

          public int getMaxFileNameLength()

      Gets the maximum length for file names. The file name does not include folders.
      Returns:
        the maximum length for file names.

    - #### getMaxPathLength

          public int getMaxPathLength()

      Gets the maximum length of the path to a file. This can include folders.
      Returns:
        the maximum length of the path to a file.

    - #### getReservedFileNames

          public String[] getReservedFileNames()

      Gets a cloned copy of the reserved file names.
      Returns:
        the reserved file names.

    - #### isCasePreserving

          public boolean isCasePreserving()

      Whether this file system preserves case.
      Returns:
        Whether this file system preserves case.

    - #### isCaseSensitive

          public boolean isCaseSensitive()

      Whether this file system is case-sensitive.
      Returns:
        Whether this file system is case-sensitive.

    - #### isLegalFileName

          public boolean isLegalFileName(CharSequence candidate)

      Checks if a candidate file name (without a path) such as `"filename.ext"` or `"filename"` is a potentially legal file name. If the file name length exceeds `getMaxFileNameLength()`, or if it contains an illegal character then the check fails.
      Parameters:
        `candidate` - a candidate file name (without a path) like `"filename.ext"` or `"filename"`
      Returns:
        `true` if the candidate name is legal

    - #### isReservedFileName

          public boolean isReservedFileName(CharSequence candidate)

      Returns whether the given string is a reserved file name.
      Parameters:
        `candidate` - the string to test
      Returns:
        `true` if the given string is a reserved file name.

    - #### toLegalFileName

          public String toLegalFileName(String candidate,
                                        char replacement)

      Converts a candidate file name (without a path) like `"filename.ext"` or `"filename"` to a legal file name. Illegal characters in the candidate name are replaced by the `replacement` character. If the file name length exceeds `getMaxFileNameLength()`, then the name is truncated to `getMaxFileNameLength()`.
      Parameters:
        `candidate` - a candidate file name (without a path) like `"filename.ext"` or `"filename"`
        `replacement` - Illegal characters in the candidate name are replaced by this character
      Returns:
        a String without illegal characters

Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.