Example usage for org.apache.commons.vfs UserAuthenticationData cleanup

List of usage examples for org.apache.commons.vfs UserAuthenticationData cleanup

Introduction

In this page you can find the example usage for org.apache.commons.vfs UserAuthenticationData cleanup.

Prototype

public void cleanup() 

Source Link

Document

deleted all data stored within this authenticator

Usage

From source file:com.thinkberg.vfs.s3.S3FileProvider.java

/**
 * Create a file system with the S3 root provided.
 *
 * @param fileName          the S3 file name that defines the root (bucket)
 * @param fileSystemOptions file system options
 * @return an S3 file system//from w ww.  j a  v a  2 s .  com
 * @throws FileSystemException if te file system cannot be created
 */
protected FileSystem doCreateFileSystem(FileName fileName, FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    LOG.debug(String.format("creating new file system '%s'", fileName));
    if (null == service) {
        LOG.debug("creating new S3 service");
        UserAuthenticationData authenticationInfo = UserAuthenticatorUtils.authenticate(fileSystemOptions,
                AUTHENTICATOR_TYPES);
        String accessKey = UserAuthenticatorUtils.toString(
                UserAuthenticatorUtils.getData(authenticationInfo, UserAuthenticationData.USERNAME, null));
        String secretKey = UserAuthenticatorUtils.toString(
                UserAuthenticatorUtils.getData(authenticationInfo, UserAuthenticationData.PASSWORD, null));

        try {
            service = new RestS3Service(new AWSCredentials(accessKey, secretKey));
        } catch (S3ServiceException e) {
            throw new FileSystemException("Amazon S3 service initialization failed", e);
        } finally {
            authenticationInfo.cleanup();
        }
    }

    return new Jets3tFileSystem(service, (S3FileName) fileName, fileSystemOptions);
}