use of org.apache.commons.vfs2.FileSystemOptions in project hop by apache.
the class S3FileProviderTest method testDoCreateFileSystem.
@Test
public void testDoCreateFileSystem() throws Exception {
FileName fileName = mock(FileName.class);
FileSystemOptions options = new FileSystemOptions();
assertNotNull(provider.doCreateFileSystem(fileName, options));
}
use of org.apache.commons.vfs2.FileSystemOptions in project agileway by fangjinuo.
the class SftpFileProvider method doCreateFileSystem.
@Override
protected FileSystem doCreateFileSystem(FileName rootName, FileSystemOptions fileSystemOptions) throws FileSystemException {
// Create the file system
final GenericFileName root = (GenericFileName) rootName;
SshConnectionFactory sshConnectionFactory = new SshConnectionFactoryRegistry().getDefault();
SshConnectionConfig connectionConfig = sshConnectionFactory.newConfig();
connectionConfig.setHost(root.getHostName());
connectionConfig.setPort(root.getPort());
connectionConfig.setUser(root.getUserName());
connectionConfig.setPassword(root.getPassword());
SftpFileSystemConfigBuilder configBuilder = (SftpFileSystemConfigBuilder) getConfigBuilder();
final File knownHostsFile = configBuilder.getKnownHosts(fileSystemOptions);
if (knownHostsFile != null) {
connectionConfig.setKnownHostsPath(knownHostsFile.getAbsolutePath());
}
// JSCH 特有属性:
Integer timout = configBuilder.getTimeout(fileSystemOptions);
if (timout != null) {
connectionConfig.setProperty("ConnectTimeout", timout);
}
String strictHostKeyChecking = configBuilder.getStrictHostKeyChecking(fileSystemOptions);
if (Strings.isNotEmpty(strictHostKeyChecking)) {
connectionConfig.setProperty("StrictHostKeyChecking", strictHostKeyChecking);
}
final String preferredAuthentications = configBuilder.getPreferredAuthentications(fileSystemOptions);
if (preferredAuthentications != null) {
connectionConfig.setProperty("PreferredAuthentications", preferredAuthentications);
}
// set compression property
final String compression = configBuilder.getCompression(fileSystemOptions);
if (compression != null) {
connectionConfig.setProperty("compression.s2c", compression);
connectionConfig.setProperty("compression.c2s", compression);
}
SshConnection sshConnection = sshConnectionFactory.get(connectionConfig);
SftpSession session = sshConnection.openSftpSession();
return new SftpFileSystem(root, session, null, fileSystemOptions);
}
use of org.apache.commons.vfs2.FileSystemOptions in project agileway by fangjinuo.
the class AgilewaySftpProviderTests method testListChildren.
@Test
public void testListChildren() throws Throwable {
DefaultFileSystemManager fileSystemManager = (DefaultFileSystemManager) VFS.getManager();
String url = "sftp://fangjinuo:fjn13570@192.168.1.70:22/test2/vfs_sftp_test";
FileSystemOptions fileSystemOptions = new FileSystemOptions();
SftpFileSystemConfigBuilder configBuilder = SftpFileSystemConfigBuilder.getInstance();
configBuilder.setUserDirIsRoot(fileSystemOptions, true);
FileObject fileObject = fileSystemManager.resolveFile(url, fileSystemOptions);
System.out.println("===============Show remote directory==============");
showFile(0, fileObject);
System.out.println("===============Copy remote files to local==============");
url = "file://d:/tmp002";
FileObject localFileObject = fileSystemManager.resolveFile(url);
if (fileObject.isFolder()) {
if (!localFileObject.exists()) {
localFileObject.createFolder();
} else {
localFileObject.delete(Selectors.EXCLUDE_SELF);
}
localFileObject.copyFrom(fileObject, Selectors.EXCLUDE_SELF);
} else {
// 单独测试 文件时,将上面的 url 改成一个 文件的url即可
long writeSize = fileObject.getContent().write(localFileObject);
long expectedSize = fileObject.getContent().getSize();
Preconditions.checkTrue(writeSize == expectedSize);
localFileObject.copyFrom(fileObject, Selectors.SELECT_SELF);
}
System.out.println("================Copy local files to remote=============");
url = "sftp://fangjinuo:fjn13570@192.168.1.70:22/test2/vfs_sftp_test2";
fileObject = fileSystemManager.resolveFile(url, fileSystemOptions);
if (!fileObject.exists()) {
fileObject.createFolder();
} else {
fileObject.delete(Selectors.EXCLUDE_SELF);
}
fileObject.copyFrom(localFileObject, Selectors.EXCLUDE_SELF);
}
use of org.apache.commons.vfs2.FileSystemOptions in project commons-vfs by apache.
the class TemporaryFileProvider method findFile.
/**
* Locates a file object, by absolute URI.
*
* @param baseFile The base FileObject.
* @param uri The URI of the file to be located.
* @param fileSystemOptions FileSystemOptions to use to locate or create the file.
* @return The FileObject.
* @throws FileSystemException if an error occurs.
*/
@Override
public synchronized FileObject findFile(final FileObject baseFile, final String uri, final FileSystemOptions fileSystemOptions) throws FileSystemException {
// Parse the name
final StringBuilder buffer = new StringBuilder(uri);
final String scheme = UriParser.extractScheme(getContext().getFileSystemManager().getSchemes(), uri, buffer);
UriParser.fixSeparators(buffer);
UriParser.normalisePath(buffer);
final String path = buffer.toString();
// Create the temp file system if it does not exist
// FileSystem filesystem = findFileSystem( this, (Properties) null);
FileSystem filesystem = findFileSystem(this, fileSystemOptions);
if (filesystem == null) {
if (rootFile == null) {
rootFile = getContext().getTemporaryFileStore().allocateFile("tempfs");
}
final FileName rootName = getContext().parseURI(scheme + ":" + FileName.ROOT_PATH);
// final FileName rootName =
// new LocalFileName(scheme, scheme + ":", FileName.ROOT_PATH);
filesystem = new LocalFileSystem(rootName, rootFile.getAbsolutePath(), fileSystemOptions);
addFileSystem(this, filesystem);
}
// Find the file
return filesystem.resolveFile(path);
}
use of org.apache.commons.vfs2.FileSystemOptions in project commons-vfs by apache.
the class UrlFileProvider method findFile.
/**
* Locates a file object, by absolute URI.
*
* @param baseFile The base FileObject.
* @param fileUri The uri of the file to locate.
* @param fileSystemOptions The FileSystemOptions
* @return The FileObject
* @throws FileSystemException if an error occurs.
*/
@Override
public synchronized FileObject findFile(final FileObject baseFile, final String fileUri, final FileSystemOptions fileSystemOptions) throws FileSystemException {
try {
final URI uri = URI.create(fileUri);
final URI rootUri = uri.resolve("/");
final String key = this.getClass().getName() + rootUri.toString();
FileSystem fs = findFileSystem(key, fileSystemOptions);
if (fs == null) {
final String extForm = rootUri.toString();
final FileName rootName = getContext().parseURI(extForm);
// final FileName rootName =
// new BasicFileName(rootUrl, FileName.ROOT_PATH);
fs = new UrlFileSystem(rootName, fileSystemOptions);
addFileSystem(key, fs);
}
return fs.resolveFile(uri.getPath());
} catch (final Exception e) {
throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", fileUri, e);
}
}
Aggregations