Example usage for com.amazonaws.services.s3.transfer TransferManagerBuilder standard

List of usage examples for com.amazonaws.services.s3.transfer TransferManagerBuilder standard

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.transfer TransferManagerBuilder standard.

Prototype

public static TransferManagerBuilder standard() 

Source Link

Usage

From source file:com.att.aro.core.cloud.aws.AwsRepository.java

License:Apache License

private void constructRepo(String accessId, String secretKey, String region, String bucketName,
        ClientConfiguration config) {// w  w  w. j  av a  2  s .co  m
    System.setProperty("java.net.useSystemProxies", "true");
    if (isNotBlank(accessId) && isNotBlank(secretKey) && isNotBlank(region) && isNotBlank(bucketName)) {
        try {
            AWSCredentials creds = new BasicAWSCredentials(accessId, secretKey);
            Regions regions = Regions.fromName(region);
            this.bucketName = bucketName;
            s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds))
                    .withRegion(regions).withClientConfiguration(config).build();
            transferMgr = TransferManagerBuilder.standard().withS3Client(s3Client).build();
        } catch (IllegalArgumentException ille) {
            LOGGER.error(ille.getMessage(), ille);
        } catch (Exception exp) {
            LOGGER.error(exp.getMessage(), exp);
        }
    }
}

From source file:com.dragovorn.dragonbot.DragonBot.java

License:Open Source License

@Override
public void start() {
    setState(BotState.STARTING);/*from   w  ww. ja  va 2  s .c om*/

    AmazonS3 client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
    this.transferManager = TransferManagerBuilder.standard().withS3Client(client).build();

    UpdatePanel update = new UpdatePanel();

    new MainWindow(update);

    if (Bot.getInstance().getConfiguration().getCheckForUpdates()) {
        getLogger().info("Checking for newer version of the updater...");

        try {
            if (client
                    .getObjectMetadata(
                            new GetObjectMetadataRequest("dl.dragovorn.com", "DragonBot/updater.jar"))
                    .getLastModified().getTime() > FileManager.getUpdater().lastModified()) {
                getLogger().info("Found a newer version of the updater, downloading it now...");

                FileManager.getUpdater().delete();

                GetObjectRequest request = new GetObjectRequest("dl.dragovorn.com", "DragonBot/updater.jar");

                try {
                    this.transferManager.download(request, FileManager.getUpdater()).waitForCompletion();
                } catch (InterruptedException exception) {
                    /* Shouldn't happen */ }
            }
        } catch (Throwable throwable) {
            getLogger().info("Unable to connect to the internet!");
        }

        getLogger().info("Checking for updates...");
        update.update();

        if (update.shouldStop()) {
            stop();
            return;
        }
    }

    getLogger().info("Initializing Dragon Bot v" + getVersion() + "!");

    this.name = this.config.getName();
    this.auth = this.config.getAuth();

    this.commandManager.registerCommand(new Github());
    this.commandManager.registerCommand(new VersionCmd());

    this.pluginManager.enablePlugins();

    if (!this.name.equals("") && !this.config.getAuth().equals("")) {
        getLogger().info("Connecting to twitch!");

        try {
            connect();
        } catch (ConnectionException | IOException exception) {
            getLogger().info("Unable to connect!");
        }

        if (this.config.getAutoConnect() && !this.config.getChannel().equals("")) {
            getLogger().info("Automatically connected to " + this.config.getChannel());

            connectTo("#" + this.config.getChannel());
        }
    } else {
        String buttons[] = { "Ok" };

        JOptionPane.showOptionDialog(null,
                "You don't have a twitch account configured! Please set the bot's twitch account in the options menu!",
                "Twitch Account", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, buttons,
                buttons[0]);

        getLogger().info("No twitch account detected.");
    }

    if (!this.isConnected()) {
        MainWindow.getInstance().getChannelButton().setEnabled(false);
        MainWindow.getInstance().getChannelButton()
                .setToolTipText("The current account was unable to connect!");
    }

    setState(BotState.RUNNING);

    MainWindow.getInstance().setContentPane(MainWindow.getInstance().getPanel());
    MainWindow.getInstance().pack();
    MainWindow.getInstance().center();

    getLogger().info("Dragon Bot v" + getVersion() + " initialized!");
}

From source file:com.emc.vipr.s3.sample._10_ReadLargeObjectTM.java

License:Open Source License

public static void main(String[] args) throws Exception {
    // create the AWS S3 Client
    AmazonS3 s3 = AWSS3Factory.getS3Client();

    // retrieve the key value from user
    System.out.println("Enter the object key:");
    String key = new BufferedReader(new InputStreamReader(System.in)).readLine();

    // print start time
    Date start_date = new Date();
    System.out.println(start_date.toString());

    // file will be placed in temp dir with .tmp extension
    File file = File.createTempFile("read-large-object-tm", null);

    TransferManager tm = TransferManagerBuilder.standard().withS3Client(s3).build();

    // download the object to file
    Download download = tm.download(AWSS3Factory.S3_BUCKET, key, file);

    // block until download finished
    download.waitForCompletion();/*ww  w . j av a2  s.com*/

    tm.shutdownNow();

    // print end time
    Date end_date = new Date();
    System.out.println(end_date.toString());
}

From source file:com.github.kaklakariada.aws.sam.task.S3UploadTask.java

License:Open Source License

private TransferManager createTransferManager() {
    return TransferManagerBuilder.standard().withS3Client(getS3Client()).build();
}

From source file:com.netflix.genie.common.internal.aws.s3.S3ClientFactory.java

License:Apache License

private TransferManager buildTransferManager(final AmazonS3 s3Client) {
    // TODO: Perhaps want to supply more options?
    return TransferManagerBuilder.standard().withS3Client(s3Client).build();
}

From source file:com.streamsets.datacollector.lib.emr.S3Manager.java

License:Apache License

S3Manager(EmrClusterConfig pipelineEmrConfigs, String pipelineId, String uniquePrefix,
        List<File> filesToUpload) {
    this.pipelineEmrConfigs = pipelineEmrConfigs;
    this.pipelineId = pipelineId;
    this.uniquePrefix = uniquePrefix;
    this.filesToUpload = filesToUpload;
    s3Client = getS3Client();//from   w ww  .  j  a v a  2s.com
    int uploadThreads = Integer.parseInt(System.getProperty("sdc.emr.s3.uploadThreads", "5"));
    s3TransferManager = TransferManagerBuilder.standard().withS3Client(s3Client)
            .withMultipartUploadThreshold(10L * 1024 * 1024).withMinimumUploadPartSize(10L * 1024 * 1024)
            .withExecutorFactory(() -> Executors.newFixedThreadPool(uploadThreads))
            .withShutDownThreadPools(true).build();
}

From source file:com.streamsets.pipeline.lib.aws.s3.S3Accessor.java

License:Apache License

TransferManagerBuilder createTransferManagerBuilder() {
    return TransferManagerBuilder.standard();
}

From source file:com.vitembp.services.interfaces.AmazonSimpleStorageService.java

License:Open Source License

/**
 * Initializes a new instance of the AmazonSQS class.
 * @param bucketName The name of the queue to connect to.
 *///from   ww  w .j a  va2  s.  c  o m
public AmazonSimpleStorageService(String bucketName) {
    // save parameters
    this.bucketName = bucketName;

    // builds a client with credentials
    AmazonS3 client = AmazonS3Client.builder().build();

    // builds a transfer manager from the client
    this.transferManager = TransferManagerBuilder.standard().withS3Client(client).build();
}

From source file:jetbrains.buildServer.util.amazon.S3Util.java

License:Apache License

@NotNull
private static <T extends Transfer> Collection<T> withTransferManager(@NotNull final AmazonS3Client s3Client,
        final boolean shutdownClient, @NotNull final WithTransferManager<T> withTransferManager)
        throws Throwable {

    final TransferManager manager = TransferManagerBuilder.standard().withS3Client(s3Client)
            .withExecutorFactory(createExecutorFactory(createDefaultExecutorService()))
            .withShutDownThreadPools(true).build();

    try {//from w  w  w  . j a v a 2  s  .  com
        final ArrayList<T> transfers = new ArrayList<T>(withTransferManager.run(manager));

        final AtomicBoolean isInterrupted = new AtomicBoolean(false);

        if (withTransferManager instanceof InterruptAwareWithTransferManager) {
            final TransferManagerInterruptHook hook = new TransferManagerInterruptHook() {
                @Override
                public void interrupt() throws Throwable {
                    isInterrupted.set(true);

                    for (T transfer : transfers) {
                        if (transfer instanceof Download) {
                            ((Download) transfer).abort();
                            continue;
                        }

                        if (transfer instanceof Upload) {
                            ((Upload) transfer).abort();
                            continue;
                        }

                        if (transfer instanceof MultipleFileDownload) {
                            ((MultipleFileDownload) transfer).abort();
                            continue;
                        }

                        LOG.warn("Transfer type " + transfer.getClass().getName()
                                + " does not support interrupt");
                    }
                }
            };
            ((InterruptAwareWithTransferManager) withTransferManager).setInterruptHook(hook);
        }

        for (T transfer : transfers) {
            try {
                transfer.waitForCompletion();
            } catch (Throwable t) {
                if (!isInterrupted.get()) {
                    throw t;
                }
            }
        }

        return CollectionsUtil.filterCollection(transfers, new Filter<T>() {
            @Override
            public boolean accept(@NotNull T data) {
                return Transfer.TransferState.Completed == data.getState();
            }
        });
    } finally {
        manager.shutdownNow(shutdownClient);
    }
}

From source file:jp.classmethod.aws.gradle.s3.AmazonS3ProgressiveFileUploadTask.java

License:Apache License

@TaskAction
public void upload() throws InterruptedException {
    // to enable conventionMappings feature
    String bucketName = getBucketName();
    String key = getKey();/* w  w w  .j a va 2 s. c  o  m*/
    File file = getFile();

    if (bucketName == null) {
        throw new GradleException("bucketName is not specified");
    }
    if (key == null) {
        throw new GradleException("key is not specified");
    }
    if (file == null) {
        throw new GradleException("file is not specified");
    }
    if (file.isFile() == false) {
        throw new GradleException("file must be regular file");
    }

    AmazonS3PluginExtension ext = getProject().getExtensions().getByType(AmazonS3PluginExtension.class);
    AmazonS3 s3 = ext.getClient();

    TransferManager s3mgr = TransferManagerBuilder.standard().withS3Client(s3).build();
    getLogger().info("Uploading... s3://{}/{}", bucketName, key);

    Upload upload = s3mgr.upload(
            new PutObjectRequest(getBucketName(), getKey(), getFile()).withMetadata(getObjectMetadata()));
    upload.addProgressListener(new ProgressListener() {

        public void progressChanged(ProgressEvent event) {
            getLogger().info("  {}% uploaded", upload.getProgress().getPercentTransferred());
        }
    });
    upload.waitForCompletion();
    setResourceUrl(s3.getUrl(bucketName, key).toString());
    getLogger().info("Upload completed: {}", getResourceUrl());
}