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 Details

    • StorageBlobResource

      public StorageBlobResource(com.azure.storage.blob.BlobServiceClient blobServiceClient, String location)
      Creates a new instance of StorageBlobResource.
      Parameters:
      blobServiceClient - the BlobServiceClient
      location - the location
    • StorageBlobResource

      public StorageBlobResource(com.azure.storage.blob.BlobServiceClient blobServiceClient, String location, Boolean autoCreateFiles)
      Creates a new instance of StorageBlobResource.
      Parameters:
      blobServiceClient - the BlobServiceClient
      location - the location
      autoCreateFiles - 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 of StorageBlobResource.
      Parameters:
      blobServiceClient - the BlobServiceClient
      location - the location
      autoCreateFiles - whether to automatically create files
      snapshot - the snapshot name
      versionId - the version id
      contentType - the content type
  • Method Details

    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      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 interface org.springframework.core.io.Resource
      Overrides:
      exists in class org.springframework.core.io.AbstractResource
      Returns:
      true if the blob exists, false if it doesn't
    • getURL

      public URL getURL() throws IOException
      Gets the URL of the blob represented by this client.
      Specified by:
      getURL in interface org.springframework.core.io.Resource
      Overrides:
      getURL in class org.springframework.core.io.AbstractResource
      Returns:
      the URL.
      Throws:
      IOException
    • getFile

      public File getFile()
      This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
      Specified by:
      getFile in interface org.springframework.core.io.Resource
      Overrides:
      getFile in class org.springframework.core.io.AbstractResource
    • contentLength

      public long contentLength()
      Specified by:
      contentLength in interface org.springframework.core.io.Resource
      Overrides:
      contentLength in class org.springframework.core.io.AbstractResource
      Returns:
      the size of the blob in bytes
    • lastModified

      public long lastModified()
      Specified by:
      lastModified in interface org.springframework.core.io.Resource
      Overrides:
      lastModified in class org.springframework.core.io.AbstractResource
      Returns:
      the time when the blob was last modified
    • createRelative

      public org.springframework.core.io.Resource createRelative(String relativePath)
      Specified by:
      createRelative in interface org.springframework.core.io.Resource
      Overrides:
      createRelative in class org.springframework.core.io.AbstractResource
    • getFilename

      public String getFilename()
      Specified by:
      getFilename in interface org.springframework.core.io.Resource
      Overrides:
      getFilename in class org.springframework.core.io.AbstractResource
      Returns:
      The decoded name of the blob.
    • getDescription

      public String getDescription()
      Returns:
      a description for this resource, to be used for error output when working with the resource.
    • getInputStream

      public InputStream getInputStream() throws IOException
      Throws:
      IOException