On Wed, Nov 15, 2017 at 10:30 AM, Gary Gregory <[email protected]>
wrote:
> I find myself writing and using non-OO code around things like:
>
> private final int MAX_FILE_NAME_LENGTH_WINDOWS = 255;
> private final int MAX_FILE_NAME_LENGTH_LINUX = 255;
> private final int MAX_FILE_NAME_LENGTH_MAC = 255;
> private final int MAX_FILE_NAME_LENGTH_MAC_OS9 = 31;
>
> private final int MAX_FILE_PATH_LENGTH_WINDOWS = 32000;
> private final int MAX_FILE_PATH_LENGTH_LINUX = 4096;
> private final int MAX_FILE_PATH_LENGTH_MAC = 1024;
>
> But that is not even right for older Macs which limits file names to 31
> chars.
>
> I was thinking of creating a new enum:
>
> package org.apache.commons.io;
>
> public enum FileSystem {
>
> LINUX(255, 4096),
> MAC_OSX(255, 1024),
> MAC_OSX_9(31, 1024),
> WINDOWS(255, 32000);
>
> private final long maxFileLength;
> private final long maxPathLength;
>
> private FileSystem(long maxFileLength, long maxPathLength) {
> this.maxFileLength = maxFileLength;
> this.maxPathLength = maxPathLength;
> }
>
> public long getMaxFileLength() {
> return maxFileLength;
> }
>
> public long getMaxPathLength() {
> return maxPathLength;
> }
>
> public boolean isIllegalFileName(char ch) {
> ...
> }
>
> public String toLegalFileName(String candidate, char replacement) {
> ...
> }
>
> }
>
> I would also move the new method from https://issues.apache.org/
> jira/browse/IO-555 there and rename it "isIllegalFileName(char)"
>
> Thoughts?
>
The enum would obviously need a "public static FileSystem getCurrent()"
method.
Gary
>
> Gary
>