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
ConstructorsConstructorDescriptionStorageBlobResource(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 TypeMethodDescriptionlongorg.springframework.core.io.ResourcecreateRelative(String relativePath) booleanexists()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.longMethods inherited from class org.springframework.core.io.AbstractResource
equals, getFileForLastModifiedCheck, getURI, hashCode, isFile, isOpen, isReadable, readableChannel, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.core.io.Resource
getURI, isFile, isOpen, isReadable, readableChannelMethods 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
BlobOutputStreamobject 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:
existsin interfaceorg.springframework.core.io.Resource- Overrides:
existsin 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:
getURLin interfaceorg.springframework.core.io.Resource- Overrides:
getURLin 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:
getFilein interfaceorg.springframework.core.io.Resource- Overrides:
getFilein classorg.springframework.core.io.AbstractResource
-
contentLength
public long contentLength()- Specified by:
contentLengthin interfaceorg.springframework.core.io.Resource- Overrides:
contentLengthin classorg.springframework.core.io.AbstractResource- Returns:
- the size of the blob in bytes
-
lastModified
public long lastModified()- Specified by:
lastModifiedin interfaceorg.springframework.core.io.Resource- Overrides:
lastModifiedin classorg.springframework.core.io.AbstractResource- Returns:
- the time when the blob was last modified
-
createRelative
- Specified by:
createRelativein interfaceorg.springframework.core.io.Resource- Overrides:
createRelativein classorg.springframework.core.io.AbstractResource
-
getFilename
- Specified by:
getFilenamein interfaceorg.springframework.core.io.Resource- Overrides:
getFilenamein 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
-