Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 1.13 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package org.springframework.aws;
  2.  
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import org.apache.tools.ant.BuildException;
  8. import org.jets3t.service.S3Service;
  9. import org.jets3t.service.S3ServiceException;
  10. import org.jets3t.service.impl.rest.httpclient.RestS3Service;
  11. import org.jets3t.service.security.AWSCredentials;
  12.  
  13. public class SimpleStorageService {
  14.  
  15.         private String accessKey;
  16.  
  17.         private String secretKey;
  18.  
  19.         private List<Upload> uploads = new ArrayList<Upload>();
  20.  
  21.         public void setAccessKey(String accessKey) {
  22.                 this.accessKey = accessKey;
  23.         }
  24.  
  25.         public void setSecretKey(String secretKey) {
  26.                 this.secretKey = secretKey;
  27.         }
  28.  
  29.         public void addConfiguredUpload(Upload upload) {
  30.                 uploads.add(upload);
  31.         }
  32.  
  33.         public void execute() {
  34.                 try {
  35.                         AWSCredentials credentials = new AWSCredentials(accessKey, secretKey);
  36.                         S3Service service = new RestS3Service(credentials);
  37.  
  38.                         for (Upload upload : uploads) {
  39.                                 upload.upload(service);
  40.                         }
  41.                 } catch (S3ServiceException e) {
  42.                         throw new BuildException(e);
  43.                 } catch (IOException e) {
  44.                         throw new BuildException(e);
  45.                 }
  46.         }
  47.  
  48. }