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 int |
blockSize |
private boolean |
casePreserving |
private boolean |
caseSensitive |
private static FileSystem |
CURRENT
The current FileSystem.
|
private int[] |
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 char |
nameSeparator |
private char |
nameSeparatorOther |
private static java.lang.String |
OS_NAME_WINDOWS_PREFIX
The prefix String for all Windows OS.
|
private java.lang.String[] |
reservedFileNames |
private boolean |
reservedFileNamesExtensions |
private boolean |
supportsDriveLetter |
| Modifier and Type | Method and Description |
|---|---|
private static FileSystem |
current()
Gets the current file system.
|
int |
getBlockSize()
Gets the file allocation block size in bytes.
|
static FileSystem |
getCurrent()
Gets the current file system.
|
char[] |
getIllegalFileNameChars()
Gets a cloned copy of the illegal characters for this file system.
|
int[] |
getIllegalFileNameCodePoints()
Gets a cloned copy of the illegal code points 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.
|
char |
getNameSeparator()
Gets the name separator, '\\' on Windows, '/' on Linux.
|
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. |
private static int |
indexOf(java.lang.CharSequence cs,
int searchChar,
int start)
Copied from Apache Commons Lang CharSequenceUtils.
|
boolean |
isCasePreserving()
Tests whether this file system preserves case.
|
boolean |
isCaseSensitive()
Tests whether this file system is case-sensitive.
|
private boolean |
isIllegalFileNameChar(int c)
Tests if the given character is illegal in a file name,
false otherwise. |
boolean |
isLegalFileName(java.lang.CharSequence candidate)
Tests 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)
Tests whether the given string is a reserved file name.
|
java.lang.String |
normalizeSeparators(java.lang.String path)
Converts all separators to the Windows separator of backslash.
|
private static java.lang.String |
replace(java.lang.String path,
char oldChar,
char newChar)
Null-safe replace.
|
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. |
(package private) java.lang.CharSequence |
trimExtension(java.lang.CharSequence cs) |
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 static final FileSystem CURRENT
private final int blockSize
private final boolean casePreserving
private final boolean caseSensitive
private final int[] illegalFileNameChars
private final int maxFileNameLength
private final int maxPathLength
private final java.lang.String[] reservedFileNames
private final boolean reservedFileNamesExtensions
private final boolean supportsDriveLetter
private final char nameSeparator
private final char nameSeparatorOther
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 nullprivate static FileSystem current()
public 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 int indexOf(java.lang.CharSequence cs,
int searchChar,
int start)
cs of the first occurrence of the
specified character, starting the search at the specified index.
If a character with value searchChar occurs in the
character sequence represented by the cs
object at an index no smaller than start, then
the index of the first such occurrence is returned. For values
of searchChar in the range from 0 to 0xFFFF (inclusive),
this is the smallest value k such that:
is true. For other values of(this.charAt(k) == searchChar) && (k >= start)
searchChar, it is the
smallest value k such that:
(this.codePointAt(k) == searchChar) && (k >= start)
is true. In either case, if no such character occurs in cs
at or after position start, then
-1 is returned.
There is no restriction on the value of start. If it
is negative, it has the same effect as if it were zero: the entire
CharSequence may be searched. If it is greater than
the length of cs, it has the same effect as if it were
equal to the length of cs: -1 is returned.
All indices are specified in char values
(Unicode code units).
cs - the CharSequence to be processed, not nullsearchChar - the char to be searched forstart - the start index, negative starts at the string startStringprivate 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 nameprivate static java.lang.String replace(java.lang.String path,
char oldChar,
char newChar)
path - the path to be changed, null ignored.oldChar - the old character.newChar - the new character.public int getBlockSize()
public char[] getIllegalFileNameChars()
public int[] getIllegalFileNameCodePoints()
public int getMaxFileNameLength()
public int getMaxPathLength()
public char getNameSeparator()
public java.lang.String[] getReservedFileNames()
public boolean isCasePreserving()
public boolean isCaseSensitive()
private boolean isIllegalFileNameChar(int c)
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 java.lang.String normalizeSeparators(java.lang.String path)
path - the path to be changed, null ignoredpublic 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 characterjava.lang.CharSequence trimExtension(java.lang.CharSequence cs)