Class StorageFileResource

java.lang.Object
org.springframework.core.io.AbstractResource
com.azure.spring.cloud.core.resource.StorageFileResource
All Implemented Interfaces:
org.springframework.core.io.InputStreamSource, org.springframework.core.io.Resource, org.springframework.core.io.WritableResource

public final class StorageFileResource extends org.springframework.core.io.AbstractResource
Implements WritableResource for reading and writing objects in Azure StorageAccount file. An instance of this class represents a handle to a file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    StorageFileResource(com.azure.storage.file.share.ShareServiceClient shareServiceClient, String location)
    Creates a new instance of StorageFileResource.
    StorageFileResource(com.azure.storage.file.share.ShareServiceClient shareServiceClient, String location, boolean autoCreateFiles)
    Creates a new instance of StorageFileResource.
    StorageFileResource(com.azure.storage.file.share.ShareServiceClient shareServiceClient, String location, boolean autoCreateFiles, String contentType)
    Creates a new instance of StorageFileResource.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
     
    org.springframework.core.io.Resource
    createRelative(String relativePath)
    Create relative resource from current location.
    boolean
    Determines if the file this client represents exists in the cloud.
     
    This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
     
     
    Checks whether an Azure Storage File can be opened, if the file is not existed, and autoCreateFiles==true, it will create the file on Azure Storage.
    Get the url of the storage file 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

    getURI, isFile, isOpen, isReadable, readableChannel

    Methods inherited from interface org.springframework.core.io.WritableResource

    isWritable, writableChannel
  • Constructor Details

    • StorageFileResource

      public StorageFileResource(com.azure.storage.file.share.ShareServiceClient shareServiceClient, String location)
      Creates a new instance of StorageFileResource.
      Parameters:
      shareServiceClient - the ShareServiceClient
      location - the location
    • StorageFileResource

      public StorageFileResource(com.azure.storage.file.share.ShareServiceClient shareServiceClient, String location, boolean autoCreateFiles)
      Creates a new instance of StorageFileResource.
      Parameters:
      shareServiceClient - the ShareServiceClient
      location - the location
      autoCreateFiles - whether to automatically create files
    • StorageFileResource

      public StorageFileResource(com.azure.storage.file.share.ShareServiceClient shareServiceClient, String location, boolean autoCreateFiles, String contentType)
      Creates a new instance of StorageFileResource.
      Parameters:
      shareServiceClient - the ShareServiceClient
      location - the location
      autoCreateFiles - whether to automatically create files
      contentType - the content type
  • Method Details

    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Checks whether an Azure Storage File can be opened, if the file is not existed, and autoCreateFiles==true, it will create the file on Azure Storage.
      Returns:
      A StorageFileOutputStream object used to write data to the file.
      Throws:
      IOException - when fail to open the output stream.
    • exists

      public boolean exists()
      Determines if the file 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:
      Flag indicating existence of the file.
    • getURL

      public URL getURL() throws IOException
      Get the url of the storage file client.
      Specified by:
      getURL in interface org.springframework.core.io.Resource
      Overrides:
      getURL in class org.springframework.core.io.AbstractResource
      Returns:
      the URL of the storage file client.
      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 number of bytes present in the response body.
    • lastModified

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

      public org.springframework.core.io.Resource createRelative(String relativePath)
      Create relative resource from current location.
      Specified by:
      createRelative in interface org.springframework.core.io.Resource
      Overrides:
      createRelative in class org.springframework.core.io.AbstractResource
      Parameters:
      relativePath - the relative path.
      Returns:
      StorageFileResource with relative path from current location.
    • 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 name of the file.
    • 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