Copyright Microsoft Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
/**
* Copyright Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.azure.storage.file;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import com.microsoft.azure.storage.AccessCondition;
import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.DoesServiceRequest;
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.ResultContinuation;
import com.microsoft.azure.storage.ResultContinuationType;
import com.microsoft.azure.storage.ResultSegment;
import com.microsoft.azure.storage.StorageCredentials;
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
import com.microsoft.azure.storage.StorageErrorCodeStrings;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.StorageUri;
import com.microsoft.azure.storage.core.BaseResponse;
import com.microsoft.azure.storage.core.ExecutionEngine;
import com.microsoft.azure.storage.core.LazySegmentedIterable;
import com.microsoft.azure.storage.core.ListResponse;
import com.microsoft.azure.storage.core.ListingContext;
import com.microsoft.azure.storage.core.PathUtility;
import com.microsoft.azure.storage.core.RequestLocationMode;
import com.microsoft.azure.storage.core.SR;
import com.microsoft.azure.storage.core.SegmentedStorageRequest;
import com.microsoft.azure.storage.core.SharedAccessSignatureHelper;
import com.microsoft.azure.storage.core.StorageRequest;
import com.microsoft.azure.storage.core.Utility;
Represents a virtual directory of files.
Directories, which are encapsulated as CloudFileDirectory
objects, hold files and can also contain sub-directories.
/**
* Represents a virtual directory of files.
* <p>
* Directories, which are encapsulated as {@link CloudFileDirectory} objects, hold files and can also contain
* sub-directories.
*/
public final class CloudFileDirectory implements ListFileItem {
Holds the share reference.
/**
* Holds the share reference.
*/
private CloudFileShare share;
Represents the parent directory.
/**
* Represents the parent directory.
*/
private CloudFileDirectory parent;
Represents the File client.
/**
* Represents the File client.
*/
private CloudFileClient fileServiceClient;
Holds the list of URIs for all locations.
/**
* Holds the list of URIs for all locations.
*/
private StorageUri storageUri;
Holds the name of the directory.
/**
* Holds the name of the directory.
*/
private String name;
Represents the directory metadata.
/**
* Represents the directory metadata.
*/
private HashMap<String, String> metadata = new HashMap<String, String>();
Holds a FileDirectoryProperties object that holds the directory's system properties.
/**
* Holds a FileDirectoryProperties object that holds the directory's system properties.
*/
private FileDirectoryProperties properties = new FileDirectoryProperties();
Represents the file permission for this directory.
/**
* Represents the file permission for this directory.
*/
private String filePermission;
Creates an instance of the CloudFileDirectory
class using an absolute URI to the directory.
Params: - directoryAbsoluteUri – A
URI
that represents the file directory's address.
Throws:
/**
* Creates an instance of the <code>CloudFileDirectory</code> class using an absolute URI to the directory.
*
* @param directoryAbsoluteUri
* A {@link URI} that represents the file directory's address.
* @throws StorageException
* @throws URISyntaxException
*/
public CloudFileDirectory(final URI directoryAbsoluteUri) throws StorageException, URISyntaxException {
this(new StorageUri(directoryAbsoluteUri));
}
Creates an instance of the CloudFileDirectory
class using an absolute URI to the directory.
Params: - directoryAbsoluteUri – A
StorageUri
that represents the file directory's address.
Throws:
/**
* Creates an instance of the <code>CloudFileDirectory</code> class using an absolute URI to the directory.
*
* @param directoryAbsoluteUri
* A {@link StorageUri} that represents the file directory's address.
* @throws StorageException
* @throws URISyntaxException
*/
public CloudFileDirectory(final StorageUri directoryAbsoluteUri) throws StorageException, URISyntaxException {
this(directoryAbsoluteUri, (StorageCredentials) null);
}
Creates an instance of the CloudFileDirectory
class using an absolute URI to the directory
and credentials.
Params: - directoryAbsoluteUri – A
URI
that represents the file directory's address. - credentials – A
StorageCredentials
object used to authenticate access.
Throws:
/**
* Creates an instance of the <code>CloudFileDirectory</code> class using an absolute URI to the directory
* and credentials.
*
* @param directoryAbsoluteUri
* A {@link URI} that represents the file directory's address.
* @param credentials
* A {@link StorageCredentials} object used to authenticate access.
* @throws StorageException
* @throws URISyntaxException
*/
public CloudFileDirectory(final URI directoryAbsoluteUri, final StorageCredentials credentials)
throws StorageException, URISyntaxException {
this(new StorageUri(directoryAbsoluteUri), credentials);
}
Creates an instance of the CloudFileDirectory
class using an absolute URI to the directory
and credentials.
Params: - directoryAbsoluteUri – A
StorageUri
that represents the file directory's address. - credentials – A
StorageCredentials
object used to authenticate access.
Throws:
/**
* Creates an instance of the <code>CloudFileDirectory</code> class using an absolute URI to the directory
* and credentials.
*
* @param directoryAbsoluteUri
* A {@link StorageUri} that represents the file directory's address.
* @param credentials
* A {@link StorageCredentials} object used to authenticate access.
* @throws StorageException
* @throws URISyntaxException
*/
public CloudFileDirectory(final StorageUri directoryAbsoluteUri, final StorageCredentials credentials)
throws StorageException, URISyntaxException {
this.parseQueryAndVerify(directoryAbsoluteUri, credentials);
}
Creates an instance of the CloudFileDirectory
class using the specified address, share,
and client.
Params: - uri – A
StorageUri
that represents the file directory's address. - directoryName –
A
String
that represents the name of the directory. - share – A
CloudFileShare
object that represents the associated file share.
/**
* Creates an instance of the <code>CloudFileDirectory</code> class using the specified address, share,
* and client.
*
* @param uri
* A {@link StorageUri} that represents the file directory's address.
* @param directoryName
* A <code>String</code> that represents the name of the directory.
* @param share
* A {@link CloudFileShare} object that represents the associated file share.
*/
protected CloudFileDirectory(final StorageUri uri, final String directoryName, final CloudFileShare share) {
Utility.assertNotNull("uri", uri);
Utility.assertNotNull("directoryName", directoryName);
Utility.assertNotNull("share", share);
this.name = directoryName;
this.fileServiceClient = share.getServiceClient();
this.share = share;
this.storageUri = uri;
}
Creates the directory.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
/**
* Creates the directory.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public void create() throws StorageException, URISyntaxException {
this.create(null /* options */, null /* opContext */);
}
Creates the directory using the specified options and operation context.
Params: - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
/**
* Creates the directory using the specified options and operation context.
*
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public void create(FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
this.assertValidFilePermissionOrKey();
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
ExecutionEngine.executeWithRetry(this.fileServiceClient, this, createDirectoryImpl(options),
options.getRetryPolicyFactory(), opContext);
}
private StorageRequest<CloudFileClient, CloudFileDirectory, Void> createDirectoryImpl(
final FileRequestOptions options) {
final StorageRequest<CloudFileClient, CloudFileDirectory, Void> putRequest =
new StorageRequest<CloudFileClient, CloudFileDirectory, Void>(options, this.getStorageUri()) {
@Override
public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory directory,
OperationContext context) throws Exception {
final HttpURLConnection request = FileRequest.createDirectory(
directory.getTransformedAddress().getUri(this.getCurrentLocation()), options, context,
directory.properties, directory.filePermission);
return request;
}
@Override
public void setHeaders(HttpURLConnection connection, CloudFileDirectory directory, OperationContext context) {
FileRequest.addMetadata(connection, directory.getMetadata(), context);
}
@Override
public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context)
throws Exception {
StorageRequest.signBlobQueueAndFileRequest(connection, client, 0L, context);
}
@Override
public Void preProcessResponse(CloudFileDirectory directory, CloudFileClient client,
OperationContext context) throws Exception {
if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_CREATED) {
this.setNonExceptionedRetryableFailure(true);
return null;
}
// Set attributes
final FileDirectoryAttributes attributes = FileResponse
.getFileDirectoryAttributes(this.getConnection(), client.isUsePathStyleUris());
// Update the file SMB properties to be the file SMB properties returned in the HTTP response
FileResponse.updateDirectorySMBProperties(this.getConnection(), attributes.getProperties());
directory.filePermission = null;
directory.setProperties(attributes.getProperties());
this.getResult().setRequestServiceEncrypted(BaseResponse.isServerRequestEncrypted(this.getConnection()));
return null;
}
};
return putRequest;
}
Creates the directory if it does not exist.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
Returns: true
if the directory did not already exist and was created; otherwise, false
.
/**
* Creates the directory if it does not exist.
*
* @return <code>true</code> if the directory did not already exist and was created; otherwise, <code>false</code>.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public boolean createIfNotExists() throws StorageException, URISyntaxException {
return this.createIfNotExists(null /* options */, null /* opContext */);
}
Creates the directory if it does not exist, using the specified request options and operation context.
Params: - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client (CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
Returns: true
if the directory did not already exist and was created; otherwise, false
.
/**
* Creates the directory if it does not exist, using the specified request options and operation context.
*
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request.
* Specifying <code>null</code> will use the default request options from the associated service client
* ({@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @return <code>true</code> if the directory did not already exist and was created; otherwise, <code>false</code>.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public boolean createIfNotExists(FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException {
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
this.getShare().assertNoSnapshot();
boolean exists = this.exists(true /* primaryOnly */, null /* accessCondition */, options, opContext);
if (exists) {
return false;
}
else {
try {
this.create(options, opContext);
return true;
}
catch (StorageException e) {
if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT
&& StorageErrorCodeStrings.RESOURCE_ALREADY_EXISTS.equals(e.getErrorCode())) {
return false;
}
else {
throw e;
}
}
}
}
Deletes the directory.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
/**
* Deletes the directory.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public void delete() throws StorageException, URISyntaxException {
this.delete(null /* accessCondition */, null /* options */, null /* opContext */);
}
Deletes the directory using the specified request options and operation context.
Params: - accessCondition – An
AccessCondition
object that represents the access conditions for the directory. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
/**
* Deletes the directory using the specified request options and operation context.
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the directory.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public void delete(AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext)
throws StorageException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
ExecutionEngine.executeWithRetry(this.fileServiceClient, this, deleteDirectoryImpl(accessCondition, options),
options.getRetryPolicyFactory(), opContext);
}
private StorageRequest<CloudFileClient, CloudFileDirectory, Void> deleteDirectoryImpl(
final AccessCondition accessCondition, final FileRequestOptions options) {
final StorageRequest<CloudFileClient, CloudFileDirectory, Void> putRequest =
new StorageRequest<CloudFileClient, CloudFileDirectory, Void>(options, this.getStorageUri()) {
@Override
public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory directory,
OperationContext context) throws Exception {
return FileRequest.deleteDirectory(directory.getTransformedAddress().getUri(this.getCurrentLocation()), options, context,
accessCondition);
}
@Override
public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context)
throws Exception {
StorageRequest.signBlobQueueAndFileRequest(connection, client, -1L, context);
}
@Override
public Void preProcessResponse(CloudFileDirectory directory, CloudFileClient client,
OperationContext context) throws Exception {
if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_ACCEPTED) {
this.setNonExceptionedRetryableFailure(true);
}
return null;
}
};
return putRequest;
}
Deletes the directory if it exists.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
Returns: true
if the directory did not already exist and was created; otherwise, false
.
/**
* Deletes the directory if it exists.
*
* @return <code>true</code> if the directory did not already exist and was created; otherwise, <code>false</code>.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public boolean deleteIfExists() throws StorageException, URISyntaxException {
return this.deleteIfExists(null /* accessCondition */, null /* options */, null /* opContext */);
}
Deletes the directory if it exists using the specified request options and operation context.
Params: - accessCondition – An
AccessCondition
object that represents the access conditions for the directory. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
Returns: true
if the directory existed and was deleted; otherwise, false
.
/**
* Deletes the directory if it exists using the specified request options and operation context.
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the directory.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @return <code>true</code> if the directory existed and was deleted; otherwise, <code>false</code>.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public boolean deleteIfExists(AccessCondition accessCondition, FileRequestOptions options,
OperationContext opContext) throws StorageException, URISyntaxException {
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
boolean exists = this.exists(true /* primaryOnly */, accessCondition, options, opContext);
if (exists) {
try {
this.delete(accessCondition, options, opContext);
return true;
}
catch (StorageException e) {
if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
&& StorageErrorCodeStrings.RESOURCE_NOT_FOUND.equals(e.getErrorCode())) {
return false;
}
else {
throw e;
}
}
}
else {
return false;
}
}
Returns a value that indicates whether the directory exists.
Throws: - StorageException –
If a storage service error occurred.
Returns: true
if the directory exists, otherwise false
.
/**
* Returns a value that indicates whether the directory exists.
*
* @return <code>true</code> if the directory exists, otherwise <code>false</code>.
*
* @throws StorageException
* If a storage service error occurred.
*/
@DoesServiceRequest
public boolean exists() throws StorageException {
return this.exists(null /* accessCondition */, null /* options */, null /* opContext */);
}
Returns a value that indicates whether the directory exists, using the specified request options and operation
context.
Params: - accessCondition – An
AccessCondition
object that represents the access conditions for the share. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
Returns: true
if the directory exists, otherwise false
.
/**
* Returns a value that indicates whether the directory exists, using the specified request options and operation
* context.
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the share.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @return <code>true</code> if the directory exists, otherwise <code>false</code>.
*
* @throws StorageException
* If a storage service error occurred.
*/
@DoesServiceRequest
public boolean exists(final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext)
throws StorageException {
return this.exists(false, accessCondition, options, opContext);
}
@DoesServiceRequest
private boolean exists(final boolean primaryOnly, final AccessCondition accessCondition,
FileRequestOptions options, OperationContext opContext) throws StorageException {
if (opContext == null) {
opContext = new OperationContext();
}
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
return ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.existsImpl(primaryOnly, accessCondition, options), options.getRetryPolicyFactory(), opContext);
}
private StorageRequest<CloudFileClient, CloudFileDirectory, Boolean> existsImpl(final boolean primaryOnly,
final AccessCondition accessCondition, final FileRequestOptions options) {
final StorageRequest<CloudFileClient, CloudFileDirectory, Boolean> getRequest =
new StorageRequest<CloudFileClient, CloudFileDirectory, Boolean>(options, this.getStorageUri()) {
@Override
public void setRequestLocationMode() {
this.setRequestLocationMode(primaryOnly ? RequestLocationMode.PRIMARY_ONLY
: RequestLocationMode.PRIMARY_OR_SECONDARY);
}
@Override
public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory directory,
OperationContext context) throws Exception {
return FileRequest.getDirectoryProperties(
directory.getTransformedAddress().getUri(this.getCurrentLocation()), options, context,
accessCondition, directory.getShare().snapshotID);
}
@Override
public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context)
throws Exception {
StorageRequest.signBlobQueueAndFileRequest(connection, client, -1L, context);
}
@Override
public Boolean preProcessResponse(CloudFileDirectory directory, CloudFileClient client,
OperationContext context) throws Exception {
if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_OK) {
directory.updatePropertiesFromResponse(this.getConnection());
// Set properties
final FileDirectoryAttributes attributes =
FileResponse.getFileDirectoryAttributes(this.getConnection(), client.isUsePathStyleUris());
directory.setMetadata(attributes.getMetadata());
directory.setProperties(attributes.getProperties());
return Boolean.valueOf(true);
}
else if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
return Boolean.valueOf(false);
}
else {
this.setNonExceptionedRetryableFailure(true);
// return false instead of null to avoid SCA issues
return false;
}
}
};
return getRequest;
}
private void updatePropertiesFromResponse(HttpURLConnection request) {
// ETag
this.getProperties().setEtag(request.getHeaderField(Constants.HeaderConstants.ETAG));
// Last Modified
if (0 != request.getLastModified()) {
final Calendar lastModifiedCalendar = Calendar.getInstance(Utility.LOCALE_US);
lastModifiedCalendar.setTimeZone(Utility.UTC_ZONE);
lastModifiedCalendar.setTime(new Date(request.getLastModified()));
this.getProperties().setLastModified(lastModifiedCalendar.getTime());
}
}
Uploads the directory's metadata.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
/**
* Uploads the directory's metadata.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public void uploadMetadata() throws StorageException, URISyntaxException {
this.uploadMetadata(null /* accessCondition */, null /* options */, null /* opContext */);
}
Uploads the directory's metadata using the specified request options and operation context.
Params: - accessCondition – An
AccessCondition
object that represents the access conditions for the directory. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
/**
* Uploads the directory's metadata using the specified request options and operation context.
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the directory.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public void uploadMetadata(AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext)
throws StorageException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.uploadMetadataImpl(accessCondition, options), options.getRetryPolicyFactory(), opContext);
}
private StorageRequest<CloudFileClient, CloudFileDirectory, Void> uploadMetadataImpl(
final AccessCondition accessCondition, final FileRequestOptions options) {
final StorageRequest<CloudFileClient, CloudFileDirectory, Void> putRequest =
new StorageRequest<CloudFileClient, CloudFileDirectory, Void>(
options, this.getStorageUri()) {
@Override
public HttpURLConnection buildRequest(
CloudFileClient client, CloudFileDirectory directory, OperationContext context) throws Exception {
return FileRequest.setDirectoryMetadata(directory.getTransformedAddress().getUri(this.getCurrentLocation()),
options, context, accessCondition);
}
@Override
public void setHeaders(HttpURLConnection connection, CloudFileDirectory directory, OperationContext context) {
FileRequest.addMetadata(connection, directory.getMetadata(), context);
}
@Override
public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context)
throws Exception {
StorageRequest.signBlobQueueAndFileRequest(connection, client, 0L, context);
}
@Override
public Void preProcessResponse(CloudFileDirectory directory, CloudFileClient client, OperationContext context)
throws Exception {
if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) {
this.setNonExceptionedRetryableFailure(true);
}
directory.updatePropertiesFromResponse(this.getConnection());
this.getResult().setRequestServiceEncrypted(BaseResponse.isServerRequestEncrypted(this.getConnection()));
return null;
}
};
return putRequest;
}
Uploads the directory's properties to the storage service.
Use downloadAttributes
to retrieve the latest values for the directory's properties and metadata from the Microsoft Azure storage service.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
/**
* Uploads the directory's properties to the storage service.
* <p>
* Use {@link CloudFileDirectory#downloadAttributes} to retrieve the latest values for the directory's properties
* and metadata from the Microsoft Azure storage service.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public final void uploadProperties() throws StorageException, URISyntaxException {
this.uploadProperties(null /* accessCondition */, null /* options */, null /*opContext */);
}
Uploads the directory's properties using the access condition, request options, and operation context.
Use downloadAttributes
to retrieve the latest values for the directory's properties and metadata from the Microsoft Azure storage service.
Params: - accessCondition – An
AccessCondition
object that represents the access conditions for the directory. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
/**
* Uploads the directory's properties using the access condition, request options, and operation context.
* <p>
* Use {@link CloudFileDirectory#downloadAttributes} to retrieve the latest values for the directory's properties
* and metadata from the Microsoft Azure storage service.
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the directory.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
@DoesServiceRequest
public final void uploadProperties(final AccessCondition accessCondition, FileRequestOptions options,
OperationContext opContext) throws StorageException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
this.assertValidFilePermissionOrKey();
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.uploadPropertiesImpl(accessCondition, options), options.getRetryPolicyFactory(), opContext);
}
private StorageRequest<CloudFileClient, CloudFileDirectory, Void> uploadPropertiesImpl(
final AccessCondition accessCondition, final FileRequestOptions options) {
final StorageRequest<CloudFileClient, CloudFileDirectory, Void> putRequest =
new StorageRequest<CloudFileClient, CloudFileDirectory, Void>(
options, this.getStorageUri()) {
@Override
public HttpURLConnection buildRequest(
CloudFileClient client, CloudFileDirectory directory, OperationContext context) throws Exception {
return FileRequest.setDirectoryProperties(directory.getTransformedAddress().getUri(this.getCurrentLocation()),
options, context, accessCondition, directory.properties, directory.filePermission);
}
@Override
public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context)
throws Exception {
StorageRequest.signBlobQueueAndFileRequest(connection, client, 0L, context);
}
@Override
public Void preProcessResponse(CloudFileDirectory directory, CloudFileClient client, OperationContext context)
throws Exception {
if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) {
this.setNonExceptionedRetryableFailure(true);
return null;
}
// Update the file SMB properties to be the file SMB properties returned in the HTTP response
FileResponse.updateDirectorySMBProperties(this.getConnection(), directory.properties);
directory.filePermission = null;
this.getResult().setRequestServiceEncrypted(BaseResponse.isServerRequestEncrypted(this.getConnection()));
return null;
}
};
return putRequest;
}
Downloads the directory's properties.
Throws: - StorageException –
If a storage service error occurred.
/**
* Downloads the directory's properties.
*
* @throws StorageException
* If a storage service error occurred.
*/
@DoesServiceRequest
public void downloadAttributes() throws StorageException {
this.downloadAttributes(null /* accessCondition */, null /* options */, null /* opContext */);
}
Downloads the directory's properties using the specified request options and operation context.
Params: - accessCondition – An
AccessCondition
object that represents the access conditions for the directory. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
/**
* Downloads the directory's properties using the specified request options and operation context.
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the directory.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @throws StorageException
* If a storage service error occurred.
*/
@DoesServiceRequest
public void downloadAttributes(AccessCondition accessCondition, FileRequestOptions options,
OperationContext opContext) throws StorageException {
if (opContext == null) {
opContext = new OperationContext();
}
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.downloadAttributesImpl(accessCondition, options), options.getRetryPolicyFactory(), opContext);
}
private StorageRequest<CloudFileClient, CloudFileDirectory, Void> downloadAttributesImpl(
final AccessCondition accessCondition, final FileRequestOptions options) {
final StorageRequest<CloudFileClient, CloudFileDirectory, Void> getRequest =
new StorageRequest<CloudFileClient, CloudFileDirectory, Void>(options, this.getStorageUri()) {
@Override
public void setRequestLocationMode() {
this.setRequestLocationMode(RequestLocationMode.PRIMARY_OR_SECONDARY);
}
@Override
public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory directory,
OperationContext context) throws Exception {
return FileRequest.getDirectoryProperties(
directory.getTransformedAddress().getUri(this.getCurrentLocation()), options, context,
accessCondition, directory.getShare().snapshotID);
}
@Override
public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context)
throws Exception {
StorageRequest.signBlobQueueAndFileRequest(connection, client, -1L, context);
}
@Override
public Void preProcessResponse(CloudFileDirectory directory, CloudFileClient client,
OperationContext context) throws Exception {
if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) {
this.setNonExceptionedRetryableFailure(true);
return null;
}
// Set properties
final FileDirectoryAttributes attributes =
FileResponse.getFileDirectoryAttributes(this.getConnection(), client.isUsePathStyleUris());
directory.setMetadata(attributes.getMetadata());
// Update the file SMB properties to be the file SMB properties returned in the HTTP response
FileResponse.updateDirectorySMBProperties(this.getConnection(), attributes.getProperties());
directory.setProperties(attributes.getProperties());
return null;
}
};
return getRequest;
}
Returns an enumerable collection of file and directory items for the directory.
Returns: An enumerable collection of ListFileItem
objects that represent the file and directory items in this directory.
/**
* Returns an enumerable collection of file and directory items for the directory.
*
* @return An enumerable collection of {@link ListFileItem} objects that represent the file and directory items in
* this directory.
*/
@DoesServiceRequest
public Iterable<ListFileItem> listFilesAndDirectories() {
return this.listFilesAndDirectories(null /* prefix */, null /* options */, null /* opContext */);
}
Returns an enumerable collection of file and directory items for the directory.
Params: - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Returns: An enumerable collection of ListFileItem
objects that represent the file and directory items in this directory.
/**
* Returns an enumerable collection of file and directory items for the directory.
*
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @return An enumerable collection of {@link ListFileItem} objects that represent the file and directory items in
* this directory.
*/
@DoesServiceRequest
public Iterable<ListFileItem> listFilesAndDirectories(FileRequestOptions options, OperationContext opContext) {
return listFilesAndDirectories(null /* prefix */, options, opContext);
}
Returns an enumerable collection of file and directory items for the directory.
Params: - prefix –
A string containing the file or directory name prefix.
- options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Returns: An enumerable collection of ListFileItem
objects that represent the file and directory items in this directory.
/**
* Returns an enumerable collection of file and directory items for the directory.
*
* @param prefix
* A string containing the file or directory name prefix.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @return An enumerable collection of {@link ListFileItem} objects that represent the file and directory items in
* this directory.
*/
@DoesServiceRequest
public Iterable<ListFileItem> listFilesAndDirectories(
String prefix, FileRequestOptions options, OperationContext opContext) {
if (opContext == null) {
opContext = new OperationContext();
}
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
SegmentedStorageRequest segmentedRequest = new SegmentedStorageRequest();
return new LazySegmentedIterable<CloudFileClient, CloudFileDirectory, ListFileItem>(
this.listFilesAndDirectoriesSegmentedImpl(prefix, null /* maxResults */, options, segmentedRequest),
this.fileServiceClient, this,
options.getRetryPolicyFactory(), opContext);
}
Returns a result segment of an enumerable collection of files and directories for this File service client.
Throws: Returns: A ResultSegment
object that contains a segment of the enumerable collection of ListFileItem
objects that represent the files and directories.
/**
* Returns a result segment of an enumerable collection of files and directories for this File service client.
*
* @return A {@link ResultSegment} object that contains a segment of the enumerable collection of
* {@link ListFileItem} objects that represent the files and directories.
* @throws StorageException
*/
@DoesServiceRequest
public ResultSegment<ListFileItem> listFilesAndDirectoriesSegmented() throws StorageException {
return this.listFilesAndDirectoriesSegmented(null /* prefix */, null /* maxResults */,
null /* continuationToken */, null /* options */, null /* opContext */);
}
Returns a result segment of an enumerable collection of files and directories for this directory, using the
specified listing details options, request options, and operation context.
Params: - maxResults –
The maximum number of results to retrieve. If
null
or greater
than 5000, the server will return up to 5,000 items. Must be at least 1. - continuationToken – A
ResultContinuation
object that represents a continuation token returned by a previous listing operation. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
Returns: A ResultSegment
object that contains a segment of the enumerable collection of ListFileItem
objects that represent the files and directories in this directory.
/**
* Returns a result segment of an enumerable collection of files and directories for this directory, using the
* specified listing details options, request options, and operation context.
*
* @param maxResults
* The maximum number of results to retrieve. If <code>null</code> or greater
* than 5000, the server will return up to 5,000 items. Must be at least 1.
* @param continuationToken
* A {@link ResultContinuation} object that represents a continuation token
* returned by a previous listing operation.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for
* the request. Specifying <code>null</code> will use the default request options
* from the associated service client ( {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current
* operation. This object is used to track requests to the storage service,
* and to provide additional runtime information about the operation.
*
* @return A {@link ResultSegment} object that contains a segment of the enumerable collection of
* {@link ListFileItem} objects that represent the files and directories in this directory.
*
* @throws StorageException
* If a storage service error occurred.
*/
@DoesServiceRequest
public ResultSegment<ListFileItem> listFilesAndDirectoriesSegmented(final Integer maxResults,
final ResultContinuation continuationToken, FileRequestOptions options, OperationContext opContext)
throws StorageException {
return listFilesAndDirectoriesSegmented(null, maxResults, continuationToken, options, opContext);
}
Returns a result segment of an enumerable collection of files and directories for this directory, using the
specified listing details options, request options, and operation context.
Params: - prefix –
A string containing the file or directory name prefix.
- maxResults –
The maximum number of results to retrieve. If
null
or greater
than 5000, the server will return up to 5,000 items. Must be at least 1. - continuationToken – A
ResultContinuation
object that represents a continuation token returned by a previous listing operation. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: - StorageException –
If a storage service error occurred.
Returns: A ResultSegment
object that contains a segment of the enumerable collection of ListFileItem
objects that represent the files and directories in this directory.
/**
* Returns a result segment of an enumerable collection of files and directories for this directory, using the
* specified listing details options, request options, and operation context.
*
* @param prefix
* A string containing the file or directory name prefix.
* @param maxResults
* The maximum number of results to retrieve. If <code>null</code> or greater
* than 5000, the server will return up to 5,000 items. Must be at least 1.
* @param continuationToken
* A {@link ResultContinuation} object that represents a continuation token
* returned by a previous listing operation.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for
* the request. Specifying <code>null</code> will use the default request options
* from the associated service client ( {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current
* operation. This object is used to track requests to the storage service,
* and to provide additional runtime information about the operation.
*
* @return A {@link ResultSegment} object that contains a segment of the enumerable collection of
* {@link ListFileItem} objects that represent the files and directories in this directory.
*
* @throws StorageException
* If a storage service error occurred.
*/
@DoesServiceRequest
public ResultSegment<ListFileItem> listFilesAndDirectoriesSegmented(final String prefix, final Integer maxResults,
final ResultContinuation continuationToken, FileRequestOptions options, OperationContext opContext)
throws StorageException {
if (opContext == null) {
opContext = new OperationContext();
}
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
Utility.assertContinuationType(continuationToken, ResultContinuationType.FILE);
SegmentedStorageRequest segmentedRequest = new SegmentedStorageRequest();
segmentedRequest.setToken(continuationToken);
return ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.listFilesAndDirectoriesSegmentedImpl(prefix, maxResults, options, segmentedRequest),
options.getRetryPolicyFactory(), opContext);
}
private StorageRequest<CloudFileClient, CloudFileDirectory, ResultSegment<ListFileItem>> listFilesAndDirectoriesSegmentedImpl(
final String prefix, final Integer maxResults, final FileRequestOptions options, final SegmentedStorageRequest segmentedRequest) {
Utility.assertContinuationType(segmentedRequest.getToken(), ResultContinuationType.FILE);
final ListingContext listingContext = new ListingContext(prefix, maxResults);
final StorageRequest<CloudFileClient, CloudFileDirectory, ResultSegment<ListFileItem>> getRequest =
new StorageRequest<CloudFileClient, CloudFileDirectory, ResultSegment<ListFileItem>>(
options, this.getStorageUri()) {
@Override
public void setRequestLocationMode() {
this.setRequestLocationMode(Utility.getListingLocationMode(segmentedRequest.getToken()));
}
@Override
public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory directory,
OperationContext context) throws Exception {
listingContext.setMarker(segmentedRequest.getToken() != null ? segmentedRequest.getToken()
.getNextMarker() : null);
return FileRequest.listFilesAndDirectories(
directory.getTransformedAddress().getUri(this.getCurrentLocation()),
options, context, listingContext, directory.getShare().snapshotID);
}
@Override
public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context)
throws Exception {
StorageRequest.signBlobQueueAndFileRequest(connection, client, -1L, context);
}
@Override
public ResultSegment<ListFileItem> preProcessResponse(CloudFileDirectory directory, CloudFileClient client,
OperationContext context) throws Exception {
if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) {
this.setNonExceptionedRetryableFailure(true);
}
return null;
}
@Override
public ResultSegment<ListFileItem> postProcessResponse(HttpURLConnection connection,
CloudFileDirectory directory, CloudFileClient client, OperationContext context,
ResultSegment<ListFileItem> storageObject) throws Exception {
final ListResponse<ListFileItem> response = FileListHandler.getFileAndDirectoryList(this
.getConnection().getInputStream(), directory);
ResultContinuation newToken = null;
if (response.getNextMarker() != null) {
newToken = new ResultContinuation();
newToken.setNextMarker(response.getNextMarker());
newToken.setContinuationType(ResultContinuationType.FILE);
newToken.setTargetLocation(this.getResult().getTargetLocation());
}
final ResultSegment<ListFileItem> resSegment = new ResultSegment<ListFileItem>(response.getResults(),
response.getMaxResults(), newToken);
// Important for listFilesAndDirectories because this is required by the lazy iterator between executions.
segmentedRequest.setToken(resSegment.getContinuationToken());
return resSegment;
}
};
return getRequest;
}
Gets the SMB handles open on this file.
Returns: An Iterable
of the handles that will lazily request new segments.
/**
* Gets the SMB handles open on this file.
*
* @return An {@code Iterable} of the handles that will lazily request new segments.
*/
@DoesServiceRequest
public Iterable<FileHandle> listHandles() {
return this.listHandles(false, null, null);
}
Gets the SMB handles open on this file.
Params: - recursive –
Specifies if operation should apply to the directory specified in the URI, its files, its
subdirectories and their files.
- options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object which represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Returns: An Iterable
of the handles that will lazily request new segments.
/**
* Gets the SMB handles open on this file.
*
* @param recursive
* Specifies if operation should apply to the directory specified in the URI, its files, its
* subdirectories and their files.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object which represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
* @return An {@code Iterable} of the handles that will lazily request new segments.
*/
@DoesServiceRequest
public Iterable<FileHandle> listHandles(boolean recursive, FileRequestOptions options, OperationContext opContext) {
if (opContext == null) {
opContext = new OperationContext();
}
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
SegmentedStorageRequest segmentedRequest = new SegmentedStorageRequest();
return new LazySegmentedIterable<CloudFileClient, CloudFileDirectory, FileHandle>(
this.listHandlesSegmentedImpl( null /* maxResults */, false, options, segmentedRequest),
this.fileServiceClient, this, options.getRetryPolicyFactory(), opContext);
}
Gets the SMB handles open on this file.
Throws: Returns: A ResultSegment
object that contains a segment of the enumerable collection of ListFileItem
objects that represent the files and directories.
/**
* Gets the SMB handles open on this file.
*
* @return A {@link ResultSegment} object that contains a segment of the enumerable collection of
* {@link ListFileItem} objects that represent the files and directories.
* @throws StorageException
*/
@DoesServiceRequest
public ResultSegment<FileHandle> listHandlesSegmented() throws StorageException {
return this.listHandlesSegmented(null, false, null, null, null);
}
Gets the SMB handles open on this file.
Params: - maxResults –
The maximum number of results to retrieve. If
null
or greater
than 5000, the server will return up to 5,000 items. Must be at least 1. - recursive –
Specifies if operation should apply to the directory specified in the URI, its files, its
subdirectories and their files.
- continuationToken – A
ResultContinuation
object that represents a continuation token returned by a previous listing operation. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object which represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: Returns: A ResultSegment
object that contains a segment of the enumerable collection of ListFileItem
objects that represent the files and directories.
/**
* Gets the SMB handles open on this file.
*
* @param maxResults
* The maximum number of results to retrieve. If <code>null</code> or greater
* than 5000, the server will return up to 5,000 items. Must be at least 1.
* @param recursive
* Specifies if operation should apply to the directory specified in the URI, its files, its
* subdirectories and their files.
* @param continuationToken
* A {@link ResultContinuation} object that represents a continuation token
* returned by a previous listing operation.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object which represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
* @return A {@link ResultSegment} object that contains a segment of the enumerable collection of
* {@link ListFileItem} objects that represent the files and directories.
* @throws StorageException
*/
@DoesServiceRequest
public ResultSegment<FileHandle> listHandlesSegmented(final Integer maxResults, final boolean recursive,
final ResultContinuation continuationToken, FileRequestOptions options, OperationContext opContext)
throws StorageException {
if (opContext == null) {
opContext = new OperationContext();
}
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
Utility.assertContinuationType(continuationToken, ResultContinuationType.HANDLE);
SegmentedStorageRequest segmentedRequest = new SegmentedStorageRequest();
segmentedRequest.setToken(continuationToken);
return ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.listHandlesSegmentedImpl(maxResults, recursive, options, segmentedRequest),
options.getRetryPolicyFactory(), opContext);
}
private StorageRequest<CloudFileClient, CloudFileDirectory, ResultSegment<FileHandle>> listHandlesSegmentedImpl(
final Integer maxResults, final boolean recursive, final FileRequestOptions options,
final SegmentedStorageRequest segmentedRequest) {
Utility.assertContinuationType(segmentedRequest.getToken(), ResultContinuationType.HANDLE);
final ListingContext listingContext = new ListingContext(null, maxResults);
final StorageRequest<CloudFileClient, CloudFileDirectory, ResultSegment<FileHandle>> getRequest =
new StorageRequest<CloudFileClient, CloudFileDirectory, ResultSegment<FileHandle>>(
options, this.getStorageUri()) {
@Override
public void setRequestLocationMode() {
this.setRequestLocationMode(Utility.getListingLocationMode(segmentedRequest.getToken()));
}
@Override
public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory directory,
OperationContext context) throws Exception {
listingContext.setMarker(segmentedRequest.getToken() != null ? segmentedRequest.getToken()
.getNextMarker() : null);
return FileRequest.listHandles(
directory.getTransformedAddress().getUri(this.getCurrentLocation()),
options, context, listingContext, recursive, directory.getShare().snapshotID);
}
@Override
public void signRequest(HttpURLConnection connection, CloudFileClient client,
OperationContext context) throws Exception {
StorageRequest.signBlobQueueAndFileRequest(connection, client, -1L, context);
}
@Override
public ResultSegment<FileHandle> preProcessResponse(CloudFileDirectory directory,
CloudFileClient client, OperationContext context) throws Exception {
if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) {
this.setNonExceptionedRetryableFailure(true);
}
return null;
}
@Override
public ResultSegment<FileHandle> postProcessResponse(HttpURLConnection connection,
CloudFileDirectory directory, CloudFileClient client, OperationContext context,
ResultSegment<FileHandle> storageObject) throws Exception {
final ListResponse<FileHandle> response = HandleListHandler.getHandleList(this
.getConnection().getInputStream());
ResultContinuation newToken = null;
if (response.getNextMarker() != null) {
newToken = new ResultContinuation();
newToken.setNextMarker(response.getNextMarker());
newToken.setContinuationType(ResultContinuationType.HANDLE);
newToken.setTargetLocation(this.getResult().getTargetLocation());
}
final ResultSegment<FileHandle> resSegment =
new ResultSegment<FileHandle>(response.getResults(),
response.getMaxResults(), newToken);
// Important for listFilesAndDirectories because this is required by the lazy iterator between executions.
segmentedRequest.setToken(resSegment.getContinuationToken());
return resSegment;
}
};
return getRequest;
}
Close all SMB handles on this file.
Throws: Returns: A ResultSegment
which has one element which is the number of handles closed and a continuation to follow in case the operation took too long to be completed atomically.
/**
* Close all SMB handles on this file.
*
* @return A {@link ResultSegment} which has one element which is the number of handles closed and a
* continuation to follow in case the operation took too long to be completed atomically.
* @throws StorageException
*/
public ResultSegment<Integer> closeAllHandlesSegmented() throws StorageException {
return this.closeAllHandlesSegmented(null, false, null, null);
}
Close all SMB handles on this file.
Params: - continuationToken – A
ResultContinuation
object that represents a continuation token returned by a previous listing operation. - recursive –
Specifies if operation should apply to the directory specified in the URI, its files, its
subdirectories and their files.
- options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object which represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: Returns: A ResultSegment
which has one element which is the number of handles closed and a continuation to follow in case the operation took too long to be completed atomically.
/**
* Close all SMB handles on this file.
*
* @param continuationToken
* A {@link ResultContinuation} object that represents a continuation token
* returned by a previous listing operation.
* @param recursive
* Specifies if operation should apply to the directory specified in the URI, its files, its
* subdirectories and their files.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object which represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @return A {@link ResultSegment} which has one element which is the number of handles closed and a
* continuation to follow in case the operation took too long to be completed atomically.
* @throws StorageException
*/
public ResultSegment<Integer> closeAllHandlesSegmented(final ResultContinuation continuationToken,
boolean recursive, FileRequestOptions options, OperationContext opContext) throws StorageException {
if (opContext == null) {
opContext = new OperationContext();
}
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
Utility.assertContinuationType(continuationToken, ResultContinuationType.HANDLE);
SegmentedStorageRequest segmentedRequest = new SegmentedStorageRequest();
segmentedRequest.setToken(continuationToken);
return ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.closeHandlesSegmentedImpl(FileConstants.ALL_HANDLES, recursive, options, segmentedRequest),
options.getRetryPolicyFactory(), opContext);
}
Close all SMB handles on this file.
Params: - handleID –
The handle to close.
Throws: Returns: A ResultSegment
which has one element which is the number of handles closed and a continuation to follow in case the operation took too long to be completed atomically.
/**
* Close all SMB handles on this file.
*
* @param handleID
* The handle to close.
*
* @return A {@link ResultSegment} which has one element which is the number of handles closed and a
* continuation to follow in case the operation took too long to be completed atomically.
* @throws StorageException
*/
public ResultSegment<Integer> closeHandleSegmented(String handleID) throws StorageException {
return this.closeHandleSegmented(handleID, null, null, null);
}
Close all SMB handles on this file.
Params: - handleID –
The handle to close.
- continuationToken – A
ResultContinuation
object that represents a continuation token returned by a previous listing operation. - options – A
FileRequestOptions
object that specifies any additional options for the request. Specifying null
will use the default request options from the associated service client ( CloudFileClient
). - opContext – An
OperationContext
object which represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.
Throws: Returns: A ResultSegment
which has one element which is the number of handles closed and a continuation to follow in case the operation took too long to be completed atomically.
/**
* Close all SMB handles on this file.
*
* @param handleID
* The handle to close.
* @param continuationToken
* A {@link ResultContinuation} object that represents a continuation token
* returned by a previous listing operation.
* @param options
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client (
* {@link CloudFileClient}).
* @param opContext
* An {@link OperationContext} object which represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
* @return A {@link ResultSegment} which has one element which is the number of handles closed and a
* continuation to follow in case the operation took too long to be completed atomically.
* @throws StorageException
*/
public ResultSegment<Integer> closeHandleSegmented(String handleID, ResultContinuation continuationToken,
FileRequestOptions options, OperationContext opContext) throws StorageException {
Utility.assertNotNull("handleID", handleID);
if (opContext == null) {
opContext = new OperationContext();
}
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
Utility.assertContinuationType(continuationToken, ResultContinuationType.HANDLE);
SegmentedStorageRequest segmentedRequest = new SegmentedStorageRequest();
segmentedRequest.setToken(continuationToken);
return ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.closeHandlesSegmentedImpl(handleID, false, options, segmentedRequest),
options.getRetryPolicyFactory(), opContext);
}
private StorageRequest<CloudFileClient, CloudFileDirectory, ResultSegment<Integer>> closeHandlesSegmentedImpl(
final String handleID, final boolean recursive, final FileRequestOptions options,
final SegmentedStorageRequest segmentedRequest) {
Utility.assertContinuationType(segmentedRequest.getToken(), ResultContinuationType.HANDLE);
final ListingContext listingContext = new ListingContext(null, null);
final StorageRequest<CloudFileClient, CloudFileDirectory, ResultSegment<Integer>> putRequest =
new StorageRequest<CloudFileClient, CloudFileDirectory, ResultSegment<Integer>>(
options, this.getStorageUri()) {
@Override
public void setRequestLocationMode() {
this.setRequestLocationMode(Utility.getListingLocationMode(segmentedRequest.getToken()));
}
@Override
public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory directory,
OperationContext context) throws Exception {
listingContext.setMarker(segmentedRequest.getToken() != null ? segmentedRequest.getToken()
.getNextMarker() : null);
return FileRequest.closeHandles(
directory.getTransformedAddress().getUri(this.getCurrentLocation()),
options, context, listingContext, handleID, recursive, directory.getShare().snapshotID);
}
@Override
public void signRequest(HttpURLConnection connection, CloudFileClient client,
OperationContext context) throws Exception {
StorageRequest.signBlobQueueAndFileRequest(connection, client, -1L, context);
}
@Override
public ResultSegment<Integer> preProcessResponse(CloudFileDirectory directory,
CloudFileClient client, OperationContext context) throws Exception {
if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) {
this.setNonExceptionedRetryableFailure(true);
}
return null;
}
@Override
public ResultSegment<Integer> postProcessResponse(HttpURLConnection connection,
CloudFileDirectory directory, CloudFileClient client, OperationContext context,
ResultSegment<Integer> storageObject) throws Exception {
final ListResponse<Integer> response = new ListResponse<>();
ResultContinuation newToken = null;
if (response.getNextMarker() != null) {
newToken = new ResultContinuation();
newToken.setNextMarker(response.getNextMarker());
newToken.setContinuationType(ResultContinuationType.HANDLE_CLOSE);
newToken.setTargetLocation(this.getResult().getTargetLocation());
}
final ResultSegment<Integer> resSegment =
new ResultSegment<>(response.getResults(), response.getMaxResults(), newToken);
// Important for listFilesAndDirectories because this is required by the lazy iterator between executions.
segmentedRequest.setToken(resSegment.getContinuationToken());
resSegment.getResults().add(Integer.getInteger(
connection.getRequestProperty(FileConstants.NUMBER_OF_HANDLES_CLOSED)));
return resSegment;
}
};
return putRequest;
}
Returns a reference to a CloudFile
object that represents a file in this directory. Params: - fileName –
A
String
that represents the name of the file.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
If the resource URI is invalid.
Returns: A CloudFile
object that represents a reference to the specified file.
/**
* Returns a reference to a {@link CloudFile} object that represents a file in this directory.
*
* @param fileName
* A <code>String</code> that represents the name of the file.
*
* @return A {@link CloudFile} object that represents a reference to the specified file.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
* If the resource URI is invalid.
*/
public CloudFile getFileReference(final String fileName) throws URISyntaxException, StorageException {
Utility.assertNotNullOrEmpty("fileName", fileName);
StorageUri subdirectoryUri = PathUtility.appendPathToUri(this.storageUri, fileName);
return new CloudFile(subdirectoryUri, fileName, this.getShare());
}
Returns a reference to a CloudFileDirectory
object that represents a directory in this directory. Params: - itemName –
A
String
that represents the name of the directory.
Throws: - URISyntaxException –
If the resource URI is invalid.
- StorageException –
Returns: A CloudFileDirectory
object that represents a reference to the specified directory.
/**
* Returns a reference to a {@link CloudFileDirectory} object that represents a directory in this directory.
*
* @param itemName
* A <code>String</code> that represents the name of the directory.
*
* @return A {@link CloudFileDirectory} object that represents a reference to the specified directory.
*
* @throws URISyntaxException
* If the resource URI is invalid.
* @throws StorageException
*/
public CloudFileDirectory getDirectoryReference(final String itemName) throws URISyntaxException,
StorageException {
Utility.assertNotNullOrEmpty("itemName", itemName);
StorageUri subdirectoryUri = PathUtility.appendPathToUri(this.storageUri, itemName);
return new CloudFileDirectory(subdirectoryUri, itemName, this.getShare());
}
Returns the URI for this directory.
Returns: A java.net.URI
object that represents the URI for this directory.
/**
* Returns the URI for this directory.
*
* @return A <code>java.net.URI</code> object that represents the URI for this directory.
*/
@Override
public URI getUri() {
return this.storageUri.getPrimaryUri();
}
Returns the list of URIs for all locations.
Returns: A StorageUri
that represents the list of URIs for all locations.
/**
* Returns the list of URIs for all locations.
*
* @return A {@link StorageUri} that represents the list of URIs for all locations.
*/
@Override
public final StorageUri getStorageUri() {
return this.storageUri;
}
Returns the File service client associated with this directory.
Returns: An CloudFileClient
object that represents the service client associated with the directory.
/**
* Returns the File service client associated with this directory.
*
* @return An {@link CloudFileClient} object that represents the service client associated with the directory.
*/
public CloudFileClient getServiceClient() {
return this.fileServiceClient;
}
Returns the name of this directory.
Returns: An String
that represents the name of the directory.
/**
* Returns the name of this directory.
*
* @return An <code>String</code> that represents the name of the directory.
*/
public String getName() {
return this.name;
}
Returns the metadata for the directory. This value is initialized with the metadata from the directory by a call to downloadAttributes
, and is set on the directory with a call to uploadMetadata
. Returns: A java.util.HashMap
object that represents the metadata for the directory.
/**
* Returns the metadata for the directory. This value is initialized with the metadata from the directory
* by a call to {@link #downloadAttributes}, and is set on the directory with a call to {@link #uploadMetadata}.
*
* @return A <code>java.util.HashMap</code> object that represents the metadata for the directory.
*/
public HashMap<String, String> getMetadata() {
return this.metadata;
}
Returns the FileDirectoryProperties
object that holds the directory's system properties. Returns: A FileDirectoryProperties
object that holds the system properties associated with the directory.
/**
* Returns the {@link FileDirectoryProperties} object that holds the directory's system properties.
*
* @return A {@link FileDirectoryProperties} object that holds the system properties associated with the
* directory.
*/
public FileDirectoryProperties getProperties() {
return this.properties;
}
Returns the CloudFileDirectory
parent directory associated with this directory. Throws: Returns: An CloudFileDirectory
object that represents the parent directory associated with the directory.
/**
* Returns the {@link CloudFileDirectory} parent directory associated with this directory.
*
* @return An {@link CloudFileDirectory} object that represents the parent directory associated with the directory.
* @throws StorageException
* @throws URISyntaxException
*/
@Override
public CloudFileDirectory getParent() throws URISyntaxException, StorageException {
if (this.parent == null) {
final String parentName = CloudFile.getParentNameFromURI(this.getStorageUri(), this.getShare());
if (parentName != null) {
StorageUri parentURI = PathUtility.appendPathToUri(this.getShare().getStorageUri(), parentName);
this.parent = new CloudFileDirectory(parentURI, this.getServiceClient().getCredentials());
}
}
return this.parent;
}
Returns the share for this directory.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
If the resource URI is invalid.
Returns: A CloudFileShare
that represents the share for this directory.
/**
* Returns the share for this directory.
*
* @return A {@link CloudFileShare} that represents the share for this directory.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
* If the resource URI is invalid.
*/
@Override
public CloudFileShare getShare() throws StorageException, URISyntaxException {
if (this.share == null) {
this.share = this.fileServiceClient.getShareReference(PathUtility.getShareNameFromUri(this.getUri(),
this.fileServiceClient.isUsePathStyleUris()));
}
return this.share;
}
Sets the metadata collection of name-value pairs to be set on the directory with an uploadMetadata
call. This collection will overwrite any existing directory metadata. If this is set to an empty collection, the directory metadata will be cleared on an uploadMetadata
call. Params: - metadata –
A
java.util.HashMap
object that represents the metadata being assigned to the directory.
/**
* Sets the metadata collection of name-value pairs to be set on the directory with an {@link #uploadMetadata} call.
* This collection will overwrite any existing directory metadata. If this is set to an empty collection, the
* directory metadata will be cleared on an {@link #uploadMetadata} call.
*
* @param metadata
* A <code>java.util.HashMap</code> object that represents the metadata being assigned to the directory.
*/
public void setMetadata(HashMap<String, String> metadata) {
this.metadata = metadata;
}
Sets the share for the directory.
Params: - share – A
CloudFileShare
object that represents the share being assigned to the directory.
/**
* Sets the share for the directory.
*
* @param share
* A {@link CloudFileShare} object that represents the share being assigned to the directory.
*/
protected final void setShare(final CloudFileShare share) {
this.share = share;
}
Sets the properties for the directory.
Params: - properties – A
FileDirectoryProperties
object that represents the properties being assigned to the directory.
/**
* Sets the properties for the directory.
*
* @param properties
* A {@link FileDirectoryProperties} object that represents the properties being assigned to the
* directory.
*/
protected final void setProperties(final FileDirectoryProperties properties) {
this.properties = properties;
}
Sets the list of URIs for all locations.
Params: - storageUri – A
StorageUri
that represents the list of URIs for all locations.
/**
* Sets the list of URIs for all locations.
*
* @param storageUri
* A {@link StorageUri} that represents the list of URIs for all locations.
*/
protected void setStorageUri(final StorageUri storageUri) {
this.storageUri = storageUri;
}
Sets the directory's file permission
Params: - filePermission –
A
String
that represents the directory's file permission.
/**
* Sets the directory's file permission
* @param filePermission
* A <code>String</code> that represents the directory's file permission.
*/
public void setFilePermission(String filePermission) {
Utility.assertInBounds("filePermission", filePermission.getBytes().length, 0, 8*Constants.KB);
this.filePermission = filePermission;
}
Verifies the passed in URI. Then parses it and uses its components to populate this resource's properties.
Params: - completeUri – A
StorageUri
object which represents the complete URI. - credentials – A
StorageCredentials
object used to authenticate access.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
/**
* Verifies the passed in URI. Then parses it and uses its components to populate this resource's properties.
*
* @param completeUri
* A {@link StorageUri} object which represents the complete URI.
* @param credentials
* A {@link StorageCredentials} object used to authenticate access.
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
*/
private void parseQueryAndVerify(final StorageUri completeUri, final StorageCredentials credentials)
throws StorageException, URISyntaxException {
Utility.assertNotNull("completeUri", completeUri);
if (!completeUri.isAbsolute()) {
throw new IllegalArgumentException(String.format(SR.RELATIVE_ADDRESS_NOT_PERMITTED, completeUri.toString()));
}
this.storageUri = PathUtility.stripURIQueryAndFragment(completeUri);
final StorageCredentialsSharedAccessSignature parsedCredentials =
SharedAccessSignatureHelper.parseQuery(completeUri);
if (credentials != null && parsedCredentials != null) {
throw new IllegalArgumentException(SR.MULTIPLE_CREDENTIALS_PROVIDED);
}
try {
final boolean usePathStyleUris = Utility.determinePathStyleFromUri(this.storageUri.getPrimaryUri());
this.fileServiceClient = new CloudFileClient(PathUtility.getServiceClientBaseAddress(
this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials);
this.name = PathUtility.getDirectoryNameFromURI(this.storageUri.getPrimaryUri(), usePathStyleUris);
}
catch (final URISyntaxException e) {
throw Utility.generateNewUnexpectedStorageException(e);
}
final HashMap<String, String[]> queryParameters = PathUtility.parseQueryString(completeUri.getQuery());
final String[] snapshotIDs = queryParameters.get(Constants.QueryConstants.SHARE_SNAPSHOT);
if (snapshotIDs != null && snapshotIDs.length > 0) {
this.getShare().snapshotID = snapshotIDs[0];
}
}
Returns the URI after applying the authentication transformation.
Throws: - StorageException –
If a storage service error occurred.
- URISyntaxException –
If the resource URI is invalid.
Returns: A java.net.URI
object that represents the URI after applying the authentication
transformation.
/**
* Returns the URI after applying the authentication transformation.
*
* @return A <code>java.net.URI</code> object that represents the URI after applying the authentication
* transformation.
*
* @throws StorageException
* If a storage service error occurred.
* @throws URISyntaxException
* If the resource URI is invalid.
*/
private StorageUri getTransformedAddress() throws URISyntaxException, StorageException {
return this.fileServiceClient.getCredentials().transformUri(this.storageUri);
}
Verifies that the directory's filePermission and properties.filePermissionKey are both not set.
/**
* Verifies that the directory's filePermission and properties.filePermissionKey are both not set.
*/
protected void assertValidFilePermissionOrKey() {
if (this.filePermission != null && this.properties != null && this.properties.filePermissionKeyToSet != null) {
throw new IllegalArgumentException(SR.FILE_PERMISSION_FILE_PERMISSION_KEY_INVALID);
}
}
}