Package org.codelibs.fess.storage
Class GcsStorageClient
java.lang.Object
org.codelibs.fess.storage.GcsStorageClient
- All Implemented Interfaces:
AutoCloseable,StorageClient
Google Cloud Storage client implementation.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor for subclasses that customize behavior without initializing the GCS client.GcsStorageClient(String projectId, String bucket, String endpoint, String credentialsPath) Creates a new GcsStorageClient instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the client and releases resources.voiddeleteObject(String objectName) Deletes an object from storage.voiddownloadObject(String objectName, OutputStream outputStream) Downloads an object from storage.voidEnsures the bucket exists, creating it if necessary.getObjectTags(String objectName) Gets tags/metadata for an object.booleanChecks if storage is properly configured and accessible.protected booleanisDefaultEndpoint(String endpoint) Determines whether the given endpoint refers to the default GCS host (storage.googleapis.com).listObjects(String prefix, int maxItems) Lists objects in storage with the given prefix.voidsetObjectTags(String objectName, Map<String, String> tags) Sets tags/metadata for an object.voiduploadObject(String objectName, InputStream inputStream, long size, String contentType) Uploads an object to storage.
-
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 onstorageorbucket. -
GcsStorageClient
Creates a new GcsStorageClient instance.- Parameters:
projectId- the GCS project IDbucket- the bucket nameendpoint- the custom endpoint URL (optional, for fake-gcs-server etc.)credentialsPath- the path to the credentials JSON file (optional)
-
-
Method Details
-
isDefaultEndpoint
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:
trueif the endpoint resolves to the default GCS host
-
uploadObject
Description copied from interface:StorageClientUploads an object to storage.- Specified by:
uploadObjectin interfaceStorageClient- Parameters:
objectName- the name/path for the objectinputStream- the input stream of data to uploadsize- the size of the data in bytescontentType- the MIME type of the content
-
downloadObject
Description copied from interface:StorageClientDownloads an object from storage.- Specified by:
downloadObjectin interfaceStorageClient- Parameters:
objectName- the name/path of the object to downloadoutputStream- the output stream to write data to
-
deleteObject
Description copied from interface:StorageClientDeletes an object from storage.- Specified by:
deleteObjectin interfaceStorageClient- Parameters:
objectName- the name/path of the object to delete
-
listObjects
Description copied from interface:StorageClientLists objects in storage with the given prefix.- Specified by:
listObjectsin interfaceStorageClient- 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
Description copied from interface:StorageClientGets tags/metadata for an object.- Specified by:
getObjectTagsin interfaceStorageClient- Parameters:
objectName- the name/path of the object- Returns:
- map of tag key-value pairs
-
setObjectTags
Description copied from interface:StorageClientSets tags/metadata for an object.- Specified by:
setObjectTagsin interfaceStorageClient- Parameters:
objectName- the name/path of the objecttags- the tags to set
-
ensureBucketExists
public void ensureBucketExists()Description copied from interface:StorageClientEnsures the bucket exists, creating it if necessary.- Specified by:
ensureBucketExistsin interfaceStorageClient
-
isAvailable
public boolean isAvailable()Description copied from interface:StorageClientChecks if storage is properly configured and accessible.- Specified by:
isAvailablein interfaceStorageClient- Returns:
- true if storage is available
-
close
public void close()Description copied from interface:StorageClientCloses the client and releases resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStorageClient
-