Example usage for org.apache.commons.vfs2.provider.sftp SftpFileSystemConfigBuilder setCompression

List of usage examples for org.apache.commons.vfs2.provider.sftp SftpFileSystemConfigBuilder setCompression

Introduction

In this page you can find the example usage for org.apache.commons.vfs2.provider.sftp SftpFileSystemConfigBuilder setCompression.

Prototype

public void setCompression(final FileSystemOptions opts, final String compression) throws FileSystemException 

Source Link

Document

Configures the compression algorithms to use.

Usage

From source file:pl.otros.vfs.browser.util.VFSUtils.java

/**
 * Returns a file representation//from www  . j  a  v a2  s  . c  o m
 *
 * @param filePath The file path
 * @return a file representation
 * @throws FileSystemException
 */
public static FileObject resolveFileObject(String filePath) throws FileSystemException {
    LOGGER.info("Resolving file: {}", filePath);
    if (filePath.startsWith("sftp://")) {
        SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
        builder.setStrictHostKeyChecking(opts, "no");
        builder.setUserDirIsRoot(opts, false);
        builder.setCompression(opts, "zlib,none");

    } else if (filePath.startsWith("smb://")) {

    } else if (filePath.startsWith("ftp://")) {
        FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
    }
    UserAuthenticatorFactory factory = new UserAuthenticatorFactory();

    OtrosUserAuthenticator authenticator = factory.getUiUserAuthenticator(persistentAuthStore, sessionAuthStore,
            filePath, opts);

    if (pathContainsCredentials(filePath)) {
        authenticator = null;
    }
    return resolveFileObject(filePath, opts, authenticator, persistentAuthStore, sessionAuthStore);
}

From source file:pl.otros.vfs.browser.util.VFSUtils.java

/**
 * Returns a file representation//from   w w  w. j a  va2s  .  com
 *
 * @param filePath The file path
 * @param options  The filesystem options
 * @return a file representation
 * @throws FileSystemException
 */
public static FileObject resolveFileObject(String filePath, FileSystemOptions options,
        OtrosUserAuthenticator authenticator, AuthStore persistentAuthStore, AuthStore sessionAuthStore)
        throws FileSystemException {
    if (filePath.startsWith("sftp://")) {
        SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
        builder.setStrictHostKeyChecking(opts, "no");
        builder.setUserDirIsRoot(opts, false);
        builder.setCompression(opts, "zlib,none");
    }

    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, authenticator);
    FileObject resolveFile;

    VFSURIParser parser = new VFSURIParser(filePath);
    //Get file type to force authentication
    try {
        resolveFile = getFileSystemManager().resolveFile(filePath, options);
        resolveFile.getType();
    } catch (FileSystemException e) {
        LOGGER.error("Error resolving file " + filePath, e);
        Throwable rootCause = Throwables.getRootCause(e);
        boolean authorizationFailed = false;
        authorizationFailed = checkForWrongCredentials(rootCause);
        if (authorizationFailed) {
            LOGGER.error("Wrong user name or password for " + filePath);
            //clear last data
            //authenticator can be null if user/password was entered in URL
            if (authenticator != null) {
                UserAuthenticationDataWrapper lastUserAuthenticationData = authenticator
                        .getLastUserAuthenticationData();
                lastUserAuthenticationData.remove(UserAuthenticationDataWrapper.PASSWORD);
                String user = new String(lastUserAuthenticationData.getData(UserAuthenticationData.USERNAME));
                UserAuthenticationInfo auInfo = new UserAuthenticationInfo(parser.getProtocol().getName(),
                        parser.getHostname(), user);
                sessionAuthStore.remove(auInfo);
                sessionAuthStore.add(auInfo, lastUserAuthenticationData);
                LOGGER.info("Removing password for {} on {}",
                        new Object[] {
                                new String(lastUserAuthenticationData.getData(UserAuthenticationData.USERNAME)),
                                filePath });
            }
        }
        throw e;
    }

    if (resolveFile != null && authenticator != null && authenticator.getLastUserAuthenticationData() != null) {
        UserAuthenticationDataWrapper lastUserAuthenticationData = authenticator
                .getLastUserAuthenticationData();
        Map<Type, char[]> addedTypes = lastUserAuthenticationData.getAddedTypes();
        String user = new String(addedTypes.get(UserAuthenticationData.USERNAME));
        UserAuthenticationInfo auInfo = new UserAuthenticationInfo(parser.getProtocol().getName(),
                parser.getHostname(), user);
        sessionAuthStore.add(auInfo, lastUserAuthenticationData.copy());
        if (authenticator.isPasswordSave()) {
            LOGGER.info("Saving password for {}://{}@{}",
                    new Object[] { parser.getProtocol().getName(), user, parser.getHostname() });
            persistentAuthStore.add(auInfo, lastUserAuthenticationData);
            saveAuthStore();
        }
    }
    return resolveFile;
}