Class StorageBlobResource
java.lang.Object
org.springframework.core.io.AbstractResource
com.azure.spring.cloud.core.resource.StorageBlobResource
- All Implemented Interfaces:
org.springframework.core.io.InputStreamSource
,org.springframework.core.io.Resource
,org.springframework.core.io.WritableResource
public final class StorageBlobResource
extends org.springframework.core.io.AbstractResource
Implements
WritableResource
for reading and writing objects in Azure StorageAccount blob. An instance of this
class represents a handle to a blob.-
Constructor Summary
ConstructorDescriptionStorageBlobResource
(com.azure.storage.blob.BlobServiceClient blobServiceClient, String location) Creates a new instance ofStorageBlobResource
.StorageBlobResource
(com.azure.storage.blob.BlobServiceClient blobServiceClient, String location, Boolean autoCreateFiles) Creates a new instance ofStorageBlobResource
.StorageBlobResource
(com.azure.storage.blob.BlobServiceClient blobServiceClient, String location, Boolean autoCreateFiles, String snapshot, String versionId, String contentType) Creates a new instance ofStorageBlobResource
. -
Method Summary
Modifier and TypeMethodDescriptionlong
org.springframework.core.io.Resource
createRelative
(String relativePath) boolean
exists()
Gets if the blob this client represents exists in the cloud.getFile()
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.Creates and opens an output stream to write data to the block blob.getURL()
Gets the URL of the blob represented by this client.long
Methods inherited from class org.springframework.core.io.AbstractResource
equals, getFileForLastModifiedCheck, getURI, hashCode, isFile, isOpen, isReadable, readableChannel, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.core.io.Resource
getContentAsByteArray, getContentAsString, getURI, isFile, isOpen, isReadable, readableChannel
Methods inherited from interface org.springframework.core.io.WritableResource
isWritable, writableChannel
-
Constructor Details
-
StorageBlobResource
public StorageBlobResource(com.azure.storage.blob.BlobServiceClient blobServiceClient, String location) Creates a new instance ofStorageBlobResource
.- Parameters:
blobServiceClient
- the BlobServiceClientlocation
- the location
-
StorageBlobResource
public StorageBlobResource(com.azure.storage.blob.BlobServiceClient blobServiceClient, String location, Boolean autoCreateFiles) Creates a new instance ofStorageBlobResource
.- Parameters:
blobServiceClient
- the BlobServiceClientlocation
- the locationautoCreateFiles
- whether to automatically create files
-
StorageBlobResource
public StorageBlobResource(com.azure.storage.blob.BlobServiceClient blobServiceClient, String location, Boolean autoCreateFiles, String snapshot, String versionId, String contentType) Creates a new instance ofStorageBlobResource
.- Parameters:
blobServiceClient
- the BlobServiceClientlocation
- the locationautoCreateFiles
- whether to automatically create filessnapshot
- the snapshot nameversionId
- the version idcontentType
- the content type
-
-
Method Details
-
getOutputStream
Creates and opens an output stream to write data to the block blob. If the blob already exists on the service, it will be overwritten.- Returns:
- A
BlobOutputStream
object used to write data to the blob. - Throws:
IOException
- If a storage service error occurred or blob not found.
-
exists
public boolean exists()Gets if the blob this client represents exists in the cloud.- Specified by:
exists
in interfaceorg.springframework.core.io.Resource
- Overrides:
exists
in classorg.springframework.core.io.AbstractResource
- Returns:
- true if the blob exists, false if it doesn't
-
getURL
Gets the URL of the blob represented by this client.- Specified by:
getURL
in interfaceorg.springframework.core.io.Resource
- Overrides:
getURL
in classorg.springframework.core.io.AbstractResource
- Returns:
- the URL.
- Throws:
IOException
-
getFile
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.- Specified by:
getFile
in interfaceorg.springframework.core.io.Resource
- Overrides:
getFile
in classorg.springframework.core.io.AbstractResource
-
contentLength
public long contentLength()- Specified by:
contentLength
in interfaceorg.springframework.core.io.Resource
- Overrides:
contentLength
in classorg.springframework.core.io.AbstractResource
- Returns:
- the size of the blob in bytes
-
lastModified
public long lastModified()- Specified by:
lastModified
in interfaceorg.springframework.core.io.Resource
- Overrides:
lastModified
in classorg.springframework.core.io.AbstractResource
- Returns:
- the time when the blob was last modified
-
createRelative
- Specified by:
createRelative
in interfaceorg.springframework.core.io.Resource
- Overrides:
createRelative
in classorg.springframework.core.io.AbstractResource
-
getFilename
- Specified by:
getFilename
in interfaceorg.springframework.core.io.Resource
- Overrides:
getFilename
in classorg.springframework.core.io.AbstractResource
- Returns:
- The decoded name of the blob.
-
getDescription
- Returns:
- a description for this resource, to be used for error output when working with the resource.
-
getInputStream
- Throws:
IOException
-