public class S3URI
extends java.lang.Object
s3://<bucket>/<key>
.
Instances of this class are immutable.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
S3_DELIMITER |
static java.lang.String |
S3_PREFIX |
static java.io.File |
S3ObjectTempDir |
Constructor and Description |
---|
S3URI(java.lang.String uri)
Creates a S3URI by extracting the S3 bucket and key names from
uri . |
S3URI(java.lang.String bucket,
java.lang.String key)
Creates a S3URI from the specified bucket and key.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
java.lang.String |
getBaseName()
Returns the base name of the file or directory denoted by this URI.
|
java.lang.String |
getBucket()
Returns the bucket.
|
S3URI |
getChild(java.lang.String relativePath)
Creates a new URI by resolving the specified path relative to
this . |
java.lang.String |
getKey()
Returns the key.
|
java.lang.String |
getKeyWithTrailingDelimiter()
Returns the key, adding a trailing
delimiter . |
S3URI |
getParent()
Returns the parent URI of this URI.
|
java.io.File |
getTempFile()
Gets a temporary file to which the content of the S3Object that this URI points to can be downloaded.
|
int |
hashCode() |
java.lang.String |
toString()
Returns a string representation of the URI in the form
s3://<bucket>/<key> . |
public static final java.lang.String S3_PREFIX
public static final java.lang.String S3_DELIMITER
public static final java.io.File S3ObjectTempDir
public S3URI(java.lang.String uri)
uri
. If the key has a trailing
delimiter
, it will be removed.uri
- an S3 URI in the form s3://<bucket>/<key>
.java.lang.IllegalArgumentException
- if uri
is not in the expected form or if the bucket or key are invalid.S3URI(String, String)
public S3URI(java.lang.String bucket, java.lang.String key) throws java.lang.IllegalArgumentException
delimiter
, it will be removed.bucket
- a bucket name. Must be non-null
and at least 3 characters.key
- a key. May be null
but cannot be the empty string. Also, it may not contain consecutive
delimiters.java.lang.IllegalArgumentException
- if either argument fails the requirements.public java.lang.String getBucket()
public java.lang.String getKey()
null
if the URI did not include a key, e.g. "s3://bucket". If not null,
any trailing #S3_DELIMITER delimiter
the key had when passed to the constructor will have been stripped.public java.lang.String getKeyWithTrailingDelimiter()
public java.lang.String getBaseName()
null
, null
is returned.public S3URI getParent()
delimiter
. If the key is null
, null
is returned. If it is non-null
,
but doesn't have a logical parent, the returned URI will have a null
key (but the same bucket).
For example, the parent of s3://my-bucket/my-key
(bucket="my-bucket", key="my-key") will be
s3://my-bucket
(bucket=="my-bucket", key=null).public S3URI getChild(java.lang.String relativePath) throws java.lang.IllegalArgumentException
this
. If key == null
, the key
of the returned URI will simply be relativePath
.relativePath
- a path relative to this
. Must be non-null.java.lang.IllegalArgumentException
- if the path starts with a delimiter
.
The path must be relative.public java.io.File getTempFile()
${java.io.tmpdir}/S3Objects/${hashCode()}/${getBaseName()}
.
This method does not cause the file to be created; we're just returning a suitable path.public java.lang.String toString()
s3://<bucket>/<key>
.toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object