ShareFileClient Class
- java.
lang. Object - com.
azure. storage. file. share. ShareFileClient
- com.
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
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:
abortCopyWithResponse
public Response
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:
Returns:
abortCopyWithResponse
public Response
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:
Returns:
beginCopy
public SyncPoller
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:
Returns:
beginCopy
public SyncPoller
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"));
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:
Returns:
beginCopy
public SyncPoller
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:
Returns:
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:
Returns:
clearRangeWithResponse
public Response
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:
null
it will start from the beginning.
Returns:
clearRangeWithResponse
public Response
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:
null
it will start from the beginning.
Returns:
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:
Returns:
createWithResponse
public Response
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:
Returns:
createWithResponse
public Response
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:
Returns:
createWithResponse
public Response
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:
Returns:
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
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:
Returns:
deleteWithResponse
public Response
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:
Returns:
deleteWithResponse
public Response
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:
Returns:
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:
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:
Returns:
downloadToFileWithResponse
public Response
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:
Returns:
downloadToFileWithResponse
public Response
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:
Returns:
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:
Returns:
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:
Returns:
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:
Returns:
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:
existsWithResponse
public Response
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:
Returns:
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:
Returns:
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:
Returns:
forceCloseHandleWithResponse
public Response
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:
Returns:
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:
Returns:
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:
Returns:
String
representing the SAS query parameters.generateSas
public String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Consumer
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:
Returns:
String
representing the SAS query parameters.getAccountName
public String getAccountName()
Get associated account name.
Returns:
getAccountUrl
public String getAccountUrl()
Get the url of the storage account.
Returns:
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:
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:
Returns:
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:
getFileSeekableByteChannelRead
public SeekableByteChannel getFileSeekableByteChannelRead(ShareFileSeekableByteChannelReadOptions options)
Creates and opens a SeekableByteChannel to read data from the file.
Parameters:
Returns:
getFileSeekableByteChannelWrite
public SeekableByteChannel getFileSeekableByteChannelWrite(ShareFileSeekableByteChannelWriteOptions options)
Creates and opens a SeekableByteChannel to write data to the file.
Parameters:
Returns:
getFileUrl
public String getFileUrl()
Get the url of the storage file client.
Returns:
getHttpPipeline
public HttpPipeline getHttpPipeline()
Gets the HttpPipeline powering this client.
Returns:
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
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:
Returns:
getPropertiesWithResponse
public Response
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:
Returns:
getServiceVersion
public ShareServiceVersion getServiceVersion()
Gets the service version the client is using.
Returns:
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:
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:
DateTime
value that identifies the share snapshot to its base
share.listHandles
public PagedIterable
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:
listHandles
public PagedIterable
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:
Returns:
listRanges
public PagedIterable
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:
listRanges
public PagedIterable
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:
Returns:
listRanges
public PagedIterable
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:
Returns:
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:
Returns:
listRangesDiffWithResponse
public Response
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:
Returns:
openInputStream
public final StorageFileInputStream openInputStream()
Opens a file input stream to download the file.
Returns:
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:
Returns:
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:
Returns:
renameWithResponse
public Response
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:
Returns:
setMetadata
public ShareFileMetadataInfo setMetadata(Map
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:
Returns:
setMetadataWithResponse
public Response
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:
Returns:
setMetadataWithResponse
public Response
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:
Returns:
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:
Returns:
setPropertiesWithResponse
public Response
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:
Returns:
setPropertiesWithResponse
public Response
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:
Returns:
setPropertiesWithResponse
public Response
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:
Returns:
upload
@Deprecated
public ShareFileUploadInfo upload(InputStream data, long length)
Deprecated
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:
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:
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:
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:
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:
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:
Returns:
uploadRangeFromUrlWithResponse
public Response
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:
Returns:
uploadRangeFromUrlWithResponse
public Response
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:
Returns:
uploadRangeFromUrlWithResponse
public Response
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:
Returns:
uploadRangeWithResponse
public Response
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:
Returns:
uploadWithResponse
public Response
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:
Returns:
uploadWithResponse
@Deprecated
public Response
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:
null
it will start from the beginning.
Returns:
uploadWithResponse
@Deprecated
public Response
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:
null
it will start from the beginning.
Returns:
Applies to
Azure SDK for Java