[io] New enum for file system info?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[io] New enum for file system info?

garydgregory
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
Reply | Threaded
Open this post in threaded view
|

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

garydgregory
On Wed, Nov 15, 2017 at 10:30 AM, Gary Gregory <[hidden email]>
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
>
Reply | Threaded
Open this post in threaded view
|

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

Jan Matèrne (jhm)
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:[hidden email]]
> 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 <[hidden email]>
> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

garydgregory
On Wed, Nov 15, 2017 at 12:53 PM, Jan Matèrne (jhm) <[hidden email]>
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:[hidden email]]
> > 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 <[hidden email]>
> > 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

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

Matt Sicker
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 <[hidden email]> wrote:

> On Wed, Nov 15, 2017 at 12:53 PM, Jan Matèrne (jhm) <[hidden email]>
> 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:[hidden email]]
> > > 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 <[hidden email]
> >
> > > 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: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>



--
Matt Sicker <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

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

garydgregory
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 <[hidden email]> 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 <[hidden email]> wrote:
>
> > On Wed, Nov 15, 2017 at 12:53 PM, Jan Matèrne (jhm) <[hidden email]>
> > 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:[hidden email]]
> > > > 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 <
> [hidden email]
> > >
> > > > 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: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
>
>
>
> --
> Matt Sicker <[hidden email]>
>
Reply | Threaded
Open this post in threaded view
|

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

jochen-2
In reply to this post by garydgregory
On Wed, Nov 15, 2017 at 6:33 PM, Gary Gregory <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]