3232 */
3333public enum FileSystem {
3434
35+ GENERIC (Integer .MAX_VALUE , Integer .MAX_VALUE , new char [] { 0 }, new String [] {}),
36+
3537 LINUX (255 , 4096 , new char [] {
3638 // KEEP THIS ARRAY SORTED!
3739 // @formatter:off
@@ -51,8 +53,6 @@ public enum FileSystem {
5153 // @formatter:on
5254 }, new String [] {}),
5355
54- GENERIC (Integer .MAX_VALUE , Integer .MAX_VALUE , new char [] { 0 }, new String [] {}),
55-
5656 WINDOWS (255 , 32000 , new char [] {
5757 // KEEP THIS ARRAY SORTED!
5858 // @formatter:off
@@ -68,40 +68,40 @@ public enum FileSystem {
6868 new String [] { "AUX" , "COM1" , "COM2" , "COM3" , "COM4" , "COM5" , "COM6" , "COM7" , "COM8" , "COM9" , "CON" , "LPT1" ,
6969 "LPT2" , "LPT3" , "LPT4" , "LPT5" , "LPT6" , "LPT7" , "LPT8" , "LPT9" , "NUL" , "PRN" });
7070
71- /**
72- * The prefix String for all Windows OS.
73- */
74- private static final String OS_NAME_WINDOWS_PREFIX = "Windows" ;
75-
7671 /**
7772 * <p>
78- * Is {@code true} if this is Windows .
73+ * Is {@code true} if this is Linux .
7974 * </p>
8075 * <p>
8176 * The field will return {@code false} if {@code OS_NAME} is {@code null}.
8277 * </p>
8378 */
84- private static final boolean IS_OS_WINDOWS = getOsMatchesName (OS_NAME_WINDOWS_PREFIX );
79+ private static final boolean IS_OS_LINUX = getOsMatchesName ("Linux" ) || getOsMatchesName ( "LINUX" );
8580
8681 /**
8782 * <p>
88- * Is {@code true} if this is Linux .
83+ * Is {@code true} if this is Mac .
8984 * </p>
9085 * <p>
9186 * The field will return {@code false} if {@code OS_NAME} is {@code null}.
9287 * </p>
9388 */
94- private static final boolean IS_OS_LINUX = getOsMatchesName ("Linux" ) || getOsMatchesName ("LINUX" );
89+ private static final boolean IS_OS_MAC = getOsMatchesName ("Mac" );
90+
91+ /**
92+ * The prefix String for all Windows OS.
93+ */
94+ private static final String OS_NAME_WINDOWS_PREFIX = "Windows" ;
9595
9696 /**
9797 * <p>
98- * Is {@code true} if this is Mac .
98+ * Is {@code true} if this is Windows .
9999 * </p>
100100 * <p>
101101 * The field will return {@code false} if {@code OS_NAME} is {@code null}.
102102 * </p>
103103 */
104- private static final boolean IS_OS_MAC = getOsMatchesName ("Mac" );
104+ private static final boolean IS_OS_WINDOWS = getOsMatchesName (OS_NAME_WINDOWS_PREFIX );
105105
106106 private static final String OS_NAME = getSystemProperty ("os.name" );
107107
@@ -230,6 +230,15 @@ public int getMaxPathLength() {
230230 return maxPathLength ;
231231 }
232232
233+ /**
234+ * Gets the reserved file names.
235+ *
236+ * @return the reserved file names.
237+ */
238+ public String [] getReservedFileNames () {
239+ return reservedFileNames ;
240+ }
241+
233242 /**
234243 * Returns {@code true} if the given character is illegal in a file name, {@code false} otherwise.
235244 *
@@ -241,6 +250,30 @@ private boolean isIllegalFileNameChar(final char c) {
241250 return Arrays .binarySearch (illegalFileNameChars , c ) >= 0 ;
242251 }
243252
253+ /**
254+ * Checks if a candidate file name (without a path) such as {@code "filename.ext"} or {@code "filename"} is a
255+ * potentially legal file name. If the file name length exceeds {@link #getMaxFileNameLength()}, or if it contains
256+ * an illegal character then the check fails.
257+ *
258+ * @param candidate
259+ * a candidate file name (without a path) like {@code "filename.ext"} or {@code "filename"}
260+ * @return {@code true} if the candidate name is legal
261+ */
262+ public boolean isLegalFileName (final CharSequence candidate ) {
263+ if (candidate == null || candidate .length () == 0 || candidate .length () > maxFileNameLength ) {
264+ return false ;
265+ }
266+ if (isReservedFileName (candidate )) {
267+ return false ;
268+ }
269+ for (int i = 0 ; i < candidate .length (); i ++) {
270+ if (isIllegalFileNameChar (candidate .charAt (i ))) {
271+ return false ;
272+ }
273+ }
274+ return true ;
275+ }
276+
244277 /**
245278 * Returns whether the given string is a reserved file name.
246279 *
@@ -283,37 +316,4 @@ public String toLegalFileName(final String candidate, final char replacement) {
283316 }
284317 return changed ? String .valueOf (charArray ) : truncated ;
285318 }
286-
287- /**
288- * Checks if a candidate file name (without a path) such as {@code "filename.ext"} or {@code "filename"} is a
289- * potentially legal file name. If the file name length exceeds {@link #getMaxFileNameLength()}, or if it contains
290- * an illegal character then the check fails.
291- *
292- * @param candidate
293- * a candidate file name (without a path) like {@code "filename.ext"} or {@code "filename"}
294- * @return {@code true} if the candidate name is legal
295- */
296- public boolean isLegalFileName (final CharSequence candidate ) {
297- if (candidate == null || candidate .length () == 0 || candidate .length () > maxFileNameLength ) {
298- return false ;
299- }
300- if (isReservedFileName (candidate )) {
301- return false ;
302- }
303- for (int i = 0 ; i < candidate .length (); i ++) {
304- if (isIllegalFileNameChar (candidate .charAt (i ))) {
305- return false ;
306- }
307- }
308- return true ;
309- }
310-
311- /**
312- * Gets the reserved file names.
313- *
314- * @return the reserved file names.
315- */
316- public String [] getReservedFileNames () {
317- return reservedFileNames ;
318- }
319319}
0 commit comments