Package com.google.cloud.hadoop.gcsio
Class StorageResourceId
- java.lang.Object
-
- com.google.cloud.hadoop.gcsio.StorageResourceId
-
public class StorageResourceId extends Object
Data struct representing either a GCS StorageObject, a GCS Bucket or the GCS root (gs://). If both bucketName and objectName are null, the StorageResourceId refers to GCS root (gs://). If bucketName is non-null, and objectName is null, then this refers to a GCS Bucket. Otherwise, if bucketName and objectName are both non-null, this refers to a GCS StorageObject.
-
-
Field Summary
Fields Modifier and Type Field Description static StorageResourceIdROOTstatic longUNKNOWN_GENERATION_ID
-
Constructor Summary
Constructors Constructor Description StorageResourceId(String bucketName)Constructor for a StorageResourceId representing a Bucket;getObjectName()will return null for a StorageResourceId that represents a Bucket.StorageResourceId(String bucketName, long generationId)Constructor for a StorageResourceId representing a full StorageObject, including bucketName and objectName.StorageResourceId(String bucketName, String objectName)Constructor for a StorageResourceId representing a full StorageObject, including bucketName and objectName.StorageResourceId(String bucketName, String objectName, long generationId)Constructor for a StorageResourceId representing a full StorageObject, including bucketName and objectName.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)static StorageResourceIdfromStringPath(String path)ParsesStorageResourceIdfrom specified string.static StorageResourceIdfromStringPath(String path, long generationId)ParsesStorageResourceIdfrom specified string and generationId.static StorageResourceIdfromUriPath(URI path, boolean allowEmptyObjectName)Validates the given URI and if valid, returns the associated StorageResourceId.static StorageResourceIdfromUriPath(URI path, boolean allowEmptyObjectName, long generationId)Validates the given URI and if valid, returns the associated StorageResourceId.StringgetBucketName()Gets the bucket name component of this resource identifier.longgetGenerationId()The generationId to be used with precondition checks when using this StorageResourceId as an identifier for mutation requests.StringgetObjectName()Gets the object name component of this resource identifier.booleanhasGenerationId()Returns true if generationId is not UNKNOWN_GENERATION_ID.inthashCode()booleanisBucket()Returns true if this StorageResourceId represents a GCS Bucket; if true, thengetObjectNamewill return null.booleanisDirectory()Indicates if this StorageResourceId corresponds to a 'directory'; similar toFileInfo.isDirectory()except deals entirely with pathnames instead of also checking for exists() to be true on a corresponding GoogleCloudStorageItemInfo.booleanisRoot()Returns true if this StorageResourceId represents the GCS root (gs://); if true, then bothgetBucketNameandgetObjectNamewill be null.booleanisStorageObject()Returns true if this StorageResourceId represents a GCS StorageObject; if true, bothgetBucketNameandgetObjectNamewill be non-empty and non-null.StorageResourceIdtoDirectoryId()Converts StorageResourceId instance to look like a directory path.StringtoString()Returns a string of the formgs://<bucketName>/<objectName>.
-
-
-
Field Detail
-
UNKNOWN_GENERATION_ID
public static final long UNKNOWN_GENERATION_ID
- See Also:
- Constant Field Values
-
ROOT
public static final StorageResourceId ROOT
-
-
Constructor Detail
-
StorageResourceId
public StorageResourceId(String bucketName)
Constructor for a StorageResourceId representing a Bucket;getObjectName()will return null for a StorageResourceId that represents a Bucket.- Parameters:
bucketName- The bucket name of the resource. Must be non-empty and non-null.
-
StorageResourceId
public StorageResourceId(String bucketName, String objectName)
Constructor for a StorageResourceId representing a full StorageObject, including bucketName and objectName.- Parameters:
bucketName- The bucket name of the resource. Must be non-empty and non-null.objectName- The object name of the resource. Must be non-empty and non-null.
-
StorageResourceId
public StorageResourceId(String bucketName, String objectName, long generationId)
Constructor for a StorageResourceId representing a full StorageObject, including bucketName and objectName.- Parameters:
bucketName- The bucket name of the resource. Must be non-empty and non-null.objectName- The object name of the resource. Must be non-empty and non-null.generationId- The generationId to be used with precondition checks when using this StorageResourceId as an identifier for mutation requests.
-
StorageResourceId
public StorageResourceId(String bucketName, long generationId)
Constructor for a StorageResourceId representing a full StorageObject, including bucketName and objectName.- Parameters:
bucketName- The bucket name of the resource. Must be non-empty and non-null.generationId- The generationId to be used with precondition checks when using this StorageResourceId as an identifier for mutation requests.
-
-
Method Detail
-
isStorageObject
public boolean isStorageObject()
Returns true if this StorageResourceId represents a GCS StorageObject; if true, bothgetBucketNameandgetObjectNamewill be non-empty and non-null.
-
isBucket
public boolean isBucket()
Returns true if this StorageResourceId represents a GCS Bucket; if true, thengetObjectNamewill return null.
-
isRoot
public boolean isRoot()
Returns true if this StorageResourceId represents the GCS root (gs://); if true, then bothgetBucketNameandgetObjectNamewill be null.
-
isDirectory
public boolean isDirectory()
Indicates if this StorageResourceId corresponds to a 'directory'; similar toFileInfo.isDirectory()except deals entirely with pathnames instead of also checking for exists() to be true on a corresponding GoogleCloudStorageItemInfo.
-
getBucketName
public String getBucketName()
Gets the bucket name component of this resource identifier.
-
getObjectName
public String getObjectName()
Gets the object name component of this resource identifier.
-
getGenerationId
public long getGenerationId()
The generationId to be used with precondition checks when using this StorageResourceId as an identifier for mutation requests. The generationId is *not* used when determining equals() or hashCode().
-
hasGenerationId
public boolean hasGenerationId()
Returns true if generationId is not UNKNOWN_GENERATION_ID.
-
toString
public String toString()
Returns a string of the formgs://<bucketName>/<objectName>.
-
toDirectoryId
public StorageResourceId toDirectoryId()
Converts StorageResourceId instance to look like a directory path. If the path already looks like a directory path then this call is a no-op.- Returns:
- A resourceId with a directory path corresponding to the given resourceId.
-
fromStringPath
public static StorageResourceId fromStringPath(String path)
ParsesStorageResourceIdfrom specified string.
-
fromStringPath
public static StorageResourceId fromStringPath(String path, long generationId)
ParsesStorageResourceIdfrom specified string and generationId.
-
fromUriPath
public static StorageResourceId fromUriPath(URI path, boolean allowEmptyObjectName)
Validates the given URI and if valid, returns the associated StorageResourceId.- Parameters:
path- The GCS URI to validate.allowEmptyObjectName- If true, a missing object name is not considered invalid.- Returns:
- a StorageResourceId that may be the GCS root, a Bucket, or a StorageObject.
-
fromUriPath
public static StorageResourceId fromUriPath(URI path, boolean allowEmptyObjectName, long generationId)
Validates the given URI and if valid, returns the associated StorageResourceId.- Parameters:
path- The GCS URI to validate.allowEmptyObjectName- If true, a missing object name is not considered invalid.generationId- The generationId to be used with precondition checks when using this- Returns:
- a StorageResourceId that may be the GCS root, a Bucket, or a StorageObject.
-
-