ShareFileClient Class

Definition

  • java.lang.Object
    • com.azure.storage.file.share.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.

public class ShareFileClient

Methods

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

exists()

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

Code Samples

System.out.printf("Exists? %b%n", client.exists());
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());
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.

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.

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.

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
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"));
getAccountName()

Get associated account name.

getAccountUrl()

Get the url of the storage account.

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.

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.

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);
getFileUrl()

Get the url of the storage file client.

getHttpPipeline()

Gets the HttpPipeline powering this client.

getProperties()

Retrieves the properties of the storage account's file. The properties includes 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.

getPropertiesWithResponse(ShareRequestConditions requestConditions, Duration timeout, Context context)

Retrieves the properties of the storage account's file. The properties includes 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.

getPropertiesWithResponse(Duration timeout, Context context)

Retrieves the properties of the storage account's file. The properties includes 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.

getServiceVersion()

Gets the service version the client is using.

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);
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());
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.

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.

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.

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.

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.

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.

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.

openInputStream()

Opens a file input stream to download the file.

openInputStream(ShareFileRange range)

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

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");
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");
setMetadata(Map<String,String> 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.

setMetadataWithResponse(Map<String,String> 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.

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.

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.

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.

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.

upload(InputStream data, long length)

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

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.

Deprecated. Use uploadRangeWithResponse(ShareFileUploadRangeOptions options, Duration timeout, Context context) instead. Or consider uploadWithResponse(ShareFileUploadOptions options, Duration timeout, Context context) for an upload that can handle large amounts of data.

uploadWithResponse(InputStream data, long length, Long offset, Duration timeout, Context context)

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.

Deprecated. Use uploadRangeWithResponse(ShareFileUploadRangeOptions options, Duration timeout, Context context) instead. Or consider uploadWithResponse(ShareFileUploadOptions options, Duration timeout, Context context) for an upload that can handle large amounts of data.

Inherited Members

java.lang.Object.clone() java.lang.Object.equals(java.lang.Object) java.lang.Object.finalize() java.lang.Object.getClass() java.lang.Object.hashCode() java.lang.Object.notify() java.lang.Object.notifyAll() java.lang.Object.toString() java.lang.Object.wait() java.lang.Object.wait(long) java.lang.Object.wait(long,int)

Applies to