我有很多的NIO方法,如Files.copy
,Files.move
,Files.delete
,FileChannel
的Java应用程序...的WebDAV FileSystemProvider - 的Java NIO
我现在想要实现:我想访问远程WebDAV服务器并修改该服务器上的数据具有上传,删除或更新远程WebDAV数据等基本功能 - 无需更改我的应用程序上的每种方法。所以这里来我的想法:
我认为一个WebDAV文件系统的实现会做的伎俩。添加一个自定义的WebDAV FileSystemProvider,用于管理远程数据上提到的文件操作。我搜索了很多,Apache SFS的沙盒实现看起来不错 - 但看起来Apache VFS与NIO不兼容?
下面是一些示例代码,我想这:
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());
}
}
之后,我想在我与localPath1 + localPath2应用工作。所以,例如Files.copy(localPath1,newRemotePath)会将WebDAV服务器上的文件复制到新目录。
这是正确的行为吗?还是有其他图书馆来实现这一目标?