org.lastbamboo.common.amazon.s3
Class AmazonS3Impl

java.lang.Object
  extended by org.lastbamboo.common.amazon.s3.AmazonS3Impl
All Implemented Interfaces:
AmazonS3

public class AmazonS3Impl
extends Object
implements AmazonS3

Class implementing REST calls to Amazon's S3 service.


Constructor Summary
AmazonS3Impl()
          Creates a new S3 instance.
 
Method Summary
 void createBucket(String bucketName)
          Creates a new bucket.
 void delete(String bucketName, String fileName)
          Deletes the specified file.
 void deleteBucket(String bucketName)
          Deletes the bucket with the specified name.
 void deleteStar(String bucketName, String fileName)
          Deletes all of the files in the specified bucket matching the specified pattern.
 void getPrivateFile(String bucketName, String fileName, File target)
          Downloads a file from the specified bucket and file name to the specified local path.
 void getPublicFile(String bucketName, String fileName, File target)
          Downloads a file from the specified bucket and file name to the specified local path.
 void listBucket(String bucketName)
          List all the files in the bucket.
 void listBuckets()
          Lists all the user's buckets.
 void normalizeRequest(org.apache.commons.httpclient.HttpMethod method, String methodString, String fullPath, boolean addPublicHeader, boolean useAuth)
          Normalizes the HTTP request headers with things like the authentication token, the date, etc.
 void putPrivateDir(String bucketName, File dir)
          Adds all the files in the specified directory to the specified bucket.
 void putPrivateFile(String bucketName, File file)
          Uploads a file to S3.
 void putPublicDir(String bucketName, File dir)
          Adds all the files in the specified directory to the specified bucket.
 void putPublicFile(String bucketName, File file)
          Uploads a file to S3 that will be publicly available.
 void putPublicFile(String bucketName, File file, String mimeType)
          Uploads a file to S3 that will be publicly available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AmazonS3Impl

public AmazonS3Impl()
             throws IOException
Creates a new S3 instance.

Throws:
IOException - If the props file can't be found or keys can't be read.
Method Detail

getPrivateFile

public void getPrivateFile(String bucketName,
                           String fileName,
                           File target)
                    throws IOException
Description copied from interface: AmazonS3
Downloads a file from the specified bucket and file name to the specified local path.

Specified by:
getPrivateFile in interface AmazonS3
Parameters:
bucketName - The name of the Amazon S3 bucket.
fileName - The name of the file within the bucket.
target - The name of the local file to download to.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

getPublicFile

public void getPublicFile(String bucketName,
                          String fileName,
                          File target)
                   throws IOException
Description copied from interface: AmazonS3
Downloads a file from the specified bucket and file name to the specified local path. The specified file must be publicly available in S3.

Specified by:
getPublicFile in interface AmazonS3
Parameters:
bucketName - The name of the Amazon S3 bucket.
fileName - The name of the file within the bucket.
target - The name of the local file to download to.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

putPrivateFile

public void putPrivateFile(String bucketName,
                           File file)
                    throws IOException
Description copied from interface: AmazonS3
Uploads a file to S3.

Specified by:
putPrivateFile in interface AmazonS3
Parameters:
bucketName - The name of the bucket.
file - The file to upload.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

putPrivateDir

public void putPrivateDir(String bucketName,
                          File dir)
                   throws IOException
Description copied from interface: AmazonS3
Adds all the files in the specified directory to the specified bucket.

Specified by:
putPrivateDir in interface AmazonS3
Parameters:
bucketName - The name of the bucket to list.
dir - The directory containing files to add.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

putPublicFile

public void putPublicFile(String bucketName,
                          File file)
                   throws IOException
Description copied from interface: AmazonS3
Uploads a file to S3 that will be publicly available.

Specified by:
putPublicFile in interface AmazonS3
Parameters:
bucketName - The name of the bucket.
file - The file to upload.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

putPublicFile

public void putPublicFile(String bucketName,
                          File file,
                          String mimeType)
                   throws IOException
Description copied from interface: AmazonS3
Uploads a file to S3 that will be publicly available.

Specified by:
putPublicFile in interface AmazonS3
Parameters:
bucketName - The name of the bucket.
file - The file to upload.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

putPublicDir

public void putPublicDir(String bucketName,
                         File dir)
                  throws IOException
Description copied from interface: AmazonS3
Adds all the files in the specified directory to the specified bucket.

Specified by:
putPublicDir in interface AmazonS3
Parameters:
bucketName - The name of the bucket to list.
dir - The directory containing files to add.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

createBucket

public void createBucket(String bucketName)
                  throws IOException
Description copied from interface: AmazonS3
Creates a new bucket.

Specified by:
createBucket in interface AmazonS3
Parameters:
bucketName - The name of the bucket.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

listBuckets

public void listBuckets()
                 throws IOException
Description copied from interface: AmazonS3
Lists all the user's buckets.

Specified by:
listBuckets in interface AmazonS3
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

listBucket

public void listBucket(String bucketName)
                throws IOException
Description copied from interface: AmazonS3
List all the files in the bucket.

Specified by:
listBucket in interface AmazonS3
Parameters:
bucketName - The name of the bucket to list.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

deleteBucket

public void deleteBucket(String bucketName)
                  throws IOException
Description copied from interface: AmazonS3
Deletes the bucket with the specified name.

Specified by:
deleteBucket in interface AmazonS3
Parameters:
bucketName - The name of the bucket to delete.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

delete

public void delete(String bucketName,
                   String fileName)
            throws IOException
Description copied from interface: AmazonS3
Deletes the specified file.

Specified by:
delete in interface AmazonS3
Parameters:
bucketName - The bucket.
fileName - The file name.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

deleteStar

public void deleteStar(String bucketName,
                       String fileName)
                throws IOException
Description copied from interface: AmazonS3
Deletes all of the files in the specified bucket matching the specified pattern. Far from allowing full regular expressions, this just simply allows the star expander at the beginning or end of the file name, or both, such as "*.txt*, "file*" or *ile*".

Specified by:
deleteStar in interface AmazonS3
Parameters:
bucketName - The bucket.
fileName - The file(s) to delete. This can be of the form "*.txt*, "file*" or *ile*", for example.
Throws:
IOException - If we could either could not make a network connection to S3 or could not understand the HTTP exchange.

normalizeRequest

public void normalizeRequest(org.apache.commons.httpclient.HttpMethod method,
                             String methodString,
                             String fullPath,
                             boolean addPublicHeader,
                             boolean useAuth)
Description copied from interface: AmazonS3
Normalizes the HTTP request headers with things like the authentication token, the date, etc.

Specified by:
normalizeRequest in interface AmazonS3
Parameters:
method - The HTTP method.
methodString - The HTTP method string, such as "PUT" or "GET".
fullPath - The full path for the resource.
addPublicHeader - Whether or not to add the header to make a resource publicly accessible, as in:

x-amz-acl: public-read

useAuth - Whether or not to add the authentication header.


Copyright © 2013 LittleShoot. All Rights Reserved.