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
ConstructorDescriptionStorageFileResource
(com.azure.storage.file.share.ShareServiceClient shareServiceClient, String location) Creates a new instance ofStorageFileResource
.StorageFileResource
(com.azure.storage.file.share.ShareServiceClient shareServiceClient, String location, boolean autoCreateFiles) Creates a new instance ofStorageFileResource
.StorageFileResource
(com.azure.storage.file.share.ShareServiceClient shareServiceClient, String location, boolean autoCreateFiles, String contentType) Creates a new instance ofStorageFileResource
. -
Method Summary
Modifier and TypeMethodDescriptionlong
org.springframework.core.io.Resource
createRelative
(String relativePath) Create relative resource from current location.boolean
exists()
Determines if the file 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.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.getURL()
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
getContentAsByteArray, getContentAsString, getURI, isFile, isOpen, isReadable, readableChannel
Methods inherited from interface org.springframework.core.io.WritableResource
isWritable, writableChannel
-
Constructor Details
-
Method Details
-
getOutputStream
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 interfaceorg.springframework.core.io.Resource
- Overrides:
exists
in classorg.springframework.core.io.AbstractResource
- Returns:
- Flag indicating existence of the file.
-
getURL
Get the url of the storage file client.- Specified by:
getURL
in interfaceorg.springframework.core.io.Resource
- Overrides:
getURL
in classorg.springframework.core.io.AbstractResource
- Returns:
- the URL of the storage file client.
- 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 number of bytes present in the response body.
-
lastModified
public long lastModified()- Specified by:
lastModified
in interfaceorg.springframework.core.io.Resource
- Overrides:
lastModified
in classorg.springframework.core.io.AbstractResource
- Returns:
- Last time the directory was modified.
-
createRelative
Create relative resource from current location.- Specified by:
createRelative
in interfaceorg.springframework.core.io.Resource
- Overrides:
createRelative
in classorg.springframework.core.io.AbstractResource
- Parameters:
relativePath
- the relative path.- Returns:
- StorageFileResource with relative path from current location.
-
getFilename
- Specified by:
getFilename
in interfaceorg.springframework.core.io.Resource
- Overrides:
getFilename
in classorg.springframework.core.io.AbstractResource
- Returns:
- The name of the file.
-
getDescription
- Returns:
- a description for this resource, to be used for error output when working with the resource.
-
getInputStream
- Throws:
IOException
-