com.leverno.ysbos.archive.example.ArchiveDownloadHighLevel.java Source code

Java tutorial

Introduction

Here is the source code for com.leverno.ysbos.archive.example.ArchiveDownloadHighLevel.java

Source

/**
 *     Copyright (C) 2012  Werner van Rensburg
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.leverno.ysbos.archive.example;

import java.io.File;
import java.io.IOException;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.amazonaws.services.glacier.transfer.ArchiveTransferManager;
import com.amazonaws.services.sns.AmazonSNSClient;
import com.amazonaws.services.sqs.AmazonSQSClient;
import com.leverno.ysbos.common.Constants;

public class ArchiveDownloadHighLevel {
    public static String vaultName = Constants.vault;
    public static String archiveId = "lsUNX7NVqYl_KVJ-KS2T4EZsIcMpaSgJ4pb3u5rQEPbt3EZI50eruWJZnDDJXa3mbGBNcJhxJBVR742t2bS60N7m1KRyvhrj35wqFEfT-bMjFcb7XqbYisY2StUTKYQOkPapUTkwmg";
    public static String downloadFilePath = "/home/vern/Pictures/aws.download.jpg";

    public static AmazonGlacierClient glacier;

    public static void main(String[] args) throws IOException {

        AWSCredentials credentials = getCredentials();
        AmazonSQSClient sqs = new AmazonSQSClient(credentials);
        AmazonSNSClient sns = new AmazonSNSClient(credentials);

        glacier = new AmazonGlacierClient(credentials);
        glacier.setEndpoint(Constants.endpoint);
        sqs.setEndpoint(Constants.endpoint);
        sns.setEndpoint(Constants.endpoint);

        try {
            ArchiveTransferManager atm = new ArchiveTransferManager(glacier, sqs, sns);

            atm.download(vaultName, archiveId, new File(downloadFilePath));

        } catch (Exception e) {
            System.err.println(e);
        }
    }

    public static AWSCredentials getCredentials() {
        AWSCredentials credentials = null;

        try {
            credentials = new PropertiesCredentials(new File(Constants.propertiesPath));
        } catch (IOException e) {
            e.printStackTrace();
        }

        return credentials;
    }

}