public class GoogleStorageResource extends Object implements org.springframework.core.io.WritableResource
WritableResource for reading and writing objects in Google Cloud
Storage (GCS). An instance of this class represents a handle to a bucket or a blob.| Constructor and Description |
|---|
GoogleStorageResource(com.google.cloud.storage.Storage storage,
String location)
Constructor that defaults autoCreateFiles to true.
|
GoogleStorageResource(com.google.cloud.storage.Storage storage,
String location,
boolean autoCreateFiles)
Constructs the resource representation of a bucket or a blob (file) in Google Cloud Storage.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
bucketExists()
Checks for the existence of the
Bucket associated with the resource. |
long |
contentLength() |
com.google.cloud.storage.Blob |
createBlob()
Creates the blob that this
GoogleStorageResource represents in Google Cloud
Storage. |
com.google.cloud.storage.Bucket |
createBucket()
Creates the bucket that this resource references in Google Cloud Storage.
|
GoogleStorageResource |
createRelative(String relativePath)
Creates a
GoogleStorageResource handle that is relative to this one. |
URL |
createSignedUrl(TimeUnit timeUnit,
long timePeriods,
com.google.cloud.storage.Storage.SignUrlOption... options)
Creates a signed URL to an object, if it exists.
|
boolean |
exists() |
com.google.cloud.storage.Blob |
getBlob()
Gets the underlying storage object in Google Cloud Storage.
|
String |
getBlobName() |
com.google.cloud.storage.Bucket |
getBucket()
Returns the
Bucket associated with the resource. |
String |
getBucketName() |
String |
getDescription() |
File |
getFile() |
String |
getFilename() |
InputStream |
getInputStream() |
OutputStream |
getOutputStream()
Returns the output stream for a Google Cloud Storage file.
|
URI |
getURI() |
URL |
getURL()
Since the gs: protocol will normally not have a URL stream handler registered,
this method will always throw a
MalformedURLException. |
boolean |
isAutoCreateFiles() |
boolean |
isBucket()
Check if this resource references a bucket and not a blob.
|
boolean |
isOpen() |
boolean |
isReadable() |
boolean |
isWritable() |
long |
lastModified() |
public GoogleStorageResource(com.google.cloud.storage.Storage storage,
String location,
boolean autoCreateFiles)
storage - the Google Cloud Storage clientlocation - the URI of the bucket or blob, e.g., gs://your-bucket/ or gs://your-bucket/your-file-nameautoCreateFiles - determines the auto-creation of the file in Google Cloud Storage
if an operation that depends on its existence is triggered
(e.g., getting the output stream of a file)IllegalArgumentException - if the location URI is invalidpublic GoogleStorageResource(com.google.cloud.storage.Storage storage,
String location)
public boolean isAutoCreateFiles()
public boolean exists()
exists in interface org.springframework.core.io.Resourcepublic boolean isReadable()
isReadable in interface org.springframework.core.io.Resourcepublic boolean isOpen()
isOpen in interface org.springframework.core.io.Resourcepublic URL getURL() throws IOException
MalformedURLException.getURL in interface org.springframework.core.io.ResourceIOExceptionpublic URI getURI() throws IOException
getURI in interface org.springframework.core.io.ResourceIOExceptionpublic com.google.cloud.storage.Blob getBlob()
throws IOException
IOExceptionIllegalStateException - if the resource reference is to a bucket, and not a blob.public URL createSignedUrl(TimeUnit timeUnit, long timePeriods, com.google.cloud.storage.Storage.SignUrlOption... options) throws IOException
timeUnit - the time unit used to determine how long the URL is valid.timePeriods - the number of periods to determine how long the URL is valid.options - specifies additional options for signing URLsIllegalStateException - if the resource reference is to a bucket, and not a blob.IOExceptionpublic com.google.cloud.storage.Blob createBlob()
throws com.google.cloud.storage.StorageException
GoogleStorageResource represents in Google Cloud
Storage.com.google.cloud.storage.StorageException - if any errors during blob creation arise,
such as if the blob already existsIllegalStateException - if the resource reference is to a bucket, and not a blob.public com.google.cloud.storage.Bucket createBucket()
Bucket object for the bucketcom.google.cloud.storage.StorageException - if any errors during bucket creation arise,
such as if the bucket already existspublic com.google.cloud.storage.Bucket getBucket()
Bucket associated with the resource.public boolean bucketExists()
Bucket associated with the resource.public File getFile() throws IOException
getFile in interface org.springframework.core.io.ResourceIOExceptionpublic long contentLength()
throws IOException
contentLength in interface org.springframework.core.io.ResourceIOExceptionpublic long lastModified()
throws IOException
lastModified in interface org.springframework.core.io.ResourceIOExceptionpublic GoogleStorageResource createRelative(String relativePath) throws IOException
GoogleStorageResource handle that is relative to this one. It inherits autoCreateFiles
from this object. Note that it does not actually create the blob.
Note that this method does not actually create the blob.
createRelative in interface org.springframework.core.io.ResourcerelativePath - the URL to a Google Cloud Storage fileGoogleStorageResource handle for the relative pathIOExceptionpublic String getFilename()
getFilename in interface org.springframework.core.io.Resourcepublic String getDescription()
getDescription in interface org.springframework.core.io.Resourcepublic InputStream getInputStream() throws IOException
getInputStream in interface org.springframework.core.io.InputStreamSourceIOExceptionpublic boolean isWritable()
isWritable in interface org.springframework.core.io.WritableResourcepublic OutputStream getOutputStream() throws IOException
getOutputStream in interface org.springframework.core.io.WritableResourcenull if the object doesn't exist and cannot be
createdIOExceptionpublic String getBlobName()
public String getBucketName()
public boolean isBucket()
Copyright © 2018 Pivotal Software, Inc.. All rights reserved.