Class GcsStorageClient

java.lang.Object
org.codelibs.fess.storage.GcsStorageClient
All Implemented Interfaces:
AutoCloseable, StorageClient

public class GcsStorageClient extends Object implements StorageClient
Google Cloud Storage client implementation.
  • Constructor Details

    • GcsStorageClient

      protected GcsStorageClient()
      Constructor for subclasses that customize behavior without initializing the GCS client. Subclasses using this constructor must override any method that depends on storage or bucket.
    • GcsStorageClient

      public GcsStorageClient(String projectId, String bucket, String endpoint, String credentialsPath)
      Creates a new GcsStorageClient instance.
      Parameters:
      projectId - the GCS project ID
      bucket - the bucket name
      endpoint - the custom endpoint URL (optional, for fake-gcs-server etc.)
      credentialsPath - the path to the credentials JSON file (optional)
  • Method Details

    • isDefaultEndpoint

      protected boolean isDefaultEndpoint(String endpoint)
      Determines whether the given endpoint refers to the default GCS host (storage.googleapis.com). Subclasses may override this to recognize additional hosts as default.
      Parameters:
      endpoint - the endpoint to check (URL or host)
      Returns:
      true if the endpoint resolves to the default GCS host
    • uploadObject

      public void uploadObject(String objectName, InputStream inputStream, long size, String contentType)
      Description copied from interface: StorageClient
      Uploads an object to storage.
      Specified by:
      uploadObject in interface StorageClient
      Parameters:
      objectName - the name/path for the object
      inputStream - the input stream of data to upload
      size - the size of the data in bytes
      contentType - the MIME type of the content
    • downloadObject

      public void downloadObject(String objectName, OutputStream outputStream)
      Description copied from interface: StorageClient
      Downloads an object from storage.
      Specified by:
      downloadObject in interface StorageClient
      Parameters:
      objectName - the name/path of the object to download
      outputStream - the output stream to write data to
    • deleteObject

      public void deleteObject(String objectName)
      Description copied from interface: StorageClient
      Deletes an object from storage.
      Specified by:
      deleteObject in interface StorageClient
      Parameters:
      objectName - the name/path of the object to delete
    • listObjects

      public List<StorageItem> listObjects(String prefix, int maxItems)
      Description copied from interface: StorageClient
      Lists objects in storage with the given prefix.
      Specified by:
      listObjects in interface StorageClient
      Parameters:
      prefix - the path prefix to list objects under (null or empty for root)
      maxItems - maximum number of items to return
      Returns:
      list of storage items
    • getObjectTags

      public Map<String,String> getObjectTags(String objectName)
      Description copied from interface: StorageClient
      Gets tags/metadata for an object.
      Specified by:
      getObjectTags in interface StorageClient
      Parameters:
      objectName - the name/path of the object
      Returns:
      map of tag key-value pairs
    • setObjectTags

      public void setObjectTags(String objectName, Map<String,String> tags)
      Description copied from interface: StorageClient
      Sets tags/metadata for an object.
      Specified by:
      setObjectTags in interface StorageClient
      Parameters:
      objectName - the name/path of the object
      tags - the tags to set
    • ensureBucketExists

      public void ensureBucketExists()
      Description copied from interface: StorageClient
      Ensures the bucket exists, creating it if necessary.
      Specified by:
      ensureBucketExists in interface StorageClient
    • isAvailable

      public boolean isAvailable()
      Description copied from interface: StorageClient
      Checks if storage is properly configured and accessible.
      Specified by:
      isAvailable in interface StorageClient
      Returns:
      true if storage is available
    • close

      public void close()
      Description copied from interface: StorageClient
      Closes the client and releases resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface StorageClient