You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2017/11/15 17:30:28 UTC

[io] New enum for file system info?

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?

Gary

Re: [io] New enum for file system info?

Posted by Gary Gregory <ga...@gmail.com>.
Please see the current code evolving in comments in
https://issues.apache.org/jira/browse/IO-555 even though it might be time
to commit and let others have at it.

Gary

On Wed, Nov 15, 2017 at 1:16 PM, Matt Sicker <bo...@gmail.com> wrote:

> Oh definitely not OS-specific. Windows has FAT32, FATX/XFAT (forget the
> name; they use it on Xbox), NTFS, possibly more. macOS has HFS, HFS+, and
> APFS. Linux has at least a dozen or more. BSD has its own (possibly
> different between FreeBSD and OpenBSD), then Solaris, AIX, etc.
>
> On 15 November 2017 at 14:11, Gary Gregory <ga...@gmail.com> wrote:
>
> > On Wed, Nov 15, 2017 at 12:53 PM, Jan Matèrne (jhm) <ap...@materne.de>
> > wrote:
> >
> > > s/MAC_OSX_9/MAC_OS_9/
> > > What about older versions of MacOS?
> > > UNKNOWN(31,1024) // smallest values for safety
> > > Are there differences between FAT,FAT32,NTFS,reiserfs,... ?
> > >
> >
> > Here you go: https://en.wikipedia.org/wiki/Comparison_of_file_systems
> >
> > This makes me wonder of the enum name should not be OS name but the FS
> name
> > like FAT32.
> >
> > Gary
> >
> >
> > >
> > > Jan
> > >
> > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Gary Gregory [mailto:garydgregory@gmail.com]
> > > > Gesendet: Mittwoch, 15. November 2017 18:34
> > > > An: Commons Developers List
> > > > Betreff: Re: [io] New enum for file system info?
> > > >
> > > > On Wed, Nov 15, 2017 at 10:30 AM, Gary Gregory <
> garydgregory@gmail.com
> > >
> > > > 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
> > > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > > For additional commands, e-mail: dev-help@commons.apache.org
> > >
> > >
> >
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>

Re: [io] New enum for file system info?

Posted by Matt Sicker <bo...@gmail.com>.
Oh definitely not OS-specific. Windows has FAT32, FATX/XFAT (forget the
name; they use it on Xbox), NTFS, possibly more. macOS has HFS, HFS+, and
APFS. Linux has at least a dozen or more. BSD has its own (possibly
different between FreeBSD and OpenBSD), then Solaris, AIX, etc.

On 15 November 2017 at 14:11, Gary Gregory <ga...@gmail.com> wrote:

> On Wed, Nov 15, 2017 at 12:53 PM, Jan Matèrne (jhm) <ap...@materne.de>
> wrote:
>
> > s/MAC_OSX_9/MAC_OS_9/
> > What about older versions of MacOS?
> > UNKNOWN(31,1024) // smallest values for safety
> > Are there differences between FAT,FAT32,NTFS,reiserfs,... ?
> >
>
> Here you go: https://en.wikipedia.org/wiki/Comparison_of_file_systems
>
> This makes me wonder of the enum name should not be OS name but the FS name
> like FAT32.
>
> Gary
>
>
> >
> > Jan
> >
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Gary Gregory [mailto:garydgregory@gmail.com]
> > > Gesendet: Mittwoch, 15. November 2017 18:34
> > > An: Commons Developers List
> > > Betreff: Re: [io] New enum for file system info?
> > >
> > > On Wed, Nov 15, 2017 at 10:30 AM, Gary Gregory <garydgregory@gmail.com
> >
> > > 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
> > > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
> >
>



-- 
Matt Sicker <bo...@gmail.com>

Re: [io] New enum for file system info?

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Nov 15, 2017 at 12:53 PM, Jan Matèrne (jhm) <ap...@materne.de>
wrote:

> s/MAC_OSX_9/MAC_OS_9/
> What about older versions of MacOS?
> UNKNOWN(31,1024) // smallest values for safety
> Are there differences between FAT,FAT32,NTFS,reiserfs,... ?
>

Here you go: https://en.wikipedia.org/wiki/Comparison_of_file_systems

This makes me wonder of the enum name should not be OS name but the FS name
like FAT32.

Gary


>
> Jan
>
>
> > -----Ursprüngliche Nachricht-----
> > Von: Gary Gregory [mailto:garydgregory@gmail.com]
> > Gesendet: Mittwoch, 15. November 2017 18:34
> > An: Commons Developers List
> > Betreff: Re: [io] New enum for file system info?
> >
> > On Wed, Nov 15, 2017 at 10:30 AM, Gary Gregory <ga...@gmail.com>
> > 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
> > >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

AW: [io] New enum for file system info?

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
s/MAC_OSX_9/MAC_OS_9/
What about older versions of MacOS?
UNKNOWN(31,1024) // smallest values for safety
Are there differences between FAT,FAT32,NTFS,reiserfs,... ?

Jan


> -----Ursprüngliche Nachricht-----
> Von: Gary Gregory [mailto:garydgregory@gmail.com]
> Gesendet: Mittwoch, 15. November 2017 18:34
> An: Commons Developers List
> Betreff: Re: [io] New enum for file system info?
> 
> On Wed, Nov 15, 2017 at 10:30 AM, Gary Gregory <ga...@gmail.com>
> 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
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [io] New enum for file system info?

Posted by Jochen Wiedmann <jo...@gmail.com>.
On Wed, Nov 15, 2017 at 6:33 PM, Gary Gregory <ga...@gmail.com> wrote:

> The enum would obviously need a "public static FileSystem getCurrent()"
> method.

Wouldn't that better be FileSystem.of(File pFile), even if the
parameter were ignored initially?

Jochen


-- 
The next time you hear: "Don't reinvent the wheel!"

http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [io] New enum for file system info?

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Nov 15, 2017 at 10:30 AM, Gary Gregory <ga...@gmail.com>
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
>