共用方式為


ShareFileClient Class

  • java.lang.Object
    • com.azure.storage.file.share.ShareFileClient

public class ShareFileClient

This class provides a client that contains all the operations for interacting files under Azure Storage File Service. Operations allowed by the client are creating, uploading, copying, listing, downloading, and deleting files.

Instantiating a synchronous File Client

ShareFileClient client = new ShareFileClientBuilder()
     .connectionString("${connectionString}")
     .endpoint("${endpoint}")
     .buildFileClient();

View ShareFileClientBuilder for additional ways to construct the client.

Method Summary

Modifier and Type Method and Description
void abortCopy(String copyId)

Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.

Response<Void> 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.

Response<Void> abortCopyWithResponse(String copyId, Duration timeout, Context context)

Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.

SyncPoller<ShareFileCopyInfo,Void> 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.

SyncPoller<ShareFileCopyInfo,Void> beginCopy(String sourceUrl, ShareFileCopyOptions options, Duration pollInterval)

Copies a blob or file to a destination file within the storage account.

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.

ShareFileUploadInfo clearRange(long length)

Clears a range of bytes to specific of a file in storage file service.

Response<ShareFileUploadInfo> 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.

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.

ShareFileInfo create(long maxSize)

Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.

Response<ShareFileInfo> createWithResponse(ShareFileCreateOptions options, Duration timeout, Context context)

Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.

Response<ShareFileInfo> 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.

Response<ShareFileInfo> 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 deleteIfExists()

Deletes the file associate with the client if it exists.

Response<Boolean> deleteIfExistsWithResponse(ShareRequestConditions requestConditions, Duration timeout, Context context)

Deletes the file associate with the client if it exists.

Response<Void> deleteWithResponse(ShareRequestConditions requestConditions, Duration timeout, Context context)

Deletes the file associate with the client.

Response<Void> 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 properties

ShareFileProperties downloadToFile(String downloadFilePath)

Downloads a file from the system, including its metadata and properties into a file specified by the path.

Response<ShareFileProperties> 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.

Response<ShareFileProperties> 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.

ShareFileDownloadResponse downloadWithResponse(OutputStream stream, ShareFileRange range, Boolean rangeGetContentMD5, ShareRequestConditions requestConditions, Duration timeout, Context context)

Downloads a file from the system, including its metadata and properties

ShareFileDownloadResponse downloadWithResponse(OutputStream stream, ShareFileRange range, Boolean rangeGetContentMD5, Duration timeout, Context context)

Downloads a file from the system, including its metadata and properties

ShareFileDownloadResponse downloadWithResponse(OutputStream stream, ShareFileDownloadOptions options, Duration timeout, Context context)

Downloads a file from the system, including its metadata and properties

Boolean exists()

Determines if the file this client represents exists in the cloud.

Response<Boolean> existsWithResponse(Duration timeout, Context context)

Determines if the file this client represents exists in the cloud.

CloseHandlesInfo forceCloseAllHandles(Duration timeout, Context context)

Closes all handles opened on the file at the service.

CloseHandlesInfo forceCloseHandle(String handleId)

Closes a handle on the file at the service.

Response<CloseHandlesInfo> forceCloseHandleWithResponse(String handleId, Duration timeout, Context context)

Closes a handle on the file at the service.

String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues)

Generates a service SAS for the file using the specified ShareServiceSasSignatureValues

String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Context context)

Generates a service SAS for the file using the specified ShareServiceSasSignatureValues

String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Consumer<String> stringToSignHandler, Context context)

Generates a service SAS for the file using the specified ShareServiceSasSignatureValues

String getAccountName()

Get associated account name.

String getAccountUrl()

Get the url of the storage account.

final StorageFileOutputStream getFileOutputStream()

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.

String getFilePath()

Get file path of the client.

SeekableByteChannel getFileSeekableByteChannelRead(ShareFileSeekableByteChannelReadOptions options)

Creates and opens a SeekableByteChannel to read data from the file.

SeekableByteChannel getFileSeekableByteChannelWrite(ShareFileSeekableByteChannelWriteOptions options)

Creates and opens a SeekableByteChannel to write data to the file.

String getFileUrl()

Get the url of the storage file client.

HttpPipeline getHttpPipeline()

Gets the HttpPipeline powering this client.

ShareFileProperties getProperties()

Retrieves the properties of the storage account's file.

Response<ShareFileProperties> getPropertiesWithResponse(ShareRequestConditions requestConditions, Duration timeout, Context context)

Retrieves the properties of the storage account's file.

Response<ShareFileProperties> getPropertiesWithResponse(Duration timeout, Context context)

Retrieves the properties of the storage account's file.

ShareServiceVersion getServiceVersion()

Gets the service version the client is using.

String getShareName()

Get the share name of file client.

String getShareSnapshotId()

Get snapshot id which attached to ShareFileClient.

PagedIterable<HandleItem> listHandles()

List of open handles on a file.

PagedIterable<HandleItem> listHandles(Integer maxResultsPerPage, Duration timeout, Context context)

List of open handles on a file.

PagedIterable<ShareFileRange> listRanges()

List of valid ranges for a file.

PagedIterable<ShareFileRange> listRanges(ShareFileRange range, ShareRequestConditions requestConditions, Duration timeout, Context context)

List of valid ranges for a file.

PagedIterable<ShareFileRange> listRanges(ShareFileRange range, Duration timeout, Context context)

List of valid ranges for a file.

ShareFileRangeList listRangesDiff(String previousSnapshot)

List of valid ranges for a file.

Response<ShareFileRangeList> listRangesDiffWithResponse(ShareFileListRangesDiffOptions options, Duration timeout, Context context)

List of valid ranges for a file.

final StorageFileInputStream openInputStream()

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.

ShareFileClient rename(String destinationPath)

Moves the file to another location within the share.

Response<ShareFileClient> renameWithResponse(ShareFileRenameOptions options, Duration timeout, Context context)

Moves the file to another location within the share.

ShareFileMetadataInfo setMetadata(Map<String,String> metadata)

Sets the user-defined metadata to associate to the file.

Response<ShareFileMetadataInfo> setMetadataWithResponse(Map<String,String> metadata, ShareRequestConditions requestConditions, Duration timeout, Context context)

Sets the user-defined metadata to associate to the file.

Response<ShareFileMetadataInfo> setMetadataWithResponse(Map<String,String> metadata, Duration timeout, Context context)

Sets the user-defined metadata to associate to the file.

ShareFileInfo setProperties(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission)

Sets the user-defined httpHeaders to associate to the file.

Response<ShareFileInfo> setPropertiesWithResponse(ShareFileSetPropertiesOptions options, Duration timeout, Context context)

Sets the user-defined httpHeaders to associate to the file.

Response<ShareFileInfo> 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.

Response<ShareFileInfo> setPropertiesWithResponse(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Duration timeout, Context context)

Sets the user-defined httpHeaders to associate to the file.

ShareFileUploadInfo upload(InputStream data, long length)

Deprecated

Use uploadRange(InputStream data, long length) instead. Or consider upload(InputStream data, long length, ParallelTransferOptions transferOptions) 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.

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.

void uploadFromFile(String uploadFilePath)

Uploads file to storage file service.

void uploadFromFile(String uploadFilePath, ShareRequestConditions requestConditions)

Uploads file to storage file service.

ShareFileUploadInfo uploadRange(InputStream data, long length)

Uploads a range of bytes to the specified offset of a file in storage file service.

ShareFileUploadRangeFromUrlInfo uploadRangeFromUrl(long length, long destinationOffset, long sourceOffset, String sourceUrl)

Uploads a range of bytes from one file to another file.

Response<ShareFileUploadRangeFromUrlInfo> uploadRangeFromUrlWithResponse(ShareFileUploadRangeFromUrlOptions options, Duration timeout, Context context)

Uploads a range of bytes from one file to another file.

Response<ShareFileUploadRangeFromUrlInfo> 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.

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.

Response<ShareFileUploadInfo> uploadRangeWithResponse(ShareFileUploadRangeOptions options, Duration timeout, Context context)

Uploads a range of bytes to the specified offset of a file in storage file service.

Response<ShareFileUploadInfo> 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.

Response<ShareFileUploadInfo> uploadWithResponse(InputStream data, long length, Long offset, ShareRequestConditions requestConditions, Duration timeout, Context context)

Deprecated

Uploads a range of bytes to specific of a file in storage file service.

Response<ShareFileUploadInfo> uploadWithResponse(InputStream data, long length, Long offset, Duration timeout, Context context)

Deprecated

Uploads a range of bytes to specific of a file in storage file service.

Methods inherited from java.lang.Object

Method Details

abortCopy

public void abortCopy(String copyId)

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

public Response 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.

Code Samples

Abort copy file from copy id("someCopyId")

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<Void> response = fileClient.abortCopyWithResponse("someCopyId", requestConditions,
     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.
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException 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.

abortCopyWithResponse

public Response abortCopyWithResponse(String copyId, Duration timeout, Context context)

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 a RuntimeException 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.

beginCopy

public SyncPoller beginCopy(String sourceUrl, FileSmbProperties smbProperties, String filePermission, PermissionCopyModeType filePermissionCopyMode, Boolean ignoreReadOnly, Boolean setArchiveAttribute, Map metadata, Duration pollInterval, ShareRequestConditions destinationRequestConditions)

Copies a blob or file to a destination file within the storage account.

Code Samples

Copy file from source getDirectoryUrl to the resourcePath

FileSmbProperties smbProperties = new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey");
 String filePermission = "filePermission";
 // NOTE: filePermission and filePermissionKey should never be both set
 boolean ignoreReadOnly = false; // Default value
 boolean setArchiveAttribute = true; // Default value
 ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);

 SyncPoller<ShareFileCopyInfo, Void> poller = fileClient.beginCopy(
     "https://{accountName}.file.core.windows.net?{SASToken}", smbProperties, filePermission,
     PermissionCopyModeType.SOURCE, ignoreReadOnly, setArchiveAttribute,
     Collections.singletonMap("file", "metadata"), Duration.ofSeconds(2), requestConditions);

 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.
smbProperties - The user settable file smb properties.
filePermission - The file permission of the file.
filePermissionCopyMode - Mode of file permission acquisition.
ignoreReadOnly - Whether to copy despite target being read only. (default is false)
setArchiveAttribute - Whether the archive attribute is to be set on the target. (default is true)
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.
destinationRequestConditions - ShareRequestConditions

Returns:

A SyncPoller<T,U> to poll the progress of copy operation.

beginCopy

public SyncPoller beginCopy(String sourceUrl, ShareFileCopyOptions options, 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

FileSmbProperties smbProperties = new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey");
 String filePermission = "filePermission";
 // NOTE: filePermission and filePermissionKey should never be both set
 boolean ignoreReadOnly = false; // Default value
 boolean setArchiveAttribute = true; // Default value
 ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 CopyableFileSmbPropertiesList list = new CopyableFileSmbPropertiesList().setCreatedOn(true).setLastWrittenOn(true);
 // NOTE: FileSmbProperties and CopyableFileSmbPropertiesList should never be both set

 ShareFileCopyOptions options = new ShareFileCopyOptions()
     .setSmbProperties(smbProperties)
     .setFilePermission(filePermission)
     .setIgnoreReadOnly(ignoreReadOnly)
     .setArchiveAttribute(setArchiveAttribute)
     .setDestinationRequestConditions(requestConditions)
     .setSmbPropertiesToCopy(list)
     .setPermissionCopyModeType(PermissionCopyModeType.SOURCE)
     .setMetadata(Collections.singletonMap("file", "metadata"))
     .setFilePermissionFormat(FilePermissionFormat.BINARY);

 SyncPoller<ShareFileCopyInfo, Void> poller = fileClient.beginCopy(
     "https://{accountName}.file.core.windows.net?{SASToken}", options, 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.
pollInterval - Duration between each poll for the copy status. If none is specified, a default of one second is used.

Returns:

A SyncPoller<T,U> to poll the progress of copy operation.

beginCopy

public SyncPoller beginCopy(String sourceUrl, Map 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<T,U> to poll the progress of copy operation.

clearRange

public ShareFileUploadInfo clearRange(long length)

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:

clearRangeWithResponse

public Response 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. Upload operations performs an in-place write on the specified file.

Code Samples

Clear the range starting from 1024 with length of 1024.

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<ShareFileUploadInfo> response = fileClient.clearRangeWithResponse(1024, 1024, requestConditions,
     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, if null it will start from the beginning.
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileUploadInfo with headers and response status code.

clearRangeWithResponse

public Response 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, if null it will start from the beginning.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileUploadInfo with headers and response status code.

create

public ShareFileInfo create(long maxSize)

Creates a file in the storage account and returns a response of ShareFileInfo 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:

createWithResponse

public Response createWithResponse(ShareFileCreateOptions options, Duration timeout, Context context)

Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.

Code Samples

Create the file with length of 1024 bytes, some headers, file smb properties and metadata.

ShareFileCreateOptions options = new ShareFileCreateOptions(1024);

 options.setShareFileHttpHeaders(new ShareFileHttpHeaders()
     .setContentType("text/html")
     .setContentEncoding("gzip")
     .setContentLanguage("en")
     .setCacheControl("no-transform")
     .setContentDisposition("attachment"));
 options.setSmbProperties(new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey"));
 options.setFilePermission("filePermission");
 options.setFilePermissionFormat(FilePermissionFormat.BINARY);
 options.setMetadata(Collections.singletonMap("directory", "metadata"));
 options.setRequestConditions(new ShareRequestConditions().setLeaseId(leaseId));
 // NOTE: filePermission and filePermissionKey should never be both set
 Response<ShareFileInfo> response2 = fileClient.createWithResponse(options, Duration.ofSeconds(1),
     new Context(key1, value1));
 System.out.printf("Creating the file completed with status code %d", response2.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 a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileInfo and the status of creating the file.

createWithResponse

public Response createWithResponse(long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map metadata, ShareRequestConditions requestConditions, Duration timeout, Context context)

Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.

Code Samples

Create the file with length of 1024 bytes, some headers, file smb properties and metadata.

ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
     .setContentType("text/html")
     .setContentEncoding("gzip")
     .setContentLanguage("en")
     .setCacheControl("no-transform")
     .setContentDisposition("attachment");
 FileSmbProperties smbProperties = new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey");
 String filePermission = "filePermission";
 // NOTE: filePermission and filePermissionKey should never be both set

 ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);

 Response<ShareFileInfo> response = fileClient.createWithResponse(1024, httpHeaders, smbProperties,
     filePermission, Collections.singletonMap("directory", "metadata"), requestConditions, Duration.ofSeconds(1),
     new Context(key1, value1));
 System.out.printf("Creating the file completed with status code %d", response.getStatusCode());

For more information, see the Azure Docs.

Parameters:

maxSize - The maximum size in bytes for the file.
httpHeaders - The user settable file http headers.
smbProperties - The user settable file smb properties.
filePermission - The file permission of the file.
metadata - Optional name-value pairs associated with the file as metadata.
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileInfo and the status of creating the file.

createWithResponse

public Response createWithResponse(long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map metadata, Duration timeout, Context context)

Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.

Code Samples

Create the file with length of 1024 bytes, some headers, file smb properties and metadata.

ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
     .setContentType("text/html")
     .setContentEncoding("gzip")
     .setContentLanguage("en")
     .setCacheControl("no-transform")
     .setContentDisposition("attachment");
 FileSmbProperties smbProperties = new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey");
 String filePermission = "filePermission";
 // NOTE: filePermission and filePermissionKey should never be both set
 Response<ShareFileInfo> response = fileClient.createWithResponse(1024, httpHeaders, smbProperties,
     filePermission, Collections.singletonMap("directory", "metadata"), Duration.ofSeconds(1),
     new Context(key1, value1));
 System.out.printf("Creating the file completed with status code %d", response.getStatusCode());

For more information, see the Azure Docs.

Parameters:

maxSize - The maximum size in bytes for the file.
httpHeaders - The user settable file http headers.
smbProperties - The user settable file smb properties.
filePermission - The file permission of the file.
metadata - Optional name-value pairs associated with the file as metadata.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileInfo and the status of creating the file.

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.

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.

deleteIfExistsWithResponse

public Response deleteIfExistsWithResponse(ShareRequestConditions requestConditions, Duration timeout, Context context)

Deletes the file associate with the client if it exists.

Code Samples

Delete the file

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<Boolean> response = fileClient.deleteIfExistsWithResponse(requestConditions, Duration.ofSeconds(1),
     new Context(key1, value1));
 if (response.getStatusCode() == 404) {
     System.out.println("Does not exist.");
 } else {
     System.out.printf("Delete completed with status %d%n", response.getStatusCode());
 }

For more information, see the Azure Docs.

Parameters:

requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing status code and HTTP headers. If Response<T>'s status code is 202, the file was successfully deleted. If status code is 404, the file does not exist.

deleteWithResponse

public Response deleteWithResponse(ShareRequestConditions requestConditions, Duration timeout, Context context)

Deletes the file associate with the client.

Code Samples

Delete the file

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<Void> response = fileClient.deleteWithResponse(requestConditions, 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:

requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException 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

deleteWithResponse

public Response deleteWithResponse(Duration timeout, Context context)

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 a RuntimeException 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

download

public void download(OutputStream stream)

Downloads a file from the system, including its metadata and properties

Code 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-null OutputStream where the downloaded data will be written.

downloadToFile

public ShareFileProperties downloadToFile(String downloadFilePath)

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.

downloadToFileWithResponse

public Response 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.

The file will be created and must not exist, if the file already exists a FileAlreadyExistsException will be thrown.

Code Samples

Download the file from 1024 to 2048 bytes to current folder.

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<ShareFileProperties> response =
     fileClient.downloadToFileWithResponse("somelocalfilepath", new ShareFileRange(1024, 2047L),
         requestConditions, Duration.ofSeconds(1), Context.NONE);
 if (Files.exists(Paths.get("somelocalfilepath"))) {
     System.out.println("Complete downloading the file with status code " + response.getStatusCode());
 }

For more information, see the Azure Docs.

Parameters:

downloadFilePath - The path where store the downloaded file
range - Optional byte range which returns file data only from the specified range.
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

The response of the file properties.

downloadToFileWithResponse

public Response 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.

The file will be created and must not exist, if the file already exists a FileAlreadyExistsException will be thrown.

Code Samples

Download the file from 1024 to 2048 bytes to current folder.

Response<ShareFileProperties> response =
     fileClient.downloadToFileWithResponse("somelocalfilepath", new ShareFileRange(1024, 2047L),
         Duration.ofSeconds(1), Context.NONE);
 if (Files.exists(Paths.get("somelocalfilepath"))) {
     System.out.println("Complete downloading the file with status code " + response.getStatusCode());
 }

For more information, see the Azure Docs.

Parameters:

downloadFilePath - The path where store the downloaded file
range - Optional byte range which returns file data only from the specified range.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

The response of the file properties.

downloadWithResponse

public ShareFileDownloadResponse downloadWithResponse(OutputStream stream, ShareFileRange range, Boolean rangeGetContentMD5, ShareRequestConditions requestConditions, Duration timeout, Context context)

Downloads a file from the system, including its metadata and properties

Code Samples

Download the file from 1024 to 2048 bytes with its metadata and properties and without the contentMD5.

try {
     ByteArrayOutputStream stream = new ByteArrayOutputStream();
     ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
     Response<Void> response = fileClient.downloadWithResponse(stream, new ShareFileRange(1024, 2047L), false,
         requestConditions, Duration.ofSeconds(30), new Context(key1, value1));

     System.out.printf("Completed downloading file with status code %d%n", response.getStatusCode());
     System.out.printf("Content of the file is: %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-null OutputStream where the downloaded data will be written.
range - Optional byte range which returns file data only from the specified range.
rangeGetContentMD5 - Optional boolean which the service returns the MD5 hash for the range when it sets to true, as long as the range is less than or equal to 4 MB in size.
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the headers and response status code

downloadWithResponse

public ShareFileDownloadResponse downloadWithResponse(OutputStream stream, ShareFileRange range, Boolean rangeGetContentMD5, Duration timeout, Context context)

Downloads a file from the system, including its metadata and properties

Code Samples

Download the file from 1024 to 2048 bytes with its metadata and properties and without the contentMD5.

try {
     ByteArrayOutputStream stream = new ByteArrayOutputStream();
     Response<Void> response = fileClient.downloadWithResponse(stream, new ShareFileRange(1024, 2047L), false,
         Duration.ofSeconds(30), new Context(key1, value1));

     System.out.printf("Completed downloading file with status code %d%n", response.getStatusCode());
     System.out.printf("Content of the file is: %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-null OutputStream where the downloaded data will be written.
range - Optional byte range which returns file data only from the specified range.
rangeGetContentMD5 - Optional boolean which the service returns the MD5 hash for the range when it sets to true, as long as the range is less than or equal to 4 MB in size.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the headers and response status code

downloadWithResponse

public ShareFileDownloadResponse downloadWithResponse(OutputStream stream, ShareFileDownloadOptions options, Duration timeout, Context context)

Downloads a file from the system, including its metadata and properties

Code Samples

Download the file from 1024 to 2048 bytes with its metadata and properties and without the contentMD5.

try {
     ByteArrayOutputStream stream = new ByteArrayOutputStream();
     ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
     ShareFileRange range = new ShareFileRange(1024, 2047L);
     DownloadRetryOptions retryOptions = new DownloadRetryOptions().setMaxRetryRequests(3);
     ShareFileDownloadOptions options = new ShareFileDownloadOptions().setRange(range)
         .setRequestConditions(requestConditions)
         .setRangeContentMd5Requested(false)
         .setRetryOptions(retryOptions);
     Response<Void> response = fileClient.downloadWithResponse(stream, options, Duration.ofSeconds(30),
         new Context(key1, value1));

     System.out.printf("Completed downloading file with status code %d%n", response.getStatusCode());
     System.out.printf("Content of the file is: %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-null OutputStream where the downloaded data will be written.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the headers and response status code

exists

public Boolean 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

public Response existsWithResponse(Duration timeout, Context context)

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 a RuntimeException will be raised.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

Flag indicating existence of the file.

forceCloseAllHandles

public CloseHandlesInfo forceCloseAllHandles(Duration timeout, Context context)

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 a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

Information about the closed handles

forceCloseHandle

public CloseHandlesInfo forceCloseHandle(String handleId)

Closes a handle on the file at the service. This is intended to be used alongside listHandles().

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 forceCloseHandleWithResponse(String handleId, Duration timeout, Context context)

Closes a handle on the file at the service. This is intended to be used alongside listHandles().

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 a RuntimeException 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.

generateSas

public String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues)

Generates a service SAS for the file using the specified ShareServiceSasSignatureValues

Note : The client must be authenticated via StorageSharedKeyCredential

See ShareServiceSasSignatureValues for more information on how to construct a service SAS.

Code Samples

OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1);
 ShareFileSasPermission permission = new ShareFileSasPermission().setReadPermission(true);

 ShareServiceSasSignatureValues values = new ShareServiceSasSignatureValues(expiryTime, permission)
     .setStartTime(OffsetDateTime.now());

 shareFileClient.generateSas(values); // Client must be authenticated via StorageSharedKeyCredential

Parameters:

shareServiceSasSignatureValues - ShareServiceSasSignatureValues

Returns:

A String representing the SAS query parameters.

generateSas

public String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Context context)

Generates a service SAS for the file using the specified ShareServiceSasSignatureValues

Note : The client must be authenticated via StorageSharedKeyCredential

See ShareServiceSasSignatureValues for more information on how to construct a service SAS.

Code Samples

OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1);
 ShareFileSasPermission permission = new ShareFileSasPermission().setReadPermission(true);

 ShareServiceSasSignatureValues values = new ShareServiceSasSignatureValues(expiryTime, permission)
     .setStartTime(OffsetDateTime.now());

 // Client must be authenticated via StorageSharedKeyCredential
 shareFileClient.generateSas(values, new Context("key", "value"));

Parameters:

shareServiceSasSignatureValues - ShareServiceSasSignatureValues
context - Additional context that is passed through the code when generating a SAS.

Returns:

A String representing the SAS query parameters.

generateSas

public String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Consumer stringToSignHandler, Context context)

Generates a service SAS for the file using the specified ShareServiceSasSignatureValues

Note : The client must be authenticated via StorageSharedKeyCredential

See ShareServiceSasSignatureValues for more information on how to construct a service SAS.

Parameters:

shareServiceSasSignatureValues - ShareServiceSasSignatureValues
stringToSignHandler - For debugging purposes only. Returns the string to sign that was used to generate the signature.
context - Additional context that is passed through the code when generating a SAS.

Returns:

A String representing the SAS query parameters.

getAccountName

public String getAccountName()

Get associated account name.

Returns:

account name associated with this storage resource.

getAccountUrl

public String getAccountUrl()

Get the url of the storage account.

Returns:

the URL of the storage account

getFileOutputStream

public final StorageFileOutputStream 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.

getFileOutputStream

public final StorageFileOutputStream getFileOutputStream(long offset)

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.

Returns:

A StorageFileOutputStream object used to write data to the file.

getFilePath

public String 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.

getFileSeekableByteChannelRead

public SeekableByteChannel getFileSeekableByteChannelRead(ShareFileSeekableByteChannelReadOptions options)

Creates and opens a SeekableByteChannel to read data from the file.

Parameters:

options - Options for opening the channel.

Returns:

The opened channel.

getFileSeekableByteChannelWrite

public SeekableByteChannel getFileSeekableByteChannelWrite(ShareFileSeekableByteChannelWriteOptions options)

Creates and opens a SeekableByteChannel to write data to the file.

Parameters:

options - Options for opening the channel.

Returns:

The opened channel.

getFileUrl

public String getFileUrl()

Get the url of the storage file client.

Returns:

the URL of the storage file client.

getHttpPipeline

public HttpPipeline getHttpPipeline()

Gets the HttpPipeline powering this client.

Returns:

The pipeline.

getProperties

public ShareFileProperties 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:

getPropertiesWithResponse

public Response getPropertiesWithResponse(ShareRequestConditions requestConditions, Duration timeout, Context context)

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

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<ShareFileProperties> response = fileClient.getPropertiesWithResponse(requestConditions,
     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:

requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileProperties with headers and status code.

getPropertiesWithResponse

public Response getPropertiesWithResponse(Duration timeout, Context context)

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 a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileProperties with headers and status code.

getServiceVersion

public ShareServiceVersion getServiceVersion()

Gets the service version the client is using.

Returns:

the service version the client is using.

getShareName

public String getShareName()

Get the share name of file client.

Get the share name.

String shareName = fileClient.getShareName();
 System.out.println("The share name of the directory is " + shareName);

Returns:

The share name of the file.

getShareSnapshotId

public String getShareSnapshotId()

Get snapshot id which attached to ShareFileClient. Return null if no snapshot id attached.

Code Samples

Get the share snapshot id.

OffsetDateTime currentTime = OffsetDateTime.of(LocalDateTime.now(), ZoneOffset.UTC);
 ShareFileClient fileClient = new ShareFileClientBuilder()
     .endpoint("https://${accountName}.file.core.windows.net")
     .sasToken("${SASToken}")
     .shareName("myshare")
     .resourcePath("myfile")
     .snapshot(currentTime.toString())
     .buildFileClient();

 System.out.printf("Snapshot ID: %s%n", fileClient.getShareSnapshotId());

Returns:

The snapshot id which is a unique DateTime value that identifies the share snapshot to its base share.

listHandles

public PagedIterable 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:

HandleItem in the files that satisfy the requirements

listHandles

public PagedIterable 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 page
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

HandleItem in the file that satisfy the requirements

listRanges

public PagedIterable 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:

ShareFileRange in the files.

listRanges

public PagedIterable listRanges(ShareFileRange range, ShareRequestConditions requestConditions, Duration timeout, Context context)

List of valid ranges for a file.

Code Samples

List all ranges within the file range from 1KB to 2KB.

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Iterable<ShareFileRange> ranges = fileClient.listRanges(new ShareFileRange(1024, 2048L), requestConditions,
     Duration.ofSeconds(1), new Context(key1, value1));
 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.

Parameters:

range - Optional byte range which returns file data only from the specified range.
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

ShareFileRange in the files that satisfy the requirements

listRanges

public PagedIterable listRanges(ShareFileRange range, Duration timeout, Context context)

List of valid ranges for a file.

Code Samples

List all ranges within the file range from 1KB to 2KB.

Iterable<ShareFileRange> ranges = fileClient.listRanges(new ShareFileRange(1024, 2048L), Duration.ofSeconds(1),
     new Context(key1, value1));
 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.

Parameters:

range - Optional byte range which returns file data only from the specified range.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

ShareFileRange in the files that satisfy the requirements

listRangesDiff

public ShareFileRangeList listRangesDiff(String previousSnapshot)

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:

ShareFileRange in the files that satisfy the requirements

listRangesDiffWithResponse

public Response listRangesDiffWithResponse(ShareFileListRangesDiffOptions options, Duration timeout, Context context)

List of valid ranges for a file.

Code Samples

List all ranges within the file range from 1KB to 2KB.

ShareFileRangeList rangeList = fileClient.listRangesDiffWithResponse(
     new ShareFileListRangesDiffOptions("previoussnapshot")
     .setRange(new ShareFileRange(1024, 2048L)), Duration.ofSeconds(1), new Context(key1, value1)).getValue();
 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:

timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

ShareFileRange in the files that satisfy the requirements

openInputStream

public final StorageFileInputStream 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.

openInputStream

public final StorageFileInputStream openInputStream(ShareFileRange range)

Opens a file input stream to download the specified range of the file.

Parameters:

range - ShareFileRange

Returns:

An InputStream object that represents the stream to use for reading from the file.

rename

public ShareFileClient rename(String destinationPath)

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.

renameWithResponse

public Response renameWithResponse(ShareFileRenameOptions options, Duration timeout, Context context)

Moves the file to another location within the share. For more information see the Azure Docs.

Code Samples

FileSmbProperties smbProperties = new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey");
 ShareFileRenameOptions options = new ShareFileRenameOptions(destinationPath)
     .setDestinationRequestConditions(new ShareRequestConditions().setLeaseId(leaseId))
     .setSourceRequestConditions(new ShareRequestConditions().setLeaseId(leaseId))
     .setIgnoreReadOnly(false)
     .setReplaceIfExists(false)
     .setFilePermission("filePermission")
     .setSmbProperties(smbProperties);

 ShareFileClient newRenamedClient = client.renameWithResponse(options, timeout, new Context(key1, value1))
     .getValue();
 System.out.println("File Client has been renamed");

Parameters:

timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A Response<T> whose value contains a ShareFileClient used to interact with the file created.

setMetadata

public ShareFileMetadataInfo setMetadata(Map metadata)

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:

setMetadataWithResponse

public Response setMetadataWithResponse(Map metadata, ShareRequestConditions requestConditions, 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"

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<ShareFileMetadataInfo> response = fileClient.setMetadataWithResponse(
     Collections.singletonMap("file", "updatedMetadata"), requestConditions, 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

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<ShareFileMetadataInfo> response = fileClient.setMetadataWithResponse(null, requestConditions,
     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 cleared
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

Response containing the ShareFileMetadataInfo with headers and status code

setMetadataWithResponse

public Response setMetadataWithResponse(Map 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 cleared
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

Response containing the ShareFileMetadataInfo with headers and status code

setProperties

public ShareFileInfo setProperties(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission)

Sets the user-defined httpHeaders to associate to the file.

If null is passed for the httpHeaders it will clear the httpHeaders associated to the file.

Code Samples

Set the httpHeaders of contentType of "text/plain"

ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
     .setContentType("text/html")
     .setContentEncoding("gzip")
     .setContentLanguage("en")
     .setCacheControl("no-transform")
     .setContentDisposition("attachment");
 FileSmbProperties smbProperties = new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey");
 String filePermission = "filePermission";
 // NOTE: filePermission and filePermissionKey should never be both set
 fileClient.setProperties(1024, httpHeaders, smbProperties, filePermission);
 System.out.println("Setting the file httpHeaders completed.");

Clear the httpHeaders of the file and preserve the SMB properties

ShareFileInfo response = fileClient.setProperties(1024, null, null, null);
 System.out.println("Setting the file httpHeaders completed.");

For more information, see the Azure Docs.

Parameters:

newFileSize - New file size of the file
httpHeaders - The user settable file http headers.
smbProperties - The user settable file smb properties.
filePermission - The file permission of the file

Returns:

setPropertiesWithResponse

public Response setPropertiesWithResponse(ShareFileSetPropertiesOptions options, Duration timeout, Context context)

Sets the user-defined httpHeaders to associate to the file.

If null is passed for the httpHeaders it will clear the httpHeaders associated to the file.

Code Samples

Set the httpHeaders of contentType of "text/plain"

ShareFileSetPropertiesOptions options = new ShareFileSetPropertiesOptions(1024);
 options.setRequestConditions(new ShareRequestConditions().setLeaseId(leaseId));
 options.setHttpHeaders(new ShareFileHttpHeaders()
     .setContentType("text/html")
     .setContentEncoding("gzip")
     .setContentLanguage("en")
     .setCacheControl("no-transform")
     .setContentDisposition("attachment"));
 options.setSmbProperties(new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey"));
 options.setFilePermissions(new ShareFilePermission().setPermission("filePermission")
     .setPermissionFormat(FilePermissionFormat.BINARY));
 // NOTE: filePermission and filePermissionKey should never be both set
 fileClient.setPropertiesWithResponse(options, null, null);
 System.out.println("Setting the file httpHeaders completed.");

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 a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

Response containing the ShareFileInfo with headers and status code

setPropertiesWithResponse

public Response 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.

If null is passed for the httpHeaders it will clear the httpHeaders associated to the file.

Code Samples

Set the httpHeaders of contentType of "text/plain"

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
     .setContentType("text/html")
     .setContentEncoding("gzip")
     .setContentLanguage("en")
     .setCacheControl("no-transform")
     .setContentDisposition("attachment");
 FileSmbProperties smbProperties = new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey");
 String filePermission = "filePermission";
 // NOTE: filePermission and filePermissionKey should never be both set
 fileClient.setPropertiesWithResponse(1024, httpHeaders, smbProperties, filePermission, requestConditions, null,
     null);
 System.out.println("Setting the file httpHeaders completed.");

Clear the httpHeaders of the file and preserve the SMB properties

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<ShareFileInfo> response = fileClient.setPropertiesWithResponse(1024, null, null, null, requestConditions,
     Duration.ofSeconds(1), new Context(key1, value1));
 System.out.printf("Setting the file httpHeaders completed with status code %d", response.getStatusCode());

For more information, see the Azure Docs.

Parameters:

newFileSize - New file size of the file
httpHeaders - The user settable file http headers.
smbProperties - The user settable file smb properties.
filePermission - The file permission of the file
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

Response containing the ShareFileInfo with headers and status code

setPropertiesWithResponse

public Response setPropertiesWithResponse(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Duration timeout, Context context)

Sets the user-defined httpHeaders to associate to the file.

If null is passed for the httpHeaders it will clear the httpHeaders associated to the file.

Code Samples

Set the httpHeaders of contentType of "text/plain"

ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
     .setContentType("text/html")
     .setContentEncoding("gzip")
     .setContentLanguage("en")
     .setCacheControl("no-transform")
     .setContentDisposition("attachment");
 FileSmbProperties smbProperties = new FileSmbProperties()
     .setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
     .setFileCreationTime(OffsetDateTime.now())
     .setFileLastWriteTime(OffsetDateTime.now())
     .setFilePermissionKey("filePermissionKey");
 String filePermission = "filePermission";
 // NOTE: filePermission and filePermissionKey should never be both set
 Response<ShareFileInfo> response = fileClient.setPropertiesWithResponse(1024, httpHeaders, smbProperties,
     filePermission, Duration.ofSeconds(1), new Context(key1, value1));
 System.out.printf("Setting the file httpHeaders completed with status code %d", response.getStatusCode());

Clear the httpHeaders of the file and preserve the SMB properties

Response<ShareFileInfo> response = fileClient.setPropertiesWithResponse(1024, null, null, null,
     Duration.ofSeconds(1), new Context(key1, value1));
 System.out.printf("Setting the file httpHeaders completed with status code %d", response.getStatusCode());

For more information, see the Azure Docs.

Parameters:

newFileSize - New file size of the file
httpHeaders - The user settable file http headers.
smbProperties - The user settable file smb properties.
filePermission - The file permission of the file
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

Response containing the ShareFileInfo with headers and status code

upload

@Deprecated
public ShareFileUploadInfo upload(InputStream data, long length)

Deprecated

Use uploadRange(InputStream data, long length) instead. Or consider upload(InputStream data, long length, ParallelTransferOptions transferOptions) 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. Value must be greater than or equal to 1.

Returns:

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. Value must be greater than or equal to 1.
transferOptions - ParallelTransferOptions for file transfer.

Returns:

uploadFromFile

public void uploadFromFile(String uploadFilePath)

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

uploadFromFile

public void uploadFromFile(String uploadFilePath, ShareRequestConditions requestConditions)

Uploads file to storage file service.

Code Samples

Upload the file from the source file path.

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 fileClient.uploadFromFile("someFilePath", requestConditions);

For more information, see the Azure Docs Create File and Azure Docs Upload.

Parameters:

uploadFilePath - The path where store the source file to upload
requestConditions - ShareRequestConditions

uploadRange

public ShareFileUploadInfo uploadRange(InputStream data, long length)

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. Value must be greater than or equal to 1.

Returns:

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:

uploadRangeFromUrlWithResponse

public Response uploadRangeFromUrlWithResponse(ShareFileUploadRangeFromUrlOptions options, 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(new ShareFileUploadRangeFromUrlOptions(6, "sourceUrl")
         .setDestinationOffset(8), Duration.ofSeconds(1), Context.NONE);
 System.out.println("Completed upload range from url!");

For more information, see the Azure Docs.

Parameters:

options - argument collection
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileUploadRangeFromUrlInfo with headers and response status code.

uploadRangeFromUrlWithResponse

public Response 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.

Code Samples

Upload a number of bytes from a file at defined source and destination offsets

ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<ShareFileUploadRangeFromUrlInfo> response = fileClient.uploadRangeFromUrlWithResponse(6, 8, 0,
     "sourceUrl", requestConditions, 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.
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileUploadRangeFromUrlInfo with headers and response status code.

uploadRangeFromUrlWithResponse

public Response 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 a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileUploadRangeFromUrlInfo with headers and response status code.

uploadRangeWithResponse

public Response uploadRangeWithResponse(ShareFileUploadRangeOptions options, Duration timeout, Context context)

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);
 Response<ShareFileUploadInfo> response = shareFileClient.uploadRangeWithResponse(
     new ShareFileUploadRangeOptions(uploadData, data.length), 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());

This method does a single Put Range operation. For more information, see the Azure Docs.

Parameters:

options - Argument collection for the upload operation.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

uploadWithResponse

public Response 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. 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);
 Response<ShareFileUploadInfo> response = shareFileAsyncClient.uploadWithResponse(
     new ShareFileUploadOptions(uploadData, data.length), 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:

options - Argument collection for the upload operation.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

uploadWithResponse

@Deprecated
public Response uploadWithResponse(InputStream data, long length, Long offset, ShareRequestConditions requestConditions, Duration timeout, Context context)

Deprecated

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);
 ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
 Response<ShareFileUploadInfo> response = fileClient.uploadWithResponse(uploadData, data.length, 0L,
     requestConditions, 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. Value must be greater than or equal to 1.
offset - Starting point of the upload range, if null it will start from the beginning.
requestConditions - ShareRequestConditions
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileUploadInfo with headers and response status code.

uploadWithResponse

@Deprecated
public Response uploadWithResponse(InputStream data, long length, Long offset, Duration timeout, Context context)

Deprecated

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. Value must be greater than or equal to 1.
offset - Starting point of the upload range, if null it will start from the beginning.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A response containing the ShareFileUploadInfo with headers and response status code.

Applies to