Skip to content

Commit ef0fb79

Browse files
committed
Add slots for case sensitivity and case preservation.
1 parent 9e801d9 commit ef0fb79

1 file changed

Lines changed: 62 additions & 24 deletions

File tree

src/main/java/org/apache/commons/io/FileSystem.java

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@
3333
*/
3434
public enum FileSystem {
3535

36-
GENERIC(Integer.MAX_VALUE, Integer.MAX_VALUE, new char[] { 0 }, new String[] {}),
36+
/**
37+
* Generic file system.
38+
*/
39+
GENERIC(false, false, Integer.MAX_VALUE, Integer.MAX_VALUE, new char[] { 0 }, new String[] {}),
3740

38-
LINUX(255, 4096, new char[] {
41+
/**
42+
* Linux file system.
43+
*/
44+
LINUX(true, true, 255, 4096, new char[] {
3945
// KEEP THIS ARRAY SORTED!
4046
// @formatter:off
4147
// ASCII NUL
@@ -44,7 +50,10 @@ public enum FileSystem {
4450
// @formatter:on
4551
}, new String[] {}),
4652

47-
MAC_OSX(255, 1024, new char[] {
53+
/**
54+
* MacOS file system.
55+
*/
56+
MAC_OSX(true, true, 255, 1024, new char[] {
4857
// KEEP THIS ARRAY SORTED!
4958
// @formatter:off
5059
// ASCII NUL
@@ -54,18 +63,21 @@ public enum FileSystem {
5463
// @formatter:on
5564
}, new String[] {}),
5665

57-
WINDOWS(255, 32000, new char[] {
58-
// KEEP THIS ARRAY SORTED!
59-
// @formatter:off
60-
// ASCII NUL
61-
0,
62-
// 1-31 may be allowed in file streams
63-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
64-
29, 30, 31,
65-
'"', '*', '/', ':', '<', '>', '?', '\\', '|'
66-
// @formatter:on
67-
},
68-
// KEEP THIS ARRAY SORTED!
66+
/**
67+
* Windows file system.
68+
*/
69+
WINDOWS(false, true, 255,
70+
32000, new char[] {
71+
// KEEP THIS ARRAY SORTED!
72+
// @formatter:off
73+
// ASCII NUL
74+
0,
75+
// 1-31 may be allowed in file streams
76+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
77+
29, 30, 31,
78+
'"', '*', '/', ':', '<', '>', '?', '\\', '|'
79+
// @formatter:on
80+
}, // KEEP THIS ARRAY SORTED!
6981
new String[] { "AUX", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "CON", "LPT1",
7082
"LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "NUL", "PRN" });
7183

@@ -178,6 +190,8 @@ private static boolean isOsNameMatch(final String osName, final String osNamePre
178190
return osName.toUpperCase(Locale.ROOT).startsWith(osNamePrefix.toUpperCase(Locale.ROOT));
179191
}
180192

193+
private final boolean casePreserving;
194+
private final boolean caseSensitive;
181195
private final char[] illegalFileNameChars;
182196
private final int maxFileNameLength;
183197
private final int maxPathLength;
@@ -186,21 +200,27 @@ private static boolean isOsNameMatch(final String osName, final String osNamePre
186200
/**
187201
* Constructs a new instance.
188202
*
203+
* @param caseSensitive
204+
* Whether this file system is case sensitive.
205+
* @param casePreserving
206+
* Whether this file system is case preserving.
189207
* @param maxFileLength
190-
* the maximum length for file names. The file name does not include folders.
208+
* The maximum length for file names. The file name does not include folders.
191209
* @param maxPathLength
192-
* the maximum length of the path to a file. This can include folders.
210+
* The maximum length of the path to a file. This can include folders.
193211
* @param illegalFileNameChars
194-
* illegal characters for this file system.
212+
* Illegal characters for this file system.
195213
* @param reservedFileNames
196-
* the reserved file names.
214+
* The reserved file names.
197215
*/
198-
FileSystem(final int maxFileLength, final int maxPathLength, final char[] illegalFileNameChars,
199-
final String[] reservedFileNames) {
216+
FileSystem(final boolean caseSensitive, final boolean casePreserving, final int maxFileLength,
217+
final int maxPathLength, final char[] illegalFileNameChars, final String[] reservedFileNames) {
200218
this.maxFileNameLength = maxFileLength;
201219
this.maxPathLength = maxPathLength;
202220
this.illegalFileNameChars = Objects.requireNonNull(illegalFileNameChars, "illegalFileNameChars");
203221
this.reservedFileNames = Objects.requireNonNull(reservedFileNames, "reservedFileNames");
222+
this.caseSensitive = caseSensitive;
223+
this.casePreserving = casePreserving;
204224
}
205225

206226
/**
@@ -232,16 +252,34 @@ public int getMaxPathLength() {
232252

233253
/**
234254
* Gets a cloned copy of the reserved file names.
235-
*
255+
*
236256
* @return the reserved file names.
237257
*/
238258
public String[] getReservedFileNames() {
239259
return reservedFileNames.clone();
240260
}
241261

242262
/**
243-
* Returns {@code true} if the given character is illegal in a file name, {@code false} otherwise.
263+
* Whether this file system preserves case.
264+
*
265+
* @return Whether this file system preserves case.
266+
*/
267+
public boolean isCasePreserving() {
268+
return casePreserving;
269+
}
270+
271+
/**
272+
* Whether this file system is case-sensitive.
244273
*
274+
* @return Whether this file system is case-sensitive.
275+
*/
276+
public boolean isCaseSensitive() {
277+
return caseSensitive;
278+
}
279+
280+
/**
281+
* Returns {@code true} if the given character is illegal in a file name, {@code false} otherwise.
282+
*
245283
* @param c
246284
* the character to test
247285
* @return {@code true} if the given character is illegal in a file name, {@code false} otherwise.
@@ -276,7 +314,7 @@ public boolean isLegalFileName(final CharSequence candidate) {
276314

277315
/**
278316
* Returns whether the given string is a reserved file name.
279-
*
317+
*
280318
* @param candidate
281319
* the string to test
282320
* @return {@code true} if the given string is a reserved file name.

0 commit comments

Comments
 (0)