filesystems - WebDAV FileSystemProvider - Java NIO -
i have java application lots of nio methods files.copy
, files.move
, files.delete
, filechannel
...
what trying achieve: want access remote webdav server , modify data on server basic functions upload, delete or update remote webdav data - without changing every method on application. here comes idea:
i think webdav filesystem implementation trick. adding custom webdav filesystemprovider managing mentioned file operations on remote data. i've googled lot , apache vfs sardine implementation looks - seems apache vfs not compatible nio?
here's example code, imagine it:
public class webdavmanagertest { private static defaultfilesystemmanager fsmanager; private static webdavfileobject testfile1; private static webdavfileobject testfile2; private static filesystem webdavfilesystem1; private static filesystem webdavfilesystem2; @before public static void initwebdavfilesystem(string webdavserverurl) throws filesystemexception, org.apache.commons.vfs2.filesystemexception { try { fsmanager = new defaultfilesystemmanager(); fsmanager.addprovider("webdav", new webdavfileprovider()); fsmanager.addprovider("file", new defaultlocalfileprovider()); fsmanager.init(); } catch (org.apache.commons.vfs2.filesystemexception e) { throw new filesystemexception("exception initializing defaultfilesystemmanager: " + e.getmessage()); } string exampleremotefile1 = "/foo/bar1.txt"; string exampleremotefile2 = "/foo/bar2.txt"; testfile1 = (webdavfileobject) fsmanager.resolvefile(webdavserverurl + exampleremotefile1); webdavfilesystem1 = (filesystem) fsmanager.createfilesystem(testfile1); path localpath1 = webdavfilesystem1.getpath(testfile1.tostring()); testfile2 = (webdavfileobject) fsmanager.resolvefile(webdavserverurl + exampleremotefile2); webdavfilesystem2 = (filesystem) fsmanager.createfilesystem(testfile2); path localpath2 = webdavfilesystem1.getpath(testfile1.tostring()); } }
after want work in application localpath1 + localpath2. e.g. files.copy(localpath1, newremotepath) copy file on webdav server new directory.
is right course of action? or there other libraries achieve that?
apache vfs uses it's own filesystem interface not nio one. have 3 options varying levels of effort.
- change code use existing webdav project uses it's own filesystem ie apache vfs.
- find existing project uses webdav , implements nio filesystem etc.
- implement nio filesystem interface yourself.
option 3 has been done may able customize else has written, have @ nio-fs-provider or nio-fs-webdav. i'm sure there others these 2 easy find using google.
implementing webdav nio filesystem scratch quite lot of work wouldn't recommend starting there, i'd take has done , make work me ie option 2.
Comments
Post a Comment