Example usage for org.apache.commons.vfs2 FileSystemOptions FileSystemOptions

List of usage examples for org.apache.commons.vfs2 FileSystemOptions FileSystemOptions

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileSystemOptions FileSystemOptions.

Prototype

public FileSystemOptions() 

Source Link

Document

Creates a new instance.

Usage

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java

@Test
public void testUsernameIsNullSetAuthenticator() throws Exception {
    DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().build();

    FileSystemOptions opts = new FileSystemOptions();
    DeployOperatorBase operatorBase = (DeployOperatorBase) operator;
    operatorBase.setAuthenticator(opts, null, null);
    UserAuthenticator auth = DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(opts);
    Assert.assertNull(auth);/*  w  w w  . j a  v a  2  s .c o m*/
}

From source file:com.sludev.commons.vfs2.provider.s3.SS3TestUtils.java

public static void deleteFile(String accntName, String accntHost, String accntKey, String containerName,
        Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(SS3Constants.S3SCHEME, new SS3FileProvider());
    currMan.init();// w w  w .  j  a  v a2  s  .  c o m

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, accntHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);

    Boolean delRes = currFile.delete();
    Assert.assertTrue(delRes);
}

From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java

public static void deleteFile(String accntName, String accntHost, String accntKey, String containerName,
        Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider());
    currMan.init();//from  www.j  a v  a 2s.c o  m

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accntHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);

    Boolean delRes = currFile.delete();
    Assert.assertTrue(delRes);
}

From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java

public CommonsVfsConnection(final ConnectionDescription desc, final FileSystemAuthProvider fsAuthProvider)
        throws FileSystemException {
    try {/*ww w  . j  a v a 2 s  . co m*/
        this.desc = desc;
        FileSystemOptions options = new FileSystemOptions();
        if (null != fsAuthProvider) {
            fsAuthProvider.authSetup(desc, options);
        }
        int port = desc.getPort().orElse(Integer.valueOf(1)).intValue();
        String host = desc.getHost().orElse(null);
        URI url = new URI(desc.getScheme(), null, host, port, desc.getPath(), null, null);
        base = VFS.getManager().resolveFile(url.toString(), options);
        root = new AbstractFile(this, ".", null, true, base.exists()); //$NON-NLS-1$
        canSetLastModifiedFile = base.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE);
        canSetLastModifiedFolder = base.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER);
    } catch (org.apache.commons.vfs2.FileSystemException | URISyntaxException e) {
        throw new FileSystemException(e);
    }
}

From source file:fi.mystes.synapse.mediator.vfs.VfsFileTransferUtility.java

/**
 * Constructor.//from ww w.  j a va2 s  .c  o m
 * 
 * @param options
 *            VFS operation options
 * @throws NullPointerException
 *             If given VFS operation options instance is not initiated
 */
public VfsFileTransferUtility(VfsOperationOptions options) {
    if (options == null) {
        throw new NullPointerException("options cannot be null");
    }
    this.options = options;
    fsOptions = new FileSystemOptions();
    if (options.isFtpPassiveModeEnabled()) {
        FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fsOptions, true);
    }
}

From source file:it.geosolutions.geobatch.destination.common.utils.RemoteBrowserUtils.java

/**
 * Initialize the file system manager with a specific timeout
 * //from   ww w . ja v  a 2s .  c  o  m
 * @param timeout
 * @throws FileSystemException
 */
private static void initFsManager(int timeout) throws FileSystemException {
    // init fsManager
    if (fsManager == null) {
        // we first set strict key checking off
        fsOptions = new FileSystemOptions();
        SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fsOptions, "no");
        // now we create a new file system manager
        fsManager = (DefaultFileSystemManager) VFS.getManager();
        SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, false);
    }
    SftpFileSystemConfigBuilder.getInstance().setTimeout(fsOptions, timeout);
}

From source file:maspack.fileutil.FileCacher.java

public FileCacher() {

    authMap = new HashMap<URIxMatcher, UserAuthenticator>();
    identMap = new HashMap<URIxMatcher, SimpleIdentityRepository>();
    myIdFactory = new SimpleIdRepoFactory();

    fsOpts = new FileSystemOptions();
    manager = new StandardFileSystemManager();
    initialized = false;//from   ww w. j  a v a 2s  .c om

}

From source file:com.sonicle.webtop.vfs.sfs.StoreFileSystem.java

public StoreFileSystem(String uri, String parameters, boolean autoCreateRoot) throws URISyntaxException {
    this.uri = new URI(uri);
    this.parameters = parameters;
    this.autoCreateRoot = autoCreateRoot;
    fso = new FileSystemOptions();
}

From source file:com.streamsets.pipeline.stage.origin.remote.FTPRemoteDownloadSourceDelegate.java

protected void initAndConnectInternal(List<Stage.ConfigIssue> issues, Source.Context context, URI remoteURI,
        String archiveDir) throws IOException {
    options = new FileSystemOptions();
    this.remoteURI = remoteURI;
    if (conf.strictHostChecking) {
        issues.add(context.createConfigIssue(Groups.CREDENTIALS.getLabel(), CONF_PREFIX + "strictHostChecking",
                Errors.REMOTE_12));/*  w  ww .  j a  va2 s.c o m*/
    }
    switch (conf.auth) {
    case PRIVATE_KEY:
        issues.add(context.createConfigIssue(Groups.CREDENTIALS.getLabel(), CONF_PREFIX + "privateKey",
                Errors.REMOTE_11));
        break;
    case PASSWORD:
        String username = resolveUsername(remoteURI, issues, context);
        String password = resolvePassword(remoteURI, issues, context);
        if (remoteURI.getUserInfo() != null) {
            remoteURI = UriBuilder.fromUri(remoteURI).userInfo(null).build();
        }
        StaticUserAuthenticator authenticator = new StaticUserAuthenticator(remoteURI.getHost(), username,
                password);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, authenticator);
        break;
    case NONE:
        break;
    default:
        break;
    }
    FtpFileSystemConfigBuilder.getInstance().setPassiveMode(options, true);
    FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, conf.userDirIsRoot);

    // Only actually try to connect and authenticate if there were no issues
    if (issues.isEmpty()) {
        LOG.info("Connecting to {}", remoteURI.toString());
        // To ensure we can connect, else we fail validation.
        remoteDir = VFS.getManager().resolveFile(remoteURI.toString(), options);
        // Ensure we can assess the remote directory...
        remoteDir.refresh();
        // throw away the results.
        remoteDir.getChildren();

        setupModTime();
    }

    if (archiveDir != null) {
        archiveURI = UriBuilder.fromUri(remoteURI).replacePath(archiveDir).build();
        archiveOptions = (FileSystemOptions) options.clone();
        FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(archiveOptions, conf.archiveDirUserDirIsRoot);
    }
}

From source file:gobblin.example.simplejson.SimpleJsonExtractor.java

public SimpleJsonExtractor(WorkUnitState workUnitState) throws FileSystemException {
    this.workUnitState = workUnitState;

    // Resolve the file to pull
    if (workUnitState.getPropAsBoolean(ConfigurationKeys.SOURCE_CONN_USE_AUTHENTICATION, false)) {
        // Add authentication credential if authentication is needed
        UserAuthenticator auth = new StaticUserAuthenticator(
                workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_DOMAIN, ""),
                workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME),
                PasswordManager.getInstance(workUnitState)
                        .readPassword(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD)));
        FileSystemOptions opts = new FileSystemOptions();
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
        this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY), opts);
    } else {/* w w  w . j  a v  a 2s  .co m*/
        this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY));
    }

    // Open the file for reading
    LOGGER.info("Opening file " + this.fileObject.getURL().toString());
    this.bufferedReader = this.closer
            .register(new BufferedReader(new InputStreamReader(this.fileObject.getContent().getInputStream(),
                    ConfigurationKeys.DEFAULT_CHARSET_ENCODING)));
}