public enum FileSystem extends java.lang.Enum<FileSystem>
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.
Enum Constant and Description |
---|
GENERIC
Generic file system.
|
LINUX
Linux file system.
|
MAC_OSX
MacOS file system.
|
WINDOWS
Windows file system.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
casePreserving |
private boolean |
caseSensitive |
private char[] |
illegalFileNameChars |
private static boolean |
IS_OS_LINUX
Is
true if this is Linux. |
private static boolean |
IS_OS_MAC
Is
true if this is Mac. |
private static boolean |
IS_OS_WINDOWS
Is
true if this is Windows. |
private int |
maxFileNameLength |
private int |
maxPathLength |
private static java.lang.String |
OS_NAME_WINDOWS_PREFIX
The prefix String for all Windows OS.
|
private java.lang.String[] |
reservedFileNames |
private boolean |
supportsDriveLetter |
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.
|
private static boolean |
getOsMatchesName(java.lang.String osNamePrefix)
Decides if the operating system matches.
|
java.lang.String[] |
getReservedFileNames()
Gets a cloned copy of the reserved file names.
|
private static java.lang.String |
getSystemProperty(java.lang.String property)
Gets a System property, defaulting to
null if the property cannot be read. |
boolean |
isCasePreserving()
Whether this file system preserves case.
|
boolean |
isCaseSensitive()
Whether this file system is case-sensitive.
|
private boolean |
isIllegalFileNameChar(char c)
Returns
true if the given character is illegal in a file name, false otherwise. |
boolean |
isLegalFileName(java.lang.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 boolean |
isOsNameMatch(java.lang.String osName,
java.lang.String osNamePrefix)
Decides if the operating system matches.
|
boolean |
isReservedFileName(java.lang.CharSequence candidate)
Returns whether the given string is a reserved file name.
|
boolean |
supportsDriveLetter()
Tests whether this file system support driver letters.
|
java.lang.String |
toLegalFileName(java.lang.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(java.lang.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.
|
public static final FileSystem GENERIC
public static final FileSystem LINUX
public static final FileSystem MAC_OSX
public static final FileSystem WINDOWS
The reserved characters are defined in the Naming Conventions (microsoft.com).
private static final boolean IS_OS_LINUX
Is true
if this is Linux.
The field will return false
if OS_NAME
is null
.
private static final boolean IS_OS_MAC
Is true
if this is Mac.
The field will return false
if OS_NAME
is null
.
private static final java.lang.String OS_NAME_WINDOWS_PREFIX
private static final boolean IS_OS_WINDOWS
Is true
if this is Windows.
The field will return false
if OS_NAME
is null
.
private final boolean casePreserving
private final boolean caseSensitive
private final char[] illegalFileNameChars
private final int maxFileNameLength
private final int maxPathLength
private final java.lang.String[] reservedFileNames
private final boolean supportsDriveLetter
public static FileSystem[] values()
for (FileSystem c : FileSystem.values()) System.out.println(c);
public static FileSystem valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullpublic static FileSystem getCurrent()
private static boolean getOsMatchesName(java.lang.String osNamePrefix)
osNamePrefix
- the prefix for the os nameprivate static java.lang.String getSystemProperty(java.lang.String property)
Gets a System property, defaulting to null
if the property cannot be read.
If a SecurityException
is caught, the return value is null
and a message is written to
System.err
.
property
- the system property namenull
if a security problem occursprivate static boolean isOsNameMatch(java.lang.String osName, java.lang.String osNamePrefix)
This method is package private instead of private to support unit test invocation.
osName
- the actual OS nameosNamePrefix
- the prefix for the expected OS namepublic char[] getIllegalFileNameChars()
public int getMaxFileNameLength()
public int getMaxPathLength()
public java.lang.String[] getReservedFileNames()
public boolean isCasePreserving()
public boolean isCaseSensitive()
private boolean isIllegalFileNameChar(char c)
true
if the given character is illegal in a file name, false
otherwise.c
- the character to testtrue
if the given character is illegal in a file name, false
otherwise.public boolean isLegalFileName(java.lang.CharSequence candidate)
"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.candidate
- a candidate file name (without a path) like "filename.ext"
or "filename"
true
if the candidate name is legalpublic boolean isReservedFileName(java.lang.CharSequence candidate)
candidate
- the string to testtrue
if the given string is a reserved file name.public boolean supportsDriveLetter()
Windows supports driver letters as do other operating systems. Whether these other OS's still support Java like OS/2, is a different matter.
public java.lang.String toLegalFileName(java.lang.String candidate, char replacement)
"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()
.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