Class 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.
    • 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, both getBucketName and getObjectName will be non-empty and non-null.
      • isBucket

        public boolean isBucket()
        Returns true if this StorageResourceId represents a GCS Bucket; if true, then getObjectName will return null.
      • isRoot

        public boolean isRoot()
        Returns true if this StorageResourceId represents the GCS root (gs://); if true, then both getBucketName and getObjectName will be null.
      • isDirectory

        public boolean isDirectory()
        Indicates if this StorageResourceId corresponds to a 'directory'; similar to FileInfo.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 form gs://<bucketName>/<objectName>.
        Overrides:
        toString in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • 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.
      • 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.