Class ShareFileClient
Instantiating a synchronous File Client
ShareFileClient client = new ShareFileClientBuilder() .connectionString("${connectionString}") .endpoint("${endpoint}") .buildFileClient();
View this
for additional ways to construct the client.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.abortCopyWithResponse
(String copyId, ShareRequestConditions requestConditions, Duration timeout, Context context) Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.abortCopyWithResponse
(String copyId, Duration timeout, Context context) Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.beginCopy
(String sourceUrl, FileSmbProperties smbProperties, String filePermission, PermissionCopyModeType filePermissionCopyMode, Boolean ignoreReadOnly, Boolean setArchiveAttribute, Map<String, String> metadata, Duration pollInterval, ShareRequestConditions destinationRequestConditions) Copies a blob or file to a destination file within the storage account.beginCopy
(String sourceUrl, ShareFileCopyOptions options, Duration pollInterval) Copies a blob or file to a destination file within the storage account.Copies a blob or file to a destination file within the storage account.clearRange
(long length) Clears a range of bytes to specific of a file in storage file service.clearRangeWithResponse
(long length, long offset, ShareRequestConditions requestConditions, Duration timeout, Context context) Clears a range of bytes to specific of a file in storage file service.clearRangeWithResponse
(long length, long offset, Duration timeout, Context context) Clears a range of bytes to specific of a file in storage file service.create
(long maxSize) Creates a file in the storage account and returns a response ofShareFileInfo
to interact with it.createWithResponse
(long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata, ShareRequestConditions requestConditions, Duration timeout, Context context) Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.createWithResponse
(long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata, Duration timeout, Context context) Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.void
delete()
Deletes the file associate with the client.boolean
Deletes the file associate with the client if it exists.deleteIfExistsWithResponse
(ShareRequestConditions requestConditions, Duration timeout, Context context) Deletes the file associate with the client if it exists.deleteWithResponse
(ShareRequestConditions requestConditions, Duration timeout, Context context) Deletes the file associate with the client.deleteWithResponse
(Duration timeout, Context context) Deletes the file associate with the client.void
download
(OutputStream stream) Downloads a file from the system, including its metadata and propertiesdownloadToFile
(String downloadFilePath) Downloads a file from the system, including its metadata and properties into a file specified by the path.downloadToFileWithResponse
(String downloadFilePath, ShareFileRange range, ShareRequestConditions requestConditions, Duration timeout, Context context) Downloads a file from the system, including its metadata and properties into a file specified by the path.downloadToFileWithResponse
(String downloadFilePath, ShareFileRange range, Duration timeout, Context context) Downloads a file from the system, including its metadata and properties into a file specified by the path.downloadWithResponse
(OutputStream stream, ShareFileRange range, Boolean rangeGetContentMD5, ShareRequestConditions requestConditions, Duration timeout, Context context) Downloads a file from the system, including its metadata and propertiesdownloadWithResponse
(OutputStream stream, ShareFileRange range, Boolean rangeGetContentMD5, Duration timeout, Context context) Downloads a file from the system, including its metadata and propertiesdownloadWithResponse
(OutputStream stream, ShareFileDownloadOptions options, Duration timeout, Context context) Downloads a file from the system, including its metadata and propertiesexists()
Determines if the file this client represents exists in the cloud.existsWithResponse
(Duration timeout, Context context) Determines if the file this client represents exists in the cloud.forceCloseAllHandles
(Duration timeout, Context context) Closes all handles opened on the file at the service.forceCloseHandle
(String handleId) Closes a handle on the file at the service.forceCloseHandleWithResponse
(String handleId, Duration timeout, Context context) Closes a handle on the file at the service.generateSas
(ShareServiceSasSignatureValues shareServiceSasSignatureValues) Generates a service SAS for the file using the specifiedShareServiceSasSignatureValues
generateSas
(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Context context) Generates a service SAS for the file using the specifiedShareServiceSasSignatureValues
Get associated account name.Get the url of the storage account.final StorageFileOutputStream
Creates and opens an output stream to write data to the file.final StorageFileOutputStream
getFileOutputStream
(long offset) Creates and opens an output stream to write data to the file.Get file path of the client.Get the url of the storage file client.Gets theHttpPipeline
powering this client.Retrieves the properties of the storage account's file.getPropertiesWithResponse
(ShareRequestConditions requestConditions, Duration timeout, Context context) Retrieves the properties of the storage account's file.getPropertiesWithResponse
(Duration timeout, Context context) Retrieves the properties of the storage account's file.Gets the service version the client is using.Get the share name of file client.Get snapshot id which attached toShareFileClient
.List of open handles on a file.listHandles
(Integer maxResultsPerPage, Duration timeout, Context context) List of open handles on a file.List of valid ranges for a file.listRanges
(ShareFileRange range, ShareRequestConditions requestConditions, Duration timeout, Context context) List of valid ranges for a file.listRanges
(ShareFileRange range, Duration timeout, Context context) List of valid ranges for a file.listRangesDiff
(String previousSnapshot) List of valid ranges for a file.listRangesDiffWithResponse
(ShareFileListRangesDiffOptions options, Duration timeout, Context context) List of valid ranges for a file.final StorageFileInputStream
Opens a file input stream to download the file.final StorageFileInputStream
openInputStream
(ShareFileRange range) Opens a file input stream to download the specified range of the file.Moves the file to another location within the share.renameWithResponse
(ShareFileRenameOptions options, Duration timeout, Context context) Moves the file to another location within the share.setMetadata
(Map<String, String> metadata) Sets the user-defined metadata to associate to the file.setMetadataWithResponse
(Map<String, String> metadata, ShareRequestConditions requestConditions, Duration timeout, Context context) Sets the user-defined metadata to associate to the file.Sets the user-defined metadata to associate to the file.setProperties
(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission) Sets the user-defined httpHeaders to associate to the file.setPropertiesWithResponse
(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, ShareRequestConditions requestConditions, Duration timeout, Context context) Sets the user-defined httpHeaders to associate to the file.setPropertiesWithResponse
(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Duration timeout, Context context) Sets the user-defined httpHeaders to associate to the file.upload
(InputStream data, long length) Deprecated.upload
(InputStream data, long length, ParallelTransferOptions transferOptions) Buffers a range of bytes and uploads sub-ranges in parallel to a file in storage file service.void
uploadFromFile
(String uploadFilePath) Uploads file to storage file service.void
uploadFromFile
(String uploadFilePath, ShareRequestConditions requestConditions) Uploads file to storage file service.uploadRange
(InputStream data, long length) Uploads a range of bytes to the specified offset of a file in storage file service.uploadRangeFromUrl
(long length, long destinationOffset, long sourceOffset, String sourceUrl) Uploads a range of bytes from one file to another file.uploadRangeFromUrlWithResponse
(long length, long destinationOffset, long sourceOffset, String sourceUrl, ShareRequestConditions requestConditions, Duration timeout, Context context) Uploads a range of bytes from one file to another file.uploadRangeFromUrlWithResponse
(long length, long destinationOffset, long sourceOffset, String sourceUrl, Duration timeout, Context context) Uploads a range of bytes from one file to another file.uploadRangeFromUrlWithResponse
(ShareFileUploadRangeFromUrlOptions options, Duration timeout, Context context) Uploads a range of bytes from one file to another file.uploadRangeWithResponse
(ShareFileUploadRangeOptions options, Duration timeout, Context context) Uploads a range of bytes to the specified offset of a file in storage file service.uploadWithResponse
(ShareFileUploadOptions options, Duration timeout, Context context) Buffers a range of bytes and uploads sub-ranges in parallel to a file in storage file service.uploadWithResponse
(InputStream data, long length, Long offset, ShareRequestConditions requestConditions, Duration timeout, Context context) Deprecated.uploadWithResponse
(InputStream data, long length, Long offset, Duration timeout, Context context) Deprecated.
-
Method Details
-
getAccountUrl
Get the url of the storage account.- Returns:
- the URL of the storage account
-
getFileUrl
Get the url of the storage file client.- Returns:
- the URL of the storage file client.
-
getServiceVersion
Gets the service version the client is using.- Returns:
- the service version the client is using.
-
openInputStream
Opens a file input stream to download the file.- Returns:
- An
InputStream
object that represents the stream to use for reading from the file. - Throws:
ShareStorageException
- If a storage service error occurred.
-
getFileOutputStream
Creates and opens an output stream to write data to the file. If the file already exists on the service, it will be overwritten.- Returns:
- A
StorageFileOutputStream
object used to write data to the file. - Throws:
ShareStorageException
- If a storage service error occurred.
-
getFileOutputStream
Creates and opens an output stream to write data to the file. If the file already exists on the service, it will be overwritten.- Parameters:
offset
- Starting point of the upload range, ifnull
it will start from the beginning.- Returns:
- A
StorageFileOutputStream
object used to write data to the file. - Throws:
ShareStorageException
- If a storage service error occurred.
-
exists
Determines if the file this client represents exists in the cloud.Code Samples
System.out.printf("Exists? %b%n", client.exists());
- Returns:
- Flag indicating existence of the file.
-
existsWithResponse
Determines if the file this client represents exists in the cloud.Code Samples
Context context = new Context("Key", "Value"); System.out.printf("Exists? %b%n", client.existsWithResponse(timeout, context).getValue());
- Parameters:
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- Flag indicating existence of the file.
-
create
Creates a file in the storage account and returns a response ofShareFileInfo
to interact with it.Code Samples
Create the file with length of 1024 bytes, some headers and metadata.
ShareFileInfo response = fileClient.create(1024); System.out.println("Complete creating the file.");
For more information, see the Azure Docs.
- Parameters:
maxSize
- The maximum size in bytes for the file.- Returns:
- The
file info
- Throws:
ShareStorageException
- If the file has already existed, the parent directory does not exist or fileName is an invalid resource name.
-
beginCopy
public SyncPoller<ShareFileCopyInfo,Void> beginCopy(String sourceUrl, Map<String, String> metadata, Duration pollInterval) Copies a blob or file to a destination file within the storage account.Code Samples
Copy file from source getDirectoryUrl to the
resourcePath
SyncPoller<ShareFileCopyInfo, Void> poller = fileClient.beginCopy( "https://{accountName}.file.core.windows.net?{SASToken}", Collections.singletonMap("file", "metadata"), Duration.ofSeconds(2)); final PollResponse<ShareFileCopyInfo> pollResponse = poller.poll(); final ShareFileCopyInfo value = pollResponse.getValue(); System.out.printf("Copy source: %s. Status: %s.%n", value.getCopySourceUrl(), value.getCopyStatus());
For more information, see the Azure Docs.
- Parameters:
sourceUrl
- Specifies the URL of the source file or blob, up to 2 KB in length.metadata
- Optional name-value pairs associated with the file as metadata. Metadata names must adhere to the naming rules.pollInterval
- Duration between each poll for the copy status. If none is specified, a default of one second is used.- Returns:
- A
SyncPoller
to poll the progress of copy operation. - See Also:
-
abortCopy
Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.Code Samples
Abort copy file from copy id("someCopyId")
fileClient.abortCopy("someCopyId"); System.out.println("Abort copying the file completed.");
For more information, see the Azure Docs.
- Parameters:
copyId
- Specifies the copy id which has copying pending status associate with it.
-
abortCopyWithResponse
Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.Code Samples
Abort copy file from copy id("someCopyId")
Response<Void> response = fileClient.abortCopyWithResponse("someCopyId", Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Abort copying the file completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
copyId
- Specifies the copy id which has copying pending status associate with it.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the status of aborting copy the file.
- Throws:
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
downloadToFile
Downloads a file from the system, including its metadata and properties into a file specified by the path.The file will be created and must not exist, if the file already exists a
FileAlreadyExistsException
will be thrown.Code Samples
Download the file to current folder.
fileClient.downloadToFile("somelocalfilepath"); if (Files.exists(Paths.get("somelocalfilepath"))) { System.out.println("Complete downloading the file."); }
For more information, see the Azure Docs.
- Parameters:
downloadFilePath
- The path where store the downloaded file- Returns:
- The properties of the file.
-
download
Downloads a file from the system, including its metadata and propertiesCode Samples
Download the file with its metadata and properties.
try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); fileClient.download(stream); System.out.printf("Completed downloading the file with content: %n%s%n", new String(stream.toByteArray(), StandardCharsets.UTF_8)); } catch (Throwable throwable) { System.err.printf("Downloading failed with exception. Message: %s%n", throwable.getMessage()); }
For more information, see the Azure Docs.
- Parameters:
stream
- A non-nullOutputStream
where the downloaded data will be written.- Throws:
NullPointerException
- Ifstream
isnull
.
-
delete
public void delete()Deletes the file associate with the client.Code Samples
Delete the file
fileClient.delete(); System.out.println("Complete deleting the file.");
For more information, see the Azure Docs.
- Throws:
ShareStorageException
- If the directory doesn't exist or the file doesn't exist.
-
deleteWithResponse
Deletes the file associate with the client.Code Samples
Delete the file
Response<Void> response = fileClient.deleteWithResponse(Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Complete deleting the file with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that only contains headers and response status code
- Throws:
ShareStorageException
- If the directory doesn't exist or the file doesn't exist.RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
deleteIfExists
public boolean deleteIfExists()Deletes the file associate with the client if it exists.Code Samples
Delete the file
boolean result = fileClient.deleteIfExists(); System.out.println("File deleted: " + result);
For more information, see the Azure Docs.
- Returns:
true
if the file is successfully deleted,false
if the file does not exist.
-
getProperties
Retrieves the properties of the storage account's file. The properties include file metadata, last modified date, is server encrypted, and eTag.Code Samples
Retrieve file properties
ShareFileProperties properties = fileClient.getProperties(); System.out.printf("File latest modified date is %s.", properties.getLastModified());
For more information, see the Azure Docs.
- Returns:
Storage file properties
-
getPropertiesWithResponse
Retrieves the properties of the storage account's file. The properties include file metadata, last modified date, is server encrypted, and eTag.Code Samples
Retrieve file properties
Response<ShareFileProperties> response = fileClient.getPropertiesWithResponse( Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("File latest modified date is %s.", response.getValue().getLastModified());
For more information, see the Azure Docs.
- Parameters:
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the
Storage file properties
with headers and status code. - Throws:
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
setMetadata
Sets the user-defined metadata to associate to the file.If
null
is passed for the metadata it will clear the metadata associated to the file.Code Samples
Set the metadata to "file:updatedMetadata"
fileClient.setMetadata(Collections.singletonMap("file", "updatedMetadata")); System.out.println("Setting the file metadata completed.");
Clear the metadata of the file
fileClient.setMetadata(null); System.out.println("Setting the file metadata completed.");
For more information, see the Azure Docs.
- Parameters:
metadata
- Options.Metadata to set on the file, if null is passed the metadata for the file is cleared- Returns:
- The
file meta info
- Throws:
ShareStorageException
- If the file doesn't exist or the metadata contains invalid keys
-
setMetadataWithResponse
public Response<ShareFileMetadataInfo> setMetadataWithResponse(Map<String, String> metadata, Duration timeout, Context context) Sets the user-defined metadata to associate to the file.If
null
is passed for the metadata it will clear the metadata associated to the file.Code Samples
Set the metadata to "file:updatedMetadata"
Response<ShareFileMetadataInfo> response = fileClient.setMetadataWithResponse( Collections.singletonMap("file", "updatedMetadata"), Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Setting the file metadata completed with status code %d", response.getStatusCode());
Clear the metadata of the file
Response<ShareFileMetadataInfo> response = fileClient.setMetadataWithResponse(null, Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Setting the file metadata completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
metadata
- Options.Metadata to set on the file, if null is passed the metadata for the file is clearedtimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- Response containing the
file meta info
with headers and status code - Throws:
ShareStorageException
- If the file doesn't exist or the metadata contains invalid keysRuntimeException
- if the operation doesn't complete before the timeout concludes.
-
upload
Deprecated.UseuploadRange(InputStream, long)
instead. Or considerupload(InputStream, long, ParallelTransferOptions)
for an upload that can handle large amounts of data.Uploads a range of bytes to the beginning of a file in storage file service. Upload operations performs an in-place write on the specified file.Code Samples
Upload data "default" to the file in Storage File Service.
InputStream uploadData = new ByteArrayInputStream(data); ShareFileUploadInfo response = fileClient.upload(uploadData, data.length); System.out.println("Complete uploading the data with eTag: " + response.getETag());
For more information, see the Azure Docs.
- Parameters:
data
- The data which will upload to the storage file.length
- Specifies the number of bytes being transmitted in the request body. When the ShareFileRangeWriteType is set to clear, the value of this header must be set to zero.- Returns:
- The
file upload info
- Throws:
ShareStorageException
- If you attempt to upload a range that is larger than 4 MB, the service returns status code 413 (Request Entity Too Large)
-
uploadWithResponse
@Deprecated public Response<ShareFileUploadInfo> uploadWithResponse(InputStream data, long length, Long offset, Duration timeout, Context context) Deprecated.UseuploadRangeWithResponse(ShareFileUploadRangeOptions, Duration, Context)
instead. Or consideruploadWithResponse(ShareFileUploadOptions, Duration, Context)
for an upload that can handle large amounts of data.Uploads a range of bytes to specific of a file in storage file service. Upload operations performs an in-place write on the specified file.Code Samples
Upload data "default" starting from 1024.
InputStream uploadData = new ByteArrayInputStream(data); Response<ShareFileUploadInfo> response = fileClient.uploadWithResponse(uploadData, data.length, 0L, Duration.ofSeconds(30), null); System.out.printf("Completed uploading the data with response %d%n.", response.getStatusCode()); System.out.printf("ETag of the file is %s%n", response.getValue().getETag());
For more information, see the Azure Docs.
- Parameters:
data
- The data which will upload to the storage file.length
- Specifies the number of bytes being transmitted in the request body.offset
- Starting point of the upload range, ifnull
it will start from the beginning.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the
file upload info
with headers and response status code. - Throws:
ShareStorageException
- If you attempt to upload a range that is larger than 4 MB, the service returns status code 413 (Request Entity Too Large)RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
upload
public ShareFileUploadInfo upload(InputStream data, long length, ParallelTransferOptions transferOptions) Buffers a range of bytes and uploads sub-ranges in parallel to a file in storage file service. Upload operations perform an in-place write on the specified file.Code Samples
Upload data "default" to the file in Storage File Service.
InputStream uploadData = new ByteArrayInputStream(data); ShareFileUploadInfo response = shareFileClient.upload(uploadData, data.length, null); System.out.println("Complete uploading the data with eTag: " + response.getETag());
For more information, see the Azure Docs.
- Parameters:
data
- The data which will upload to the storage file.length
- Specifies the number of bytes being transmitted in the request body.transferOptions
-ParallelTransferOptions
for file transfer.- Returns:
- The
file upload info
-
uploadRange
Uploads a range of bytes to the specified offset of a file in storage file service. Upload operations perform an in-place write on the specified file.Code Samples
Upload data "default" to the file in Storage File Service.
InputStream uploadData = new ByteArrayInputStream(data); ShareFileUploadInfo response = shareFileClient.uploadRange(uploadData, data.length); System.out.println("Complete uploading the data with eTag: " + response.getETag());
This method does a single Put Range operation. For more information, see the Azure Docs.
- Parameters:
data
- The data which will upload to the storage file.length
- Specifies the number of bytes being transmitted in the request body.- Returns:
- The
file upload info
- Throws:
ShareStorageException
- If you attempt to upload a range that is larger than 4 MB, the service returns status code 413 (Request Entity Too Large)
-
uploadRangeFromUrl
public ShareFileUploadRangeFromUrlInfo uploadRangeFromUrl(long length, long destinationOffset, long sourceOffset, String sourceUrl) Uploads a range of bytes from one file to another file.Code Samples
Upload a number of bytes from a file at defined source and destination offsets
ShareFileUploadRangeFromUrlInfo response = fileClient.uploadRangeFromUrl(6, 8, 0, "sourceUrl"); System.out.println("Completed upload range from url!");
For more information, see the Azure Docs.
- Parameters:
length
- Specifies the number of bytes being transmitted in the request body.destinationOffset
- Starting point of the upload range on the destination.sourceOffset
- Starting point of the upload range on the source.sourceUrl
- Specifies the URL of the source file.- Returns:
- The
file upload range from url info
-
uploadRangeFromUrlWithResponse
public Response<ShareFileUploadRangeFromUrlInfo> uploadRangeFromUrlWithResponse(long length, long destinationOffset, long sourceOffset, String sourceUrl, Duration timeout, Context context) Uploads a range of bytes from one file to another file.Code Samples
Upload a number of bytes from a file at defined source and destination offsets
Response<ShareFileUploadRangeFromUrlInfo> response = fileClient.uploadRangeFromUrlWithResponse(6, 8, 0, "sourceUrl", Duration.ofSeconds(1), Context.NONE); System.out.println("Completed upload range from url!");
For more information, see the Azure Docs.
- Parameters:
length
- Specifies the number of bytes being transmitted in the request body.destinationOffset
- Starting point of the upload range on the destination.sourceOffset
- Starting point of the upload range on the source.sourceUrl
- Specifies the URL of the source file.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the
file upload range from url info
with headers and response status code. - Throws:
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
clearRange
Clears a range of bytes to specific of a file in storage file service. Clear operations performs an in-place write on the specified file.Code Samples
Clears the first 1024 bytes.
ShareFileUploadInfo response = fileClient.clearRange(1024); System.out.println("Complete clearing the range with eTag: " + response.getETag());
For more information, see the Azure Docs.
- Parameters:
length
- Specifies the number of bytes being cleared.- Returns:
- The
file upload info
-
clearRangeWithResponse
public Response<ShareFileUploadInfo> clearRangeWithResponse(long length, long offset, Duration timeout, Context context) Clears a range of bytes to specific of a file in storage file service. Upload operations performs an in-place write on the specified file.Code Samples
Clear the range starting from 1024 with length of 1024.
Response<ShareFileUploadInfo> response = fileClient.clearRangeWithResponse(1024, 1024, Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Complete clearing the range with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
length
- Specifies the number of bytes being transmitted in the request body.offset
- Starting point of the upload range, ifnull
it will start from the beginning.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the
file upload info
with headers and response status code. - Throws:
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
uploadFromFile
Uploads file to storage file service.Code Samples
Upload the file from the source file path.
fileClient.uploadFromFile("someFilePath");
For more information, see the Azure Docs Create File and Azure Docs Upload.
- Parameters:
uploadFilePath
- The path where store the source file to upload
-
listRanges
List of valid ranges for a file.Code Samples
List all ranges for the file client.
Iterable<ShareFileRange> ranges = fileClient.listRanges(); ranges.forEach(range -> System.out.printf("List ranges completed with start: %d, end: %d", range.getStart(), range.getEnd()));
For more information, see the Azure Docs.
- Returns:
ranges
in the files.
-
listRangesDiff
List of valid ranges for a file.Code Samples
List all ranges within the file range from 1KB to 2KB.
ShareFileRangeList rangeList = fileClient.listRangesDiff("previoussnapshot"); System.out.println("Valid Share File Ranges are:"); for (FileRange range : rangeList.getRanges()) { System.out.printf("Start: %s, End: %s%n", range.getStart(), range.getEnd()); }
For more information, see the Azure Docs.
- Parameters:
previousSnapshot
- Specifies that the response will contain only ranges that were changed between target file and previous snapshot. Changed ranges include both updated and cleared ranges. The target file may be a snapshot, as long as the snapshot specified by previousSnapshot is the older of the two.- Returns:
ranges
in the files that satisfy the requirements- Throws:
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
listHandles
List of open handles on a file.Code Samples
List all handles for the file client.
fileClient.listHandles() .forEach(handleItem -> System.out.printf("List handles completed with handleId %s", handleItem.getHandleId()));
For more information, see the Azure Docs.
- Returns:
handles
in the files that satisfy the requirements
-
listHandles
public PagedIterable<HandleItem> listHandles(Integer maxResultsPerPage, Duration timeout, Context context) List of open handles on a file.Code Samples
List 10 handles for the file client.
fileClient.listHandles(10, Duration.ofSeconds(1), new Context(key1, value1)) .forEach(handleItem -> System.out.printf("List handles completed with handleId %s", handleItem.getHandleId()));
For more information, see the Azure Docs.
- Parameters:
maxResultsPerPage
- Optional max number of results returned per pagetimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
handles
in the file that satisfy the requirements- Throws:
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
forceCloseHandle
Closes a handle on the file at the service. This is intended to be used alongsidelistHandles()
.Code Samples
Force close handles returned by list handles.
fileClient.listHandles().forEach(handleItem -> { fileClient.forceCloseHandle(handleItem.getHandleId()); System.out.printf("Closed handle %s on resource %s%n", handleItem.getHandleId(), handleItem.getPath()); });
For more information, see the Azure Docs.
- Parameters:
handleId
- Handle ID to be closed.- Returns:
- Information about the closed handles.
-
forceCloseHandleWithResponse
public Response<CloseHandlesInfo> forceCloseHandleWithResponse(String handleId, Duration timeout, Context context) Closes a handle on the file at the service. This is intended to be used alongsidelistHandles()
.Code Samples
Force close handles returned by list handles.
fileClient.listHandles().forEach(handleItem -> { Response<CloseHandlesInfo> closeResponse = fileClient .forceCloseHandleWithResponse(handleItem.getHandleId(), Duration.ofSeconds(30), Context.NONE); System.out.printf("Closing handle %s on resource %s completed with status code %d%n", handleItem.getHandleId(), handleItem.getPath(), closeResponse.getStatusCode()); });
For more information, see the Azure Docs.
- Parameters:
handleId
- Handle ID to be closed.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that contains information about the closed handles, headers and response status code.
-
forceCloseAllHandles
Closes all handles opened on the file at the service.Code Samples
Force close all handles.
CloseHandlesInfo closeHandlesInfo = fileClient.forceCloseAllHandles(Duration.ofSeconds(30), Context.NONE); System.out.printf("Closed %d open handles on the file%n", closeHandlesInfo.getClosedHandles()); System.out.printf("Failed to close %d open handles on the file%n", closeHandlesInfo.getFailedHandles());
For more information, see the Azure Docs.
- Parameters:
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- Information about the closed handles
-
rename
Moves the file to another location within the share. For more information see the Azure Docs.Code Samples
ShareFileClient renamedClient = client.rename(destinationPath); System.out.println("File Client has been renamed");
- Parameters:
destinationPath
- Relative path from the share to rename the file to.- Returns:
- A
ShareFileClient
used to interact with the new file created.
-
getFilePath
Get file path of the client.Get the file path.
String filePath = fileClient.getFilePath(); System.out.println("The name of the file is " + filePath);
- Returns:
- The path of the file.
-
getAccountName
Get associated account name.- Returns:
- account name associated with this storage resource.
-
getHttpPipeline
Gets theHttpPipeline
powering this client.- Returns:
- The pipeline.
-
uploadRange(InputStream, long)
instead.