This client uses the REST API to communicate with the Amazon S3 servers and read or write content through a bucket that the user has access to. It is a very lightweight implementation of the S3 API and therefore does not have all of the bells and whistles of popular client implementations.
Authentication is always performed using the user's AWSAccessKeyId and their private AWSSecretAccessKey.
Optional client-side encryption may be enabled if requested. The format is compatible with jets3t, a popular Java based Amazon S3 client library. Enabling encryption can hide sensitive data from the operators of the S3 service.
| Modifier and Type | Class and Description |
|---|---|
| private static class | AmazonS3.
KeyInfo enables sorting of keys by lastModified time |
| pack-priv static interface | AmazonS3.
Property names used in amazon connection configuration file. |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final String | acl
ACL to apply to created objects. |
| private static final String | |
| private static final String | |
| private static final String | |
| private final String | awsApiSignatureVersion
AWS API Signature Version. |
| private final String | domain
S3 Bucket Domain. |
| private final WalkEncryption | encryption
Encryption algorithm, may be a null instance that provides pass-through. |
| private static final String | |
| pack-priv final int | maxAttempts
Maximum number of times to try an operation. |
| private final String | protocol
S3 Protocol, "https" or "http"; defaults to "http". |
| private final ProxySelector | proxySelector
Our HTTP proxy support, in case we are behind a firewall. |
| private final String | publicKey
AWSAccessKeyId, public string that identifies the user's account. |
| private final String | region
S3 Region. |
| private final char[] | secretKey
AWSSecretAccessKey, private string used to access a user's account. |
| private final SecretKeySpec | secretKeySpec
Decoded form of the private AWSSecretAccessKey, to sign requests. |
| private static final Set | |
| private final File | tmpDir
Directory for locally buffered content. |
| private static final String | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | AmazonS3(final Properties
connection properties. props)Create a new S3 client for the supplied user information. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void | |
| public OutputStream | Returns: a stream which accepts the new data, and transmits once closed.name of the bucket storing the object. bucket, final String key of the object within its bucket. key, final ProgressMonitor (optional) progress monitor to post upload completion to
during the stream's close method. monitor, final String (optional) task name to display during the close method. monitorTask)Atomically create or replace a single large object. |
| public InputStream | Returns: stream to read plain text from.connection previously created by u)get(String, String)}.Decrypt an input stream from |
| public void | |
| pack-priv IOException | |
| public URLConnection | Returns: connection to stream the content of the object. The request properties of the connection may not be modified by the caller as the request parameters have already been signed.name of the bucket storing the object. bucket, String key of the object within its bucket. key)Get the content of a bucket object. |
| private static String | |
| private static boolean | |
| public List | Returns: list of keys starting withprefix, after removing
prefix (or prefix + "/")from all
of them.name of the bucket whose objects should be listed. bucket, String common prefix to filter the results by. Must not be null.
Supplying the empty string will list all keys in the bucket.
Supplying a non-empty string will act as though a trailing '/'
appears in prefix, even if it does not. prefix)List the names of keys available within a bucket. |
| pack-priv IOException | |
| private static MessageDigest | |
| private HttpURLConnection | |
| pack-priv HttpURLConnection | |
| pack-priv static Properties | |
| public void | |
| pack-priv void | putImpl(final String bucket, final String key, final byte[] csum, final TemporaryBuffer buf, ProgressMonitor monitor, String monitorTask)
|
| private static String | |
| private static String |
| acl | back to summary |
|---|---|
| private final String acl ACL to apply to created objects. | |
| AWS_API_V2 | back to summary |
|---|---|
| private static final String AWS_API_V2 | |
| AWS_API_V4 | back to summary |
|---|---|
| private static final String AWS_API_V4 | |
| AWS_S3_SERVICE_NAME | back to summary |
|---|---|
| private static final String AWS_S3_SERVICE_NAME | |
| awsApiSignatureVersion | back to summary |
|---|---|
| private final String awsApiSignatureVersion AWS API Signature Version. | |
| domain | back to summary |
|---|---|
| private final String domain S3 Bucket Domain. | |
| encryption | back to summary |
|---|---|
| private final WalkEncryption encryption Encryption algorithm, may be a null instance that provides pass-through. | |
| HMAC | back to summary |
|---|---|
| private static final String HMAC | |
| maxAttempts | back to summary |
|---|---|
| pack-priv final int maxAttempts Maximum number of times to try an operation. | |
| protocol | back to summary |
|---|---|
| private final String protocol S3 Protocol, "https" or "http"; defaults to "http". | |
| proxySelector | back to summary |
|---|---|
| private final ProxySelector proxySelector Our HTTP proxy support, in case we are behind a firewall. | |
| publicKey | back to summary |
|---|---|
| private final String publicKey AWSAccessKeyId, public string that identifies the user's account. | |
| region | back to summary |
|---|---|
| private final String region S3 Region. | |
| secretKey | back to summary |
|---|---|
| private final char[] secretKey AWSSecretAccessKey, private string used to access a user's account. | |
| secretKeySpec | back to summary |
|---|---|
| private final SecretKeySpec secretKeySpec Decoded form of the private AWSSecretAccessKey, to sign requests. | |
| SIGNED_HEADERS | back to summary |
|---|---|
| private static final Set<String> SIGNED_HEADERS | |
| tmpDir | back to summary |
|---|---|
| private final File tmpDir Directory for locally buffered content. | |
| X_AMZ_ACL | back to summary |
|---|---|
| private static final String X_AMZ_ACL | |
| X_AMZ_META | back to summary |
|---|---|
| private static final String X_AMZ_META | |
| AmazonS3 | back to summary |
|---|---|
| public AmazonS3(final Properties props) Create a new S3 client for the supplied user information. The connection properties are a subset of those supported by the popular jets3t library. For example: # AWS API signature version, must be one of: # 2 - deprecated (not supported in all AWS regions) # 4 - latest (supported in all AWS regions) # Defaults to 2. aws.api.signature.version: 4 # AWS Access and Secret Keys (required) accesskey: <YourAWSAccessKey> secretkey: <YourAWSSecretKey> # Access Control List setting to apply to uploads, must be one of: # PRIVATE, PUBLIC_READ (defaults to PRIVATE). acl: PRIVATE # S3 Domain # AWS S3 Region Domain (defaults to s3.amazonaws.com) domain: s3.amazonaws.com # AWS S3 Region (required if aws.api.signature.version = 4) region: us-west-2 # Number of times to retry after internal error from S3. httpclient.retry-max: 3 # End-to-end encryption (hides content from S3 owners) password: <encryption pass-phrase> crypto.algorithm: PBEWithMD5AndDES
| |
| authorize | back to summary |
|---|---|
| pack-priv void authorize(HttpURLConnection httpURLConnection, Map<String, String> queryParams, long contentLength, final String bodyHash) throws IOException | |
| authorizeV2 | back to summary |
|---|---|
| pack-priv void authorizeV2(HttpURLConnection c) throws IOException | |
| beginPut | back to summary |
|---|---|
| public OutputStream beginPut(final String bucket, final String key, final ProgressMonitor monitor, final String monitorTask) throws IOException Atomically create or replace a single large object. Initially the returned output stream buffers data into memory, but if the total number of written bytes starts to exceed an internal limit the data is spooled to a temporary file on the local drive.
Network transmission is attempted only when End-to-end data integrity is assured by internally computing the MD5 checksum of the supplied data and transmitting the checksum along with the data itself.
| |
| decrypt | back to summary |
|---|---|
| public InputStream decrypt(URLConnection u) throws IOException Decrypt an input stream from
| |
| delete | back to summary |
|---|---|
| public void delete(String bucket, String key) throws IOException Delete a single object. Deletion always succeeds, even if the object does not exist.
| |
| error | back to summary |
|---|---|
| pack-priv IOException error(final String action, final String key, final HttpURLConnection c) throws IOException | |
| get | back to summary |
|---|---|
| public URLConnection get(String bucket, String key) throws IOException Get the content of a bucket object.
| |
| httpNow | back to summary |
|---|---|
| private static String httpNow() | |
| isSignedHeader | back to summary |
|---|---|
| private static boolean isSignedHeader(String name) | |
| list | back to summary |
|---|---|
| public List List the names of keys available within a bucket. This method is primarily meant for obtaining a "recursive directory listing" rooted under the specified bucket and prefix location. It returns the keys sorted in reverse order of LastModified time (freshest keys first).
| |
| maxAttempts | back to summary |
|---|---|
| pack-priv IOException maxAttempts(String action, String key) | |
| newMD5 | back to summary |
|---|---|
| private static MessageDigest newMD5() | |
| open | back to summary |
|---|---|
| private HttpURLConnection open(final String method, final String bucket, final String key) throws IOException | |
| open | back to summary |
|---|---|
| pack-priv HttpURLConnection open(final String method, final String bucket, final String key, final Map<String, String> args) throws IOException | |
| properties | back to summary |
|---|---|
| pack-priv static Properties properties(File authFile) throws FileNotFoundException, IOException | |
| put | back to summary |
|---|---|
| public void put(String bucket, String key, byte[] data) throws IOException Atomically create or replace a single small object. This form is only suitable for smaller contents, where the caller can reasonable fit the entire thing into memory. End-to-end data integrity is assured by internally computing the MD5 checksum of the supplied data and transmitting the checksum along with the data itself.
| |
| putImpl | back to summary |
|---|---|
| pack-priv void putImpl(final String bucket, final String key, final byte[] csum, final TemporaryBuffer buf, ProgressMonitor monitor, String monitorTask) throws IOException | |
| remove | back to summary |
|---|---|
| private static String remove(Map<String, String> m, String k) | |
| toCleanString | back to summary |
|---|---|
| private static String toCleanString(List<String> list) | |
| Modifier and Type | Field and Description |
|---|---|
| private final long | |
| private final String |
| Modifier and Type | Method and Description |
|---|---|
| public long | |
| public String |
| lastModifiedSecs | back to summary |
|---|---|
| private final long lastModifiedSecs | |
| name | back to summary |
|---|---|
| private final String name | |
| KeyInfo | back to summary |
|---|---|
| public KeyInfo(String aname, long lsecs) | |
| getLastModifiedSecs | back to summary |
|---|---|
| public long getLastModifiedSecs() | |
| getName | back to summary |
|---|---|
| public String getName() | |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | |
| public static final String | |
| public static final String | |
| public static final String | |
| public static final String | |
| public static final String | |
| public static final String | |
| public static final String | |
| public static final String | |
| public static final String | |
| public static final String | |
| public static final String |
| ACCESS_KEY | back to summary |
|---|---|
| public static final String ACCESS_KEY | |
| ACL | back to summary |
|---|---|
| public static final String ACL | |
| AWS_API_SIGNATURE_VERSION | back to summary |
|---|---|
| public static final String AWS_API_SIGNATURE_VERSION | |
| CRYPTO_ALG | back to summary |
|---|---|
| public static final String CRYPTO_ALG | |
| CRYPTO_VER | back to summary |
|---|---|
| public static final String CRYPTO_VER | |
| DOMAIN | back to summary |
|---|---|
| public static final String DOMAIN | |
| HTTP_RETRY | back to summary |
|---|---|
| public static final String HTTP_RETRY | |
| PASSWORD | back to summary |
|---|---|
| public static final String PASSWORD | |
| PROTOCOL | back to summary |
|---|---|
| public static final String PROTOCOL | |
| REGION | back to summary |
|---|---|
| public static final String REGION | |
| SECRET_KEY | back to summary |
|---|---|
| public static final String SECRET_KEY | |
| TMP_DIR | back to summary |
|---|---|
| public static final String TMP_DIR | |
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private StringBuilder | |
| pack-priv final List | |
| private Instant | |
| private String | |
| private final String | |
| pack-priv boolean |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | characters(char[]
The characters. ch, int The start position in the character array. s, int The number of characters to use from the
character array. n)Overrides org. Implements org. Receive notification of character data inside an element. |
| public void | endElement(final String
The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed. uri, final String The local name (without prefix), or the
empty string if Namespace processing is not being
performed. name, final String The qualified name (with prefix), or the
empty string if qualified names are not available. qName)Overrides org. Implements org. Receive notification of the end of an element. |
| public void | ignorableWhitespace(final char[]
The whitespace characters. ch, final int The start position in the character array. s, final int The number of characters to use from the
character array. n)Overrides org. Implements org. Receive notification of ignorable whitespace in element content. |
| pack-priv void | |
| public void | startElement(final String
The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed. uri, final String The local name (without prefix), or the
empty string if Namespace processing is not being
performed. name, final String The qualified name (with prefix), or the
empty string if qualified names are not available. qName, final Attributes The attributes attached to the element. If
there are no attributes, it shall be an empty
Attributes object. attributes)Overrides org. Implements org. Receive notification of the start of an element. |
| bucket | back to summary |
|---|---|
| private final String bucket | |
| data | back to summary |
|---|---|
| private StringBuilder data | |
| entries | back to summary |
|---|---|
| pack-priv final List<AmazonS3. | |
| keyLastModified | back to summary |
|---|---|
| private Instant keyLastModified | |
| keyName | back to summary |
|---|---|
| private String keyName | |
| prefix | back to summary |
|---|---|
| private final String prefix | |
| truncated | back to summary |
|---|---|
| pack-priv boolean truncated | |
| ListParser | back to summary |
|---|---|
| pack-priv ListParser(String bn, String p) | |
| characters | back to summary |
|---|---|
| public void characters(char[] ch, int s, int n) throws SAXException Overrides org. Implements org. Doc from org. Receive notification of character data inside an element. By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).
| |
| endElement | back to summary |
|---|---|
| public void endElement(final String uri, final String name, final String qName) throws SAXException Overrides org. Implements org. Doc from org. Receive notification of the end of an element. By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).
| |
| ignorableWhitespace | back to summary |
|---|---|
| public void ignorableWhitespace(final char[] ch, final int s, final int n) throws SAXException Overrides org. Implements org. Doc from org. Receive notification of ignorable whitespace in element content. By default, do nothing. Application writers may override this method to take specific actions for each chunk of ignorable whitespace (such as adding data to a node or buffer, or printing it to a file).
| |
| list | back to summary |
|---|---|
| pack-priv void list() throws IOException | |
| startElement | back to summary |
|---|---|
| public void startElement(final String uri, final String name, final String qName, final Attributes attributes) throws SAXException Overrides org. Implements org. Doc from org. Receive notification of the start of an element. By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).
| |