Enum Class FileSystem
- All Implemented Interfaces:
Serializable,Comparable<FileSystem>,Constable
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
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate final booleanprivate final char[]private static final booleanIstrueif this is Linux.private static final booleanIstrueif this is Mac.private static final booleanIstrueif this is Windows.private final intprivate final intprivate static final StringThe prefix String for all Windows OS.private final String[]private final boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateFileSystem(boolean caseSensitive, boolean casePreserving, int maxFileLength, int maxPathLength, char[] illegalFileNameChars, String[] reservedFileNames, boolean supportsDriveLetter) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic FileSystemGets the current file system.char[]Gets a cloned copy of the illegal characters for this file system.intGets the maximum length for file names.intGets the maximum length of the path to a file.private static booleangetOsMatchesName(String osNamePrefix) Decides if the operating system matches.String[]Gets a cloned copy of the reserved file names.private static StringgetSystemProperty(String property) Gets a System property, defaulting tonullif the property cannot be read.booleanWhether this file system preserves case.booleanWhether this file system is case-sensitive.private booleanisIllegalFileNameChar(char c) Returnstrueif the given character is illegal in a file name,falseotherwise.booleanisLegalFileName(CharSequence candidate) Checks if a candidate file name (without a path) such as"filename.ext"or"filename"is a potentially legal file name.private static booleanisOsNameMatch(String osName, String osNamePrefix) Decides if the operating system matches.booleanisReservedFileName(CharSequence candidate) Returns whether the given string is a reserved file name.booleanTests whether this file system support driver letters.toLegalFileName(String candidate, char replacement) Converts a candidate file name (without a path) like"filename.ext"or"filename"to a legal file name.static FileSystemReturns the enum constant of this class with the specified name.static FileSystem[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
GENERIC
Generic file system. -
LINUX
Linux file system. -
MAC_OSX
MacOS file system. -
WINDOWS
Windows file system.The reserved characters are defined in the Naming Conventions (microsoft.com).
- See Also:
-
-
Field Details
-
IS_OS_LINUX
private static final boolean IS_OS_LINUXIs
trueif this is Linux.The field will return
falseifOS_NAMEisnull. -
IS_OS_MAC
private static final boolean IS_OS_MACIs
trueif this is Mac.The field will return
falseifOS_NAMEisnull. -
OS_NAME_WINDOWS_PREFIX
The prefix String for all Windows OS.- See Also:
-
IS_OS_WINDOWS
private static final boolean IS_OS_WINDOWSIs
trueif this is Windows.The field will return
falseifOS_NAMEisnull. -
casePreserving
private final boolean casePreserving -
caseSensitive
private final boolean caseSensitive -
illegalFileNameChars
private final char[] illegalFileNameChars -
maxFileNameLength
private final int maxFileNameLength -
maxPathLength
private final int maxPathLength -
reservedFileNames
-
supportsDriveLetter
private final boolean supportsDriveLetter
-
-
Constructor Details
-
FileSystem
private FileSystem(boolean caseSensitive, boolean casePreserving, int maxFileLength, int maxPathLength, char[] illegalFileNameChars, String[] reservedFileNames, boolean supportsDriveLetter) Constructs a new instance.- Parameters:
caseSensitive- Whether this file system is case sensitive.casePreserving- Whether this file system is case preserving.maxFileLength- The maximum length for file names. The file name does not include folders.maxPathLength- The maximum length of the path to a file. This can include folders.illegalFileNameChars- Illegal characters for this file system.reservedFileNames- The reserved file names.supportsDriveLetter- Whether this file system support driver letters.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified nameNullPointerException- if the argument is null
-
getCurrent
Gets the current file system.- Returns:
- the current file system
-
getOsMatchesName
Decides if the operating system matches.- Parameters:
osNamePrefix- the prefix for the os name- Returns:
- true if matches, or false if not or can't determine
-
getSystemProperty
Gets a System property, defaulting to
nullif the property cannot be read.If a
SecurityExceptionis caught, the return value isnulland a message is written toSystem.err.- Parameters:
property- the system property name- Returns:
- the system property value or
nullif a security problem occurs
-
isOsNameMatch
Decides if the operating system matches.This method is package private instead of private to support unit test invocation.
- Parameters:
osName- the actual OS nameosNamePrefix- the prefix for the expected OS name- Returns:
- true if matches, or false if not or can't determine
-
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
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.
-
isIllegalFileNameChar
private boolean isIllegalFileNameChar(char c) Returnstrueif the given character is illegal in a file name,falseotherwise.- Parameters:
c- the character to test- Returns:
trueif the given character is illegal in a file name,falseotherwise.
-
isLegalFileName
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 exceedsgetMaxFileNameLength(), 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:
trueif the candidate name is legal
-
isReservedFileName
Returns whether the given string is a reserved file name.- Parameters:
candidate- the string to test- Returns:
trueif the given string is a reserved file name.
-
supportsDriveLetter
public boolean supportsDriveLetter()Tests whether this file system support driver letters.Windows supports driver letters as do other operating systems. Whether these other OS's still support Java like OS/2, is a different matter.
- Returns:
- whether this file system support driver letters.
- Since:
- 2.9.0
- See Also:
-
toLegalFileName
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 thereplacementcharacter. If the file name length exceedsgetMaxFileNameLength(), then the name is truncated togetMaxFileNameLength().- 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
-