amazon glacier Low Level Archive Retriever - Java AWS

Java examples for AWS:Glacier

Description

amazon glacier Low Level Archive Retriever

Demo Code


import java.io.IOException;
import java.util.Date;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.amazonaws.services.glacier.model.InitiateJobRequest;
import com.amazonaws.services.glacier.model.InitiateJobResult;
import com.amazonaws.services.glacier.model.JobParameters;


public class LowLevelArchiveRetriever {

    public static String vaultName = "GLACIER_TEST";
    public static String archiveId = "ArchiveId";

    public static void main(String[] args) throws IOException {
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.setProxyHost("xx.xx.xx.xx");
        clientConfiguration.setProxyPort(0);

        AWSCredentials credentials = new PropertiesCredentials(
                VaultCreator.class
                        .getResourceAsStream("AwsCredentials.properties"));
        AmazonGlacierClient client = new AmazonGlacierClient(credentials,
                clientConfiguration);/*from  w  ww  .j a  v  a 2  s . c  o m*/
        client.setEndpoint("https://glacier.ap-northeast-1.amazonaws.com/");
        try {
            InitiateJobRequest initiateJobRequest = new InitiateJobRequest()
                    .withVaultName(vaultName).withJobParameters(
                            new JobParameters().withArchiveId(archiveId)
                                    .withType("archive-retrieval"));
            InitiateJobResult initiateJobResult = client
                    .initiateJob(initiateJobRequest);
            String jobId = initiateJobResult.getJobId();
            System.out.println("initiate archive-retrieval job:jobId="
                    + jobId + ",startTime:" + new Date());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials