Java Code Examples for com.microsoft.azure.storage.core.Base64#decode()

The following examples show how to use com.microsoft.azure.storage.core.Base64#decode() . 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: CloudQueueMessage.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the content of the message as a byte array.
 * 
 * @return A <code>byte</code> array which contains the content of the message.
 * 
 * @throws StorageException
 *         If a storage service error occurred.
 */
public final byte[] getMessageContentAsByte() throws StorageException {
    if (Utility.isNullOrEmpty(this.messageContent)) {
        return new byte[0];
    }

    if (this.messageType == QueueMessageType.RAW_STRING) {
        try {
            return this.messageContent.getBytes(Constants.UTF8_CHARSET);
        }
        catch (final UnsupportedEncodingException e) {
            throw Utility.generateNewUnexpectedStorageException(e);
        }
    }
    else {
        return Base64.decode(this.messageContent);
    }
}
 
Example 2
Source File: CloudQueueMessage.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the content of the message as a string.
 * 
 * @return A <code>String</code> which contains the content of the message.
 * 
 * @throws StorageException
 *         If a storage service error occurred.
 */
public final String getMessageContentAsString() throws StorageException {
    if (this.messageType == QueueMessageType.RAW_STRING) {
        return this.messageContent;
    }
    else {
        if (Utility.isNullOrEmpty(this.messageContent)) {
            return null;
        }

        try {
            return new String(Base64.decode(this.messageContent), Constants.UTF8_CHARSET);
        }
        catch (final UnsupportedEncodingException e) {
            throw Utility.generateNewUnexpectedStorageException(e);
        }
    }
}
 
Example 3
Source File: StorageAccountTests.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testCloudStorageAccountExportKey() throws InvalidKeyException, URISyntaxException {
    String accountKeyString = "abc2564=";
    String accountString = "BlobEndpoint=http://blobs/;AccountName=test;AccountKey=" + accountKeyString;
    CloudStorageAccount account = CloudStorageAccount.parse(accountString);
    StorageCredentialsAccountAndKey accountAndKey = (StorageCredentialsAccountAndKey) account.getCredentials();
    String key = accountAndKey.exportBase64EncodedKey();
    assertEquals(accountKeyString, key);

    byte[] keyBytes = accountAndKey.exportKey();
    byte[] expectedKeyBytes = Base64.decode(accountKeyString);
    TestHelper.assertByteArrayEquals(expectedKeyBytes, keyBytes);
}
 
Example 4
Source File: StorageCredentialsAccountAndKey.java    From azure-storage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance of the <code>StorageCredentialsAccountAndKey</code> class, using the specified storage
 * account name and access key; the specified access key is stored as a <code>String</code>.
 * 
 * @param accountName
 *            A <code>String</code> that represents the name of the storage account.
 * @param key
 *            A <code>String</code> that represents the Base-64-encoded account access key.
 */
public StorageCredentialsAccountAndKey(final String accountName, final String key) {
    this(accountName, Base64.decode(key));
}
 
Example 5
Source File: EntityProperty.java    From azure-storage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the value of this {@link EntityProperty} as a <code>byte</code> array.
 * 
 * @return
 *         A <code>byte[]</code> representation of the {@link EntityProperty} value, or <code>null</code>.
 */
public byte[] getValueAsByteArray() {
    return this.getIsNull() ? null : Base64.decode(this.value);
}