Re: commons-vfs-2.4.1 - Question re. usage of VFS.getManager()

2019-10-29 Thread Bernd Eckenfels
Hello

I think the problem in your case is that the default filesystem manager does 
not know about the ftp: scheme. The error message is a bit missleading (since a 
fix done, probably we should file a bug for this).

The default manager does try to load the FtpProvider and tries to register it 
with ftp: so I assume loading of the provider failed. Maybe you are missing 
dependencies like commons-net (see the website for the dependencies per 
provider).

For debugging you can print manager.getSchemes() to see the available schemes 
(providers).
Gruss
Bernd


--
http://bernd.eckenfels.net


Von: Erwin Hogeweg 
Gesendet: Mittwoch, Oktober 30, 2019 3:29 AM
An: Commons Users List
Betreff: commons-vfs-2.4.1 - Question re. usage of VFS.getManager()

All -

I am trying to set up a VFS but I struggled a while to get past a 
FileSystemException. After looking at the VFS source code I understood what was 
going on, and I was able to create a work-around. However, I am not sure that 
what I hacked together is the right approach so I am looking for some guidance 
from the experts here…

This is what I was trying to do:

FileObject path = VFS.getManager().resolveFile("ftp://ftp.gnu.org/README;, new 
FileSystemOptions());

The issue is, or at least appears to be, that the FileSystemManager doesn’t 
have a baseFile so the resolveFile blows up with this exception:

org.apache.commons.vfs2.FileSystemException: Could not find file with URI 
"ftp://ftp.gnu.org/README; because it is a relative path, and no base URI was 
provided.
at 
org.apache.commons.vfs2.FileSystemException.requireNonNull(FileSystemException.java:87)

I could not find how/where to define that baseFile so I eventually settled on 
this work-around:

StandardFileSystemManager fsManager = (StandardFileSystemManager) 
VFS.getManager(); // YUCK!
fsManager.setBaseFile(new File("")); // Another YUCK.
FileObject path = fsManager.resolveFile("ftp://ftp.gnu.org/README;, opts);

That works, and now I end up with the correct (expected) path. It doesn’t feel 
right though so any advice would be greatly appreciated.


Cheers,

Erwin




commons-vfs-2.4.1 - Question re. usage of VFS.getManager()

2019-10-29 Thread Erwin Hogeweg
All -

I am trying to set up a VFS but I struggled a while to get past a 
FileSystemException. After looking at the VFS source code I understood what was 
going on, and I was able to create a work-around. However, I am not sure that 
what I hacked together is the right approach so I am looking for some guidance 
from the experts here…

This is what I was trying to do:

FileObject path = VFS.getManager().resolveFile("ftp://ftp.gnu.org/README;, 
new FileSystemOptions());

The issue is, or at least appears to be, that the FileSystemManager doesn’t 
have a baseFile so the resolveFile blows up with this exception:

org.apache.commons.vfs2.FileSystemException: Could not find file with URI 
"ftp://ftp.gnu.org/README; because it is a relative path, and no base URI was 
provided.
at 
org.apache.commons.vfs2.FileSystemException.requireNonNull(FileSystemException.java:87)

I could not find how/where to define that baseFile so I eventually settled on 
this work-around:

   StandardFileSystemManager fsManager = (StandardFileSystemManager) 
VFS.getManager(); // YUCK!
   fsManager.setBaseFile(new File("")); // Another YUCK.
   FileObject path = fsManager.resolveFile("ftp://ftp.gnu.org/README;, opts);

That works, and now I end up with the correct (expected) path. It doesn’t feel 
right though so any advice would be greatly appreciated.


Cheers,

Erwin