commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernd Eckenfels (JIRA)" <>
Subject [jira] [Commented] (VFS-443) Need an easy way to convert from a FileObject to a File
Date Wed, 01 Jul 2015 23:17:04 GMT


Bernd Eckenfels commented on VFS-443:

I think it is good to reduce the exposure of provider classes/packages. All access should
be done through the main api packages (which needs to be defined:) Otherwise it would be really
hard to gurante compatibility.

We already have a `FileSystemManager#toFileObject(File)` so we can add a FileSystemManager#toFile(FileObject)`
as well?

> Need an easy way to convert from a FileObject to a File
> -------------------------------------------------------
>                 Key: VFS-443
>                 URL:
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Nicholas Allen
>            Assignee: Gary Gregory
> I've seen the reasons why Apache does not want to provide an easy way to convert from
a FileObject to a and those reasons make sense - however, I think that some things
are being overlooked and there are still valid reasons for needing to convert from a FileObject
to a File.
> Firstly, I would like to always use Apache VFS for everything I do - even if I know it's
only on the local file system. The reasons for this are:
> 1. it makes the code more flexible (it might start of being local file system and then
as specs change it could become a requirement to work over http or inside zip files for example).

> 2. The API is nicer to use than the and it's easier to write cross platform
code using it (file separator is always "/" etc).
> So if I work with Apache VFS for local file system use I would like to be able to get
back to a in case I need to interface with same other library. I would like a
method that converted to a File or null if not possible. This would allow me to take an alternate
action (eg copy file to local temp file if it's not already a local file). There's no need
to copy the file if it is already local.
> The simplest fix for this is to just make the getLocalFile() method in LocalFile public.
Once the user knows it's a LocalFile object it makes sense to call this method to obtain the So I could write a method like this:
> {}
> /**
>     * If the supplied {@link FileObject} represents a local file then this returns that,
>     * returns null.
>     */
>    public File getLocalFile(final FileObject fileObject)
>    {
>       if (fileObject instanceof LocalFile)
>       {
>          final LocalFile localFile = (LocalFile)fileObject;
>          return localFile.getLocalFile();
>       }
>       return null;
>    }
> {code}

This message was sent by Atlassian JIRA

View raw message