private StorageRequest<CloudFileClient, CloudFileShare, Void> uploadPropertiesImpl( final AccessCondition accessCondition, final FileRequestOptions options) { final StorageRequest<CloudFileClient, CloudFileShare, Void> putRequest = new StorageRequest<CloudFileClient, CloudFileShare, Void>(options, this.getStorageUri()) { @Override public HttpURLConnection buildRequest(CloudFileClient client, CloudFileShare share, OperationContext context) throws Exception { return FileRequest.setShareProperties(share.getTransformedAddress().getUri(this.getCurrentLocation()), options, context, accessCondition, share.properties); } @Override public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context) throws Exception { StorageRequest.signBlobQueueAndFileRequest(connection, client, 0L, context); } @Override public Void preProcessResponse(CloudFileShare share, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); return null; } share.updatePropertiesFromResponse(this.getConnection()); return null; } }; return putRequest; }
private StorageRequest<CloudFileClient, CloudFileShare, Void> deleteImpl( final DeleteShareSnapshotsOption deleteSnapshotsOption, final AccessCondition accessCondition, final FileRequestOptions options) { final StorageRequest<CloudFileClient, CloudFileShare, Void> putRequest = new StorageRequest<CloudFileClient, CloudFileShare, Void>(options, this.getStorageUri()) { @Override public HttpURLConnection buildRequest( CloudFileClient client, CloudFileShare share, OperationContext context) throws Exception { return FileRequest.deleteShare( share.getTransformedAddress().getPrimaryUri(), options, context, accessCondition, share.snapshotID, deleteSnapshotsOption); } @Override public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context) throws Exception { StorageRequest.signBlobQueueAndFileRequest(connection, client, -1L, context); } @Override public Void preProcessResponse(CloudFileShare share, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_ACCEPTED) { this.setNonExceptionedRetryableFailure(true); } return null; } }; return putRequest; }
private StorageRequest<CloudFileClient, CloudFileShare, Void> deleteImpl( final DeleteShareSnapshotsOption deleteSnapshotsOption, final AccessCondition accessCondition, final FileRequestOptions options) { final StorageRequest<CloudFileClient, CloudFileShare, Void> putRequest = new StorageRequest<CloudFileClient, CloudFileShare, Void>(options, this.getStorageUri()) { @Override public HttpURLConnection buildRequest( CloudFileClient client, CloudFileShare share, OperationContext context) throws Exception { return FileRequest.deleteShare( share.getTransformedAddress().getPrimaryUri(), options, context, accessCondition, share.snapshotID, deleteSnapshotsOption); } @Override public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context) throws Exception { StorageRequest.signBlobQueueAndFileRequest(connection, client, -1L, context); } @Override public Void preProcessResponse(CloudFileShare share, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_ACCEPTED) { this.setNonExceptionedRetryableFailure(true); } return null; } }; return putRequest; }
private StorageRequest<CloudFileClient, CloudFileShare, Void> downloadAttributesImpl( final AccessCondition accessCondition, final FileRequestOptions options) { final StorageRequest<CloudFileClient, CloudFileShare, Void> getRequest = new StorageRequest<CloudFileClient, CloudFileShare, Void>( options, this.getStorageUri()) {
private StorageRequest<CloudFileClient, CloudFileShare, Void> uploadPropertiesImpl( final AccessCondition accessCondition, final FileRequestOptions options) { final StorageRequest<CloudFileClient, CloudFileShare, Void> putRequest = new StorageRequest<CloudFileClient, CloudFileShare, Void>(options, this.getStorageUri()) { @Override public HttpURLConnection buildRequest(CloudFileClient client, CloudFileShare share, OperationContext context) throws Exception { return FileRequest.setShareProperties(share.getTransformedAddress().getUri(this.getCurrentLocation()), options, context, accessCondition, share.properties); } @Override public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context) throws Exception { StorageRequest.signBlobQueueAndFileRequest(connection, client, 0L, context); } @Override public Void preProcessResponse(CloudFileShare share, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); return null; } share.updatePropertiesFromResponse(this.getConnection()); return null; } }; return putRequest; }
private StorageRequest<CloudFileClient, CloudFileShare, ShareStats> getStatsImpl(final FileRequestOptions options) { final StorageRequest<CloudFileClient, CloudFileShare, ShareStats> getRequest = new StorageRequest<CloudFileClient, CloudFileShare, ShareStats>(options, this.getStorageUri()) {
private StorageRequest<CloudFileClient, CloudFileShare, Void> uploadMetadataImpl( final AccessCondition accessCondition, final FileRequestOptions options) { final StorageRequest<CloudFileClient, CloudFileShare, Void> putRequest = new StorageRequest<CloudFileClient, CloudFileShare, Void>( options, this.getStorageUri()) {
private StorageRequest<CloudFileClient, CloudFileShare, FileSharePermissions> downloadPermissionsImpl( final AccessCondition accessCondition, final FileRequestOptions options) { final StorageRequest<CloudFileClient, CloudFileShare, FileSharePermissions> getRequest = new StorageRequest<CloudFileClient, CloudFileShare, FileSharePermissions>(options, this.getStorageUri()) {
private StorageRequest<CloudFileClient, CloudFileShare, Void> uploadMetadataImpl( final AccessCondition accessCondition, final FileRequestOptions options) { final StorageRequest<CloudFileClient, CloudFileShare, Void> putRequest = new StorageRequest<CloudFileClient, CloudFileShare, Void>( options, this.getStorageUri()) {
/** * Check if a directory reference with metadata will still have that metadata after being created. * * @throws StorageException * @throws URISyntaxException */ @Test public void testCreateDirectoryWithMetadata() throws StorageException, URISyntaxException { String directoryName = "newDirectory1"; CloudFileDirectory directory = new CloudFileDirectory( PathUtility.appendPathToUri(this.share.getStorageUri(), directoryName), directoryName, this.share); Assert.assertEquals(0, directory.getMetadata().size()); directory.getMetadata().put("key1", "value1"); directory.createIfNotExists(); directory.getMetadata().clear(); directory.downloadAttributes(); Assert.assertEquals(1, directory.getMetadata().size()); Assert.assertEquals("value1", directory.getMetadata().get("key1")); }
final boolean usePathStyleUris = Utility.determinePathStyleFromUri(this.storageUri.getPrimaryUri()); this.fileServiceClient = new CloudFileClient(PathUtility.getServiceClientBaseAddress( this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials); this.name = PathUtility.getShareNameFromUri(this.storageUri.getPrimaryUri(), usePathStyleUris);
/** * Validate share references * * @throws StorageException * @throws URISyntaxException */ @Test public void testCloudFileShareReference() throws StorageException, URISyntaxException { CloudFileClient client = FileTestHelper.createCloudFileClient(); CloudFileShare share = client.getShareReference("share"); CloudFileDirectory directory = share.getRootDirectoryReference().getDirectoryReference("directory3"); CloudFileDirectory directory2 = directory.getDirectoryReference("directory4"); assertEquals(share.getStorageUri().toString(), directory.getShare().getStorageUri().toString()); assertEquals(share.getStorageUri().toString(), directory2.getShare().getStorageUri().toString()); assertEquals(share.getStorageUri().toString(), directory2.getParent().getShare().getStorageUri().toString()); }
/** * Returns the file item's parent. * * @return A {@link CloudFileDirectory} object that represents the parent directory for the file. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ @Override public final CloudFileDirectory getParent() throws URISyntaxException, StorageException { if (this.parent == null) { final String parentName = getParentNameFromURI(this.getStorageUri(), this.getShare()); if (parentName != null) { StorageUri parentURI = PathUtility.appendPathToUri(this.share.getStorageUri(), parentName); this.parent = new CloudFileDirectory(parentURI, this.getServiceClient().getCredentials()); } } return this.parent; }
/** * 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 file item's parent. * * @return A {@link CloudFileDirectory} object that represents the parent directory for the file. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ @Override public final CloudFileDirectory getParent() throws URISyntaxException, StorageException { if (this.parent == null) { final String parentName = getParentNameFromURI(this.getStorageUri(), this.getShare()); if (parentName != null) { StorageUri parentURI = PathUtility.appendPathToUri(this.share.getStorageUri(), parentName); this.parent = new CloudFileDirectory(parentURI, this.getServiceClient().getCredentials()); } } return this.parent; }
/** * 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; }
/** * Tests directory creation with absolute uris. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryAbsoluteUriAppended() throws URISyntaxException, StorageException { CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference( this.share.getUri().toString()); assertEquals(PathUtility.appendPathToUri(this.share.getStorageUri(), this.share.getUri().toString()) .getPrimaryUri(), dir.getUri()); assertEquals(new URI(this.share.getUri() + "/" + this.share.getUri()), dir.getUri()); dir = this.share.getRootDirectoryReference().getDirectoryReference(this.share.getUri() + "/TopDir1"); assertEquals( PathUtility.appendPathToUri(this.share.getStorageUri(), this.share.getUri().toString() + "/TopDir1") .getPrimaryUri(), dir.getUri()); }
readListShare.getStorageUri(), this.share.generateSharedAccessSignature(null, "readlist"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), shareFromUri.getServiceClient().getCredentials().getClass().toString());
/** * Test file constructor. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileConstructor() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); CloudFile file2 = new CloudFile(file.getStorageUri(), file.getServiceClient().getCredentials()); assertEquals(file.getName(), file2.getName()); assertEquals(file.getStorageUri(), file2.getStorageUri()); assertEquals(file.getShare().getStorageUri(), file2.getShare().getStorageUri()); assertEquals(FileTestHelper.ensureTrailingSlash(file.getServiceClient().getStorageUri()), FileTestHelper.ensureTrailingSlash(file2.getServiceClient().getStorageUri())); CloudFile file3 = new CloudFile(file2); assertEquals(file3.getName(), file2.getName()); assertEquals(file3.getStorageUri(), file2.getStorageUri()); assertEquals(file3.getShare().getStorageUri(), file2.getShare().getStorageUri()); assertEquals(FileTestHelper.ensureTrailingSlash(file3.getServiceClient().getStorageUri()), FileTestHelper.ensureTrailingSlash(file2.getServiceClient().getStorageUri())); }
/** * Tests the CloudFileDirectory constructor. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryConstructor() throws URISyntaxException, StorageException { CloudFileDirectory directory = this.share.getRootDirectoryReference().getDirectoryReference("directory1"); CloudFileDirectory directory2 = new CloudFileDirectory(directory.getStorageUri(), this.share.getServiceClient().getCredentials()); assertEquals(directory.getName(), directory2.getName()); assertEquals(directory.getStorageUri(), directory2.getStorageUri()); assertEquals(directory.getShare().getStorageUri(), directory2.getShare().getStorageUri()); assertEquals(FileTestHelper.ensureTrailingSlash(directory.getServiceClient().getStorageUri()), FileTestHelper.ensureTrailingSlash(directory2.getServiceClient().getStorageUri())); }