public class ShareFileClient extends Object
Instantiating a synchronous File Client
ShareFileClient client = new ShareFileClientBuilder() .connectionString("${connectionString}") .endpoint("${endpoint}") .buildFileClient();
View this
for additional ways to construct the client.
Modifier and Type | Method and Description |
---|---|
void |
abortCopy(String copyId)
Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.
|
com.azure.core.http.rest.Response<Void> |
abortCopyWithResponse(String copyId,
Duration timeout,
com.azure.core.util.Context context)
Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.
|
com.azure.core.http.rest.Response<Void> |
abortCopyWithResponse(String copyId,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.
|
com.azure.core.util.polling.SyncPoller<ShareFileCopyInfo,Void> |
beginCopy(String sourceUrl,
FileSmbProperties smbProperties,
String filePermission,
PermissionCopyModeType filePermissionCopyMode,
Boolean ignoreReadOnly,
Boolean setArchiveAttribute,
Map<String,String> metadata,
Duration pollInterval,
ShareRequestConditions destinationRequestConditions)
Copies a blob or file to a destination file within the storage account.
|
com.azure.core.util.polling.SyncPoller<ShareFileCopyInfo,Void> |
beginCopy(String sourceUrl,
Map<String,String> metadata,
Duration pollInterval)
Copies a blob or file to a destination file within the storage account.
|
ShareFileUploadInfo |
clearRange(long length)
Clears a range of bytes to specific of a file in storage file service.
|
com.azure.core.http.rest.Response<ShareFileUploadInfo> |
clearRangeWithResponse(long length,
long offset,
Duration timeout,
com.azure.core.util.Context context)
Clears a range of bytes to specific of a file in storage file service.
|
com.azure.core.http.rest.Response<ShareFileUploadInfo> |
clearRangeWithResponse(long length,
long offset,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Clears a range of bytes to specific of a file in storage file service.
|
ShareFileInfo |
create(long maxSize)
Creates a file in the storage account and returns a response of
ShareFileInfo to interact with it. |
com.azure.core.http.rest.Response<ShareFileInfo> |
createWithResponse(long maxSize,
ShareFileHttpHeaders httpHeaders,
FileSmbProperties smbProperties,
String filePermission,
Map<String,String> metadata,
Duration timeout,
com.azure.core.util.Context context)
Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.
|
com.azure.core.http.rest.Response<ShareFileInfo> |
createWithResponse(long maxSize,
ShareFileHttpHeaders httpHeaders,
FileSmbProperties smbProperties,
String filePermission,
Map<String,String> metadata,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.
|
void |
delete()
Deletes the file associate with the client.
|
com.azure.core.http.rest.Response<Void> |
deleteWithResponse(Duration timeout,
com.azure.core.util.Context context)
Deletes the file associate with the client.
|
com.azure.core.http.rest.Response<Void> |
deleteWithResponse(ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Deletes the file associate with the client.
|
void |
download(OutputStream stream)
Downloads a file from the system, including its metadata and properties
|
ShareFileProperties |
downloadToFile(String downloadFilePath)
Downloads a file from the system, including its metadata and properties into a file specified by the path.
|
com.azure.core.http.rest.Response<ShareFileProperties> |
downloadToFileWithResponse(String downloadFilePath,
ShareFileRange range,
Duration timeout,
com.azure.core.util.Context context)
Downloads a file from the system, including its metadata and properties into a file specified by the path.
|
com.azure.core.http.rest.Response<ShareFileProperties> |
downloadToFileWithResponse(String downloadFilePath,
ShareFileRange range,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Downloads a file from the system, including its metadata and properties into a file specified by the path.
|
ShareFileDownloadResponse |
downloadWithResponse(OutputStream stream,
ShareFileRange range,
Boolean rangeGetContentMD5,
Duration timeout,
com.azure.core.util.Context context)
Downloads a file from the system, including its metadata and properties
|
ShareFileDownloadResponse |
downloadWithResponse(OutputStream stream,
ShareFileRange range,
Boolean rangeGetContentMD5,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Downloads a file from the system, including its metadata and properties
|
Boolean |
exists()
Determines if the file this client represents exists in the cloud.
|
com.azure.core.http.rest.Response<Boolean> |
existsWithResponse(Duration timeout,
com.azure.core.util.Context context)
Determines if the file this client represents exists in the cloud.
|
CloseHandlesInfo |
forceCloseAllHandles(Duration timeout,
com.azure.core.util.Context context)
Closes all handles opened on the file at the service.
|
CloseHandlesInfo |
forceCloseHandle(String handleId)
Closes a handle on the file at the service.
|
com.azure.core.http.rest.Response<CloseHandlesInfo> |
forceCloseHandleWithResponse(String handleId,
Duration timeout,
com.azure.core.util.Context context)
Closes a handle on the file at the service.
|
String |
generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues)
Generates a service SAS for the file using the specified
ShareServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential |
String |
getAccountName()
Get associated account name.
|
StorageFileOutputStream |
getFileOutputStream()
Creates and opens an output stream to write data to the file.
|
StorageFileOutputStream |
getFileOutputStream(long offset)
Creates and opens an output stream to write data to the file.
|
String |
getFilePath()
Get file path of the client.
|
String |
getFileUrl()
Get the url of the storage file client.
|
com.azure.core.http.HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
ShareFileProperties |
getProperties()
Retrieves the properties of the storage account's file.
|
com.azure.core.http.rest.Response<ShareFileProperties> |
getPropertiesWithResponse(Duration timeout,
com.azure.core.util.Context context)
Retrieves the properties of the storage account's file.
|
com.azure.core.http.rest.Response<ShareFileProperties> |
getPropertiesWithResponse(ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Retrieves the properties of the storage account's file.
|
ShareServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
String |
getShareName()
Get the share name of file client.
|
String |
getShareSnapshotId()
Get snapshot id which attached to
ShareFileClient . |
com.azure.core.http.rest.PagedIterable<HandleItem> |
listHandles()
List of open handles on a file.
|
com.azure.core.http.rest.PagedIterable<HandleItem> |
listHandles(Integer maxResultsPerPage,
Duration timeout,
com.azure.core.util.Context context)
List of open handles on a file.
|
com.azure.core.http.rest.PagedIterable<ShareFileRange> |
listRanges()
List of valid ranges for a file.
|
com.azure.core.http.rest.PagedIterable<ShareFileRange> |
listRanges(ShareFileRange range,
Duration timeout,
com.azure.core.util.Context context)
List of valid ranges for a file.
|
com.azure.core.http.rest.PagedIterable<ShareFileRange> |
listRanges(ShareFileRange range,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
List of valid ranges for a file.
|
StorageFileInputStream |
openInputStream()
Opens a file input stream to download the file.
|
StorageFileInputStream |
openInputStream(ShareFileRange range)
Opens a file input stream to download the specified range of the file.
|
ShareFileMetadataInfo |
setMetadata(Map<String,String> metadata)
Sets the user-defined metadata to associate to the file.
|
com.azure.core.http.rest.Response<ShareFileMetadataInfo> |
setMetadataWithResponse(Map<String,String> metadata,
Duration timeout,
com.azure.core.util.Context context)
Sets the user-defined metadata to associate to the file.
|
com.azure.core.http.rest.Response<ShareFileMetadataInfo> |
setMetadataWithResponse(Map<String,String> metadata,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Sets the user-defined metadata to associate to the file.
|
ShareFileInfo |
setProperties(long newFileSize,
ShareFileHttpHeaders httpHeaders,
FileSmbProperties smbProperties,
String filePermission)
Sets the user-defined httpHeaders to associate to the file.
|
com.azure.core.http.rest.Response<ShareFileInfo> |
setPropertiesWithResponse(long newFileSize,
ShareFileHttpHeaders httpHeaders,
FileSmbProperties smbProperties,
String filePermission,
Duration timeout,
com.azure.core.util.Context context)
Sets the user-defined httpHeaders to associate to the file.
|
com.azure.core.http.rest.Response<ShareFileInfo> |
setPropertiesWithResponse(long newFileSize,
ShareFileHttpHeaders httpHeaders,
FileSmbProperties smbProperties,
String filePermission,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Sets the user-defined httpHeaders to associate to the file.
|
ShareFileUploadInfo |
upload(InputStream data,
long length)
Uploads a range of bytes to the beginning of a file in storage file service.
|
void |
uploadFromFile(String uploadFilePath)
Uploads file to storage file service.
|
void |
uploadFromFile(String uploadFilePath,
ShareRequestConditions requestConditions)
Uploads file to storage file service.
|
ShareFileUploadRangeFromUrlInfo |
uploadRangeFromUrl(long length,
long destinationOffset,
long sourceOffset,
String sourceUrl)
Uploads a range of bytes from one file to another file.
|
com.azure.core.http.rest.Response<ShareFileUploadRangeFromUrlInfo> |
uploadRangeFromUrlWithResponse(long length,
long destinationOffset,
long sourceOffset,
String sourceUrl,
Duration timeout,
com.azure.core.util.Context context)
Uploads a range of bytes from one file to another file.
|
com.azure.core.http.rest.Response<ShareFileUploadRangeFromUrlInfo> |
uploadRangeFromUrlWithResponse(long length,
long destinationOffset,
long sourceOffset,
String sourceUrl,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Uploads a range of bytes from one file to another file.
|
com.azure.core.http.rest.Response<ShareFileUploadInfo> |
uploadWithResponse(InputStream data,
long length,
Long offset,
Duration timeout,
com.azure.core.util.Context context)
Uploads a range of bytes to specific of a file in storage file service.
|
com.azure.core.http.rest.Response<ShareFileUploadInfo> |
uploadWithResponse(InputStream data,
long length,
Long offset,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Uploads a range of bytes to specific of a file in storage file service.
|
public String getFileUrl()
public ShareServiceVersion getServiceVersion()
public final StorageFileInputStream openInputStream()
InputStream
object that represents the stream to use for reading from the file.ShareStorageException
- If a storage service error occurred.public final StorageFileInputStream openInputStream(ShareFileRange range)
range
- ShareFileRange
InputStream
object that represents the stream to use for reading from the file.ShareStorageException
- If a storage service error occurred.public final StorageFileOutputStream getFileOutputStream()
StorageFileOutputStream
object used to write data to the file.ShareStorageException
- If a storage service error occurred.public final StorageFileOutputStream getFileOutputStream(long offset)
offset
- Starting point of the upload range, if null
it will start from the beginning.StorageFileOutputStream
object used to write data to the file.ShareStorageException
- If a storage service error occurred.public Boolean exists()
Code Samples
System.out.printf("Exists? %b%n", client.exists());
public com.azure.core.http.rest.Response<Boolean> existsWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
Context context = new Context("Key", "Value"); System.out.printf("Exists? %b%n", client.existsWithResponse(timeout, context).getValue());
timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.public ShareFileInfo create(long maxSize)
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.
maxSize
- The maximum size in bytes for the file.file info
ShareStorageException
- If the file has already existed, the parent directory does not exist or fileName
is an invalid resource name.public com.azure.core.http.rest.Response<ShareFileInfo> createWithResponse(long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String,String> metadata, Duration timeout, com.azure.core.util.Context context)
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.
maxSize
- The maximum size in bytes for the file.httpHeaders
- The user settable file http headers.smbProperties
- The user settable file smb properties.filePermission
- The file permission of the file.metadata
- Optional name-value pairs associated with the file as metadata.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file info
and the status of creating the file.ShareStorageException
- If the directory has already existed, the parent directory does not exist or
directory is an invalid resource name.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<ShareFileInfo> createWithResponse(long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String,String> metadata, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
maxSize
- The maximum size in bytes for the file.httpHeaders
- The user settable file http headers.smbProperties
- The user settable file smb properties.filePermission
- The file permission of the file.metadata
- Optional name-value pairs associated with the file as metadata.requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file info
and the status of creating the file.ShareStorageException
- If the directory has already existed, the parent directory does not exist or
directory is an invalid resource name.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.util.polling.SyncPoller<ShareFileCopyInfo,Void> beginCopy(String sourceUrl, Map<String,String> metadata, Duration pollInterval)
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.
sourceUrl
- Specifies the URL of the source file or blob, up to 2 KB in length.metadata
- Optional name-value pairs associated with the file as metadata. Metadata names must adhere to the
naming rules.pollInterval
- Duration between each poll for the copy status. If none is specified, a default of one second
is used.SyncPoller
to poll the progress of copy operation.public com.azure.core.util.polling.SyncPoller<ShareFileCopyInfo,Void> beginCopy(String sourceUrl, FileSmbProperties smbProperties, String filePermission, PermissionCopyModeType filePermissionCopyMode, Boolean ignoreReadOnly, Boolean setArchiveAttribute, Map<String,String> metadata, Duration pollInterval, ShareRequestConditions destinationRequestConditions)
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.
sourceUrl
- Specifies the URL of the source file or blob, up to 2 KB in length.smbProperties
- The user settable file smb properties.filePermission
- The file permission of the file.filePermissionCopyMode
- Mode of file permission acquisition.ignoreReadOnly
- Whether or not to copy despite target being read only. (default is false)setArchiveAttribute
- Whether or not the archive attribute is to be set on the target. (default is true)metadata
- Optional name-value pairs associated with the file as metadata. Metadata names must adhere to the
naming rules.pollInterval
- Duration between each poll for the copy status. If none is specified, a default of one second
is used.destinationRequestConditions
- ShareRequestConditions
SyncPoller
to poll the progress of copy operation.public void abortCopy(String copyId)
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.
copyId
- Specifies the copy id which has copying pending status associate with it.public com.azure.core.http.rest.Response<Void> abortCopyWithResponse(String copyId, Duration timeout, com.azure.core.util.Context context)
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.
copyId
- Specifies the copy id which has copying pending status associate with it.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<Void> abortCopyWithResponse(String copyId, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
copyId
- Specifies the copy id which has copying pending status associate with it.requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.RuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareFileProperties downloadToFile(String downloadFilePath)
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.
downloadFilePath
- The path where store the downloaded filepublic com.azure.core.http.rest.Response<ShareFileProperties> downloadToFileWithResponse(String downloadFilePath, ShareFileRange range, Duration timeout, com.azure.core.util.Context context)
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.
downloadFilePath
- The path where store the downloaded filerange
- Optional byte range which returns file data only from the specified range.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.public com.azure.core.http.rest.Response<ShareFileProperties> downloadToFileWithResponse(String downloadFilePath, ShareFileRange range, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
downloadFilePath
- The path where store the downloaded filerange
- Optional byte range which returns file data only from the specified range.requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.public void download(OutputStream stream)
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.
stream
- A non-null OutputStream
where the downloaded data will be written.NullPointerException
- If stream
is null
.public ShareFileDownloadResponse downloadWithResponse(OutputStream stream, ShareFileRange range, Boolean rangeGetContentMD5, Duration timeout, com.azure.core.util.Context context)
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.
stream
- A non-null OutputStream
where the downloaded data will be written.range
- Optional byte range which returns file data only from the specified range.rangeGetContentMD5
- Optional boolean which the service returns the MD5 hash for the range when it sets to
true, as long as the range is less than or equal to 4 MB in size.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.NullPointerException
- If stream
is null
.RuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareFileDownloadResponse downloadWithResponse(OutputStream stream, ShareFileRange range, Boolean rangeGetContentMD5, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
stream
- A non-null OutputStream
where the downloaded data will be written.range
- Optional byte range which returns file data only from the specified range.rangeGetContentMD5
- Optional boolean which the service returns the MD5 hash for the range when it sets to
true, as long as the range is less than or equal to 4 MB in size.requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.NullPointerException
- If stream
is null
.RuntimeException
- if the operation doesn't complete before the timeout concludes.public void delete()
Code Samples
Delete the file
fileClient.delete(); System.out.println("Complete deleting the file.");
For more information, see the Azure Docs.
ShareStorageException
- If the directory doesn't exist or the file doesn't exist.public com.azure.core.http.rest.Response<Void> deleteWithResponse(Duration timeout, com.azure.core.util.Context context)
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.
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.ShareStorageException
- If the directory doesn't exist or the file doesn't exist.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<Void> deleteWithResponse(ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.ShareStorageException
- If the directory doesn't exist or the file doesn't exist.RuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareFileProperties getProperties()
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.
Storage file properties
public com.azure.core.http.rest.Response<ShareFileProperties> getPropertiesWithResponse(Duration timeout, com.azure.core.util.Context context)
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.
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.Storage file properties
with headers and
status code.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<ShareFileProperties> getPropertiesWithResponse(ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.Storage file properties
with headers and
status code.RuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareFileInfo setProperties(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission)
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.
newFileSize
- New file size of the filehttpHeaders
- The user settable file http headers.smbProperties
- The user settable file smb properties.filePermission
- The file permission of the filefile info
IllegalArgumentException
- thrown if parameters fail the validation.public com.azure.core.http.rest.Response<ShareFileInfo> setPropertiesWithResponse(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Duration timeout, com.azure.core.util.Context context)
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.
newFileSize
- New file size of the filehttpHeaders
- The user settable file http headers.smbProperties
- The user settable file smb properties.filePermission
- The file permission of the filetimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file info
with headers and status codeIllegalArgumentException
- thrown if parameters fail the validation.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<ShareFileInfo> setPropertiesWithResponse(long newFileSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
newFileSize
- New file size of the filehttpHeaders
- The user settable file http headers.smbProperties
- The user settable file smb properties.filePermission
- The file permission of the filerequestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file info
with headers and status codeIllegalArgumentException
- thrown if parameters fail the validation.RuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareFileMetadataInfo setMetadata(Map<String,String> metadata)
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.
metadata
- Options.Metadata to set on the file, if null is passed the metadata for the file is clearedfile meta info
ShareStorageException
- If the file doesn't exist or the metadata contains invalid keyspublic com.azure.core.http.rest.Response<ShareFileMetadataInfo> setMetadataWithResponse(Map<String,String> metadata, Duration timeout, com.azure.core.util.Context context)
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.
metadata
- Options.Metadata to set on the file, if null is passed the metadata for the file is clearedtimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file meta info
with headers and status codeShareStorageException
- If the file doesn't exist or the metadata contains invalid keysRuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<ShareFileMetadataInfo> setMetadataWithResponse(Map<String,String> metadata, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
metadata
- Options.Metadata to set on the file, if null is passed the metadata for the file is clearedrequestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file meta info
with headers and status codeShareStorageException
- If the file doesn't exist or the metadata contains invalid keysRuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareFileUploadInfo upload(InputStream data, long length)
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.
data
- The data which will upload to the storage file.length
- Specifies the number of bytes being transmitted in the request body. When the
ShareFileRangeWriteType is set to clear, the value of this header must be set to zero.file upload info
ShareStorageException
- If you attempt to upload a range that is larger than 4 MB, the service returns
status code 413 (Request Entity Too Large)public com.azure.core.http.rest.Response<ShareFileUploadInfo> uploadWithResponse(InputStream data, long length, Long offset, Duration timeout, com.azure.core.util.Context context)
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.
data
- The data which will upload to the storage file.length
- Specifies the number of bytes being transmitted in the request body.offset
- Starting point of the upload range, if null
it will start from the beginning.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file upload info
with headers and response
status code.ShareStorageException
- If you attempt to upload a range that is larger than 4 MB, the service returns
status code 413 (Request Entity Too Large)RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<ShareFileUploadInfo> uploadWithResponse(InputStream data, long length, Long offset, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
data
- The data which will upload to the storage file.length
- Specifies the number of bytes being transmitted in the request body.offset
- Starting point of the upload range, if null
it will start from the beginning.requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file upload info
with headers and response
status code.ShareStorageException
- If you attempt to upload a range that is larger than 4 MB, the service returns
status code 413 (Request Entity Too Large)RuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareFileUploadRangeFromUrlInfo uploadRangeFromUrl(long length, long destinationOffset, long sourceOffset, String sourceUrl)
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.
length
- Specifies the number of bytes being transmitted in the request body.destinationOffset
- Starting point of the upload range on the destination.sourceOffset
- Starting point of the upload range on the source.sourceUrl
- Specifies the URL of the source file.file upload range from url info
public com.azure.core.http.rest.Response<ShareFileUploadRangeFromUrlInfo> uploadRangeFromUrlWithResponse(long length, long destinationOffset, long sourceOffset, String sourceUrl, Duration timeout, com.azure.core.util.Context context)
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.
length
- Specifies the number of bytes being transmitted in the request body.destinationOffset
- Starting point of the upload range on the destination.sourceOffset
- Starting point of the upload range on the source.sourceUrl
- Specifies the URL of the source file.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file upload range from url info
with
headers and response status code.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<ShareFileUploadRangeFromUrlInfo> uploadRangeFromUrlWithResponse(long length, long destinationOffset, long sourceOffset, String sourceUrl, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
length
- Specifies the number of bytes being transmitted in the request body.destinationOffset
- Starting point of the upload range on the destination.sourceOffset
- Starting point of the upload range on the source.sourceUrl
- Specifies the URL of the source file.requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file upload range from url info
with
headers and response status code.RuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareFileUploadInfo clearRange(long length)
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.
length
- Specifies the number of bytes being cleared.file upload info
public com.azure.core.http.rest.Response<ShareFileUploadInfo> clearRangeWithResponse(long length, long offset, Duration timeout, com.azure.core.util.Context context)
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.
length
- Specifies the number of bytes being transmitted in the request body.offset
- Starting point of the upload range, if null
it will start from the beginning.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file upload info
with headers and response
status code.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<ShareFileUploadInfo> clearRangeWithResponse(long length, long offset, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
length
- Specifies the number of bytes being transmitted in the request body.offset
- Starting point of the upload range, if null
it will start from the beginning.requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.file upload info
with headers and response
status code.RuntimeException
- if the operation doesn't complete before the timeout concludes.public void uploadFromFile(String uploadFilePath)
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.
uploadFilePath
- The path where store the source file to uploadpublic void uploadFromFile(String uploadFilePath, ShareRequestConditions requestConditions)
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.
uploadFilePath
- The path where store the source file to uploadrequestConditions
- ShareRequestConditions
public com.azure.core.http.rest.PagedIterable<ShareFileRange> listRanges()
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.
ranges
in the files.public com.azure.core.http.rest.PagedIterable<ShareFileRange> listRanges(ShareFileRange range, Duration timeout, com.azure.core.util.Context context)
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.
range
- Optional byte range which returns file data only from the specified range.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.ranges
in the files that satisfy the requirementsRuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.PagedIterable<ShareFileRange> listRanges(ShareFileRange range, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
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.
range
- Optional byte range which returns file data only from the specified range.requestConditions
- ShareRequestConditions
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.ranges
in the files that satisfy the requirementsRuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.PagedIterable<HandleItem> listHandles()
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.
handles
in the files that satisfy the requirementspublic com.azure.core.http.rest.PagedIterable<HandleItem> listHandles(Integer maxResultsPerPage, Duration timeout, com.azure.core.util.Context context)
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.
maxResultsPerPage
- Optional max number of results returned per pagetimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.handles
in the file that satisfy the requirementsRuntimeException
- if the operation doesn't complete before the timeout concludes.public CloseHandlesInfo forceCloseHandle(String handleId)
ShareFileClient.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.
handleId
- Handle ID to be closed.public com.azure.core.http.rest.Response<CloseHandlesInfo> forceCloseHandleWithResponse(String handleId, Duration timeout, com.azure.core.util.Context context)
ShareFileClient.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.
handleId
- Handle ID to be closed.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.public CloseHandlesInfo forceCloseAllHandles(Duration timeout, com.azure.core.util.Context context)
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.
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.public String getShareSnapshotId()
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());
DateTime
value that identifies the share snapshot to its base
share.public String getShareName()
Get the share name.
String shareName = fileClient.getShareName(); System.out.println("The share name of the directory is " + shareName);
public String getFilePath()
Get the file path.
String filePath = fileClient.getFilePath(); System.out.println("The name of the file is " + filePath);
public String getAccountName()
public com.azure.core.http.HttpPipeline getHttpPipeline()
HttpPipeline
powering this client.public String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues)
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
shareServiceSasSignatureValues
- ShareServiceSasSignatureValues
String
representing all SAS query parameters.Copyright © 2020 Microsoft Corporation. All rights reserved.