Java Code Examples for com.microsoft.azure.storage.core.Utility#determinePathStyleFromUri()
The following examples show how to use
com.microsoft.azure.storage.core.Utility#determinePathStyleFromUri() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceClient.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * Creates an instance of the <code>ServiceClient</code> class using the specified service endpoint and account * credentials. * * @param storageUri * A {@link StorageUri} object which represents the service endpoint used to create the client. * @param credentials * A {@link StorageCredentials} object which represents the account credentials. */ protected ServiceClient(final StorageUri storageUri, final StorageCredentials credentials) { Utility.assertNotNull("baseUri", storageUri); if (!storageUri.isAbsolute()) { throw new IllegalArgumentException(String.format(SR.RELATIVE_ADDRESS_NOT_PERMITTED, storageUri)); } this.credentials = credentials == null ? StorageCredentialsAnonymous.ANONYMOUS : credentials; this.usePathStyleUris = Utility.determinePathStyleFromUri(storageUri.getPrimaryUri()); this.storageUri = storageUri; }
Example 2
Source File: CloudBlobContainer.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * 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. */ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCredentials credentials) throws StorageException { 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.blobServiceClient = new CloudBlobClient(PathUtility.getServiceClientBaseAddress( this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials); this.name = PathUtility.getContainerNameFromUri(this.storageUri.getPrimaryUri(), usePathStyleUris); } catch (final URISyntaxException e) { throw Utility.generateNewUnexpectedStorageException(e); } }
Example 3
Source File: CloudBlob.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * 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. */ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCredentials credentials) throws StorageException { 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 HashMap<String, String[]> queryParameters = PathUtility.parseQueryString(completeUri.getQuery()); final String[] snapshotIDs = queryParameters.get(BlobConstants.SNAPSHOT); if (snapshotIDs != null && snapshotIDs.length > 0) { this.snapshotID = snapshotIDs[0]; } final StorageCredentialsSharedAccessSignature parsedCredentials = SharedAccessSignatureHelper.parseQuery(queryParameters); if (credentials != null && parsedCredentials != null) { throw new IllegalArgumentException(SR.MULTIPLE_CREDENTIALS_PROVIDED); } try { final boolean usePathStyleUris = Utility.determinePathStyleFromUri(this.storageUri.getPrimaryUri()); this.blobServiceClient = new CloudBlobClient(PathUtility.getServiceClientBaseAddress( this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials); this.name = PathUtility.getBlobNameFromURI(this.storageUri.getPrimaryUri(), usePathStyleUris); } catch (final URISyntaxException e) { throw Utility.generateNewUnexpectedStorageException(e); } }
Example 4
Source File: CloudFileDirectory.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * 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]; } }
Example 5
Source File: CloudFileShare.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * 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. */ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCredentials credentials) throws StorageException { 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 HashMap<String, String[]> queryParameters = PathUtility.parseQueryString(completeUri.getQuery()); final String[] snapshotIDs = queryParameters.get(Constants.QueryConstants.SHARE_SNAPSHOT); if (snapshotIDs != null && snapshotIDs.length > 0) { this.snapshotID = snapshotIDs[0]; } 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.getShareNameFromUri(this.storageUri.getPrimaryUri(), usePathStyleUris); } catch (final URISyntaxException e) { throw Utility.generateNewUnexpectedStorageException(e); } }
Example 6
Source File: CloudFile.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * 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.getFileNameFromURI(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]; } }
Example 7
Source File: CloudTable.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * 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. */ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCredentials credentials) throws StorageException { 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.tableServiceClient = new CloudTableClient(PathUtility.getServiceClientBaseAddress( this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials); this.name = PathUtility.getTableNameFromUri(storageUri.getPrimaryUri(), usePathStyleUris); } catch (final URISyntaxException e) { throw Utility.generateNewUnexpectedStorageException(e); } }
Example 8
Source File: CloudQueue.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * 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. */ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCredentials credentials) throws StorageException { 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.queueServiceClient = new CloudQueueClient(PathUtility.getServiceClientBaseAddress( this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials); this.name = PathUtility.getContainerNameFromUri(storageUri.getPrimaryUri(), usePathStyleUris); } catch (final URISyntaxException e) { throw Utility.generateNewUnexpectedStorageException(e); } }
Example 9
Source File: StorageUri.java From azure-storage-android with Apache License 2.0 | 4 votes |
/** * Initializes a new instance of the {@link StorageUri} class using the specified primary and secondary URIs. * * @param primaryUri * A <code>java.net.URI</code> object for the primary URI. * @param secondaryUri * A <code>java.net.URI</code> object for the secondary URI. */ public StorageUri(URI primaryUri, URI secondaryUri) { if (primaryUri == null && secondaryUri == null) { throw new IllegalArgumentException(SR.STORAGE_URI_NOT_NULL); } if (primaryUri != null && secondaryUri != null) { // check query component is equivalent if ((primaryUri.getQuery() == null && secondaryUri.getQuery() != null) || (primaryUri.getQuery() != null && !(primaryUri.getQuery().equals(secondaryUri.getQuery())))) { throw new IllegalArgumentException(SR.STORAGE_URI_MUST_MATCH); } boolean primaryPathStyle = Utility.determinePathStyleFromUri(primaryUri); boolean secondaryPathStyle = Utility.determinePathStyleFromUri(secondaryUri); if (!primaryPathStyle && !secondaryPathStyle) { if ((primaryUri.getPath() == null && secondaryUri.getPath() != null) || (primaryUri.getPath() != null && !(primaryUri.getPath().equals(secondaryUri.getPath())))) { throw new IllegalArgumentException(SR.STORAGE_URI_MUST_MATCH); } } else { final int maxPrimaryPathSegments = primaryPathStyle ? 3 : 2; final int maxSecondaryPathSegments = secondaryPathStyle ? 3 : 2; // getPath() on a path-style uri returns /devstore1[/path1/path2], split(3) returns ["","devstore","path1/path2"] // getPath() on a regular uri returns [/path1/path2], split(2) returns ["","path1/path2"] final String[] primaryPathSegments = primaryUri.getPath().split("/", maxPrimaryPathSegments); final String[] secondaryPathSegments = secondaryUri.getPath().split("/", maxSecondaryPathSegments); String primaryPath = ""; if (primaryPathSegments.length == maxPrimaryPathSegments) { primaryPath = primaryPathSegments[primaryPathSegments.length - 1]; } String secondaryPath = ""; if (secondaryPathSegments.length == maxSecondaryPathSegments) { secondaryPath = secondaryPathSegments[secondaryPathSegments.length - 1]; } if (!primaryPath.equals(secondaryPath)) { throw new IllegalArgumentException(SR.STORAGE_URI_MUST_MATCH); } } } this.setPrimaryUri(primaryUri); this.setSecondaryUri(secondaryUri); }
Example 10
Source File: ServiceClient.java From azure-storage-android with Apache License 2.0 | 2 votes |
/** * Sets the list of URIs for all locations. * * @param storageUri * A {@link StorageUri} object which represents the list of URIs for all locations. */ protected final void setStorageUri(final StorageUri storageUri) { this.usePathStyleUris = Utility.determinePathStyleFromUri(storageUri.getPrimaryUri()); this.storageUri = storageUri; }