Java Code Examples for com.microsoft.azure.storage.Constants#EMPTY_STRING

The following examples show how to use com.microsoft.azure.storage.Constants#EMPTY_STRING . 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: Utility.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the UTC date/time for the specified value using the ISO8601 pattern.
 * 
 * @param value
 *            A <code>Date</code> object that represents the date to convert to UTC date/time in the ISO8601
 *            pattern. If this value is <code>null</code>, this method returns an empty string.
 * 
 * @return A <code>String</code> that represents the UTC date/time for the specified value using the ISO8601
 *         pattern, or an empty string if <code>value</code> is <code>null</code>.
 */
public static String getUTCTimeOrEmpty(final Date value) {
    if (value == null) {
        return Constants.EMPTY_STRING;
    }

    final DateFormat iso8601Format = new SimpleDateFormat(ISO8601_PATTERN, LOCALE_US);
    iso8601Format.setTimeZone(UTC_ZONE);

    return iso8601Format.format(value);
}
 
Example 2
Source File: SharedAccessQueuePolicy.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Converts this policy's permissions to a string.
 * 
 * @return A <code>String</code> that represents the shared access permissions in the "raup" format, which is
 *         described at {@link SharedAccessQueuePolicy#setPermissionsFromString(String)}.
 */
@Override
public String permissionsToString() {
    if (this.permissions == null) {
        return Constants.EMPTY_STRING;
    }

    // The service supports a fixed order => raup
    final StringBuilder builder = new StringBuilder();

    if (this.permissions.contains(SharedAccessQueuePermissions.READ)) {
        builder.append("r");
    }

    if (this.permissions.contains(SharedAccessQueuePermissions.ADD)) {
        builder.append("a");
    }

    if (this.permissions.contains(SharedAccessQueuePermissions.UPDATE)) {
        builder.append("u");
    }

    if (this.permissions.contains(SharedAccessQueuePermissions.PROCESSMESSAGES)) {
        builder.append("p");
    }

    return builder.toString();
}
 
Example 3
Source File: BlobListHandler.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    this.elementStack.push(localName);

    if (BlobConstants.BLOB_ELEMENT.equals(localName) || BlobConstants.BLOB_PREFIX_ELEMENT.equals(localName)) {
        this.blobName = Constants.EMPTY_STRING;
        this.snapshotID = null;
        this.properties = new BlobProperties();
        this.metadata = new HashMap<String, String>();
        this.copyState = null;
    }
}
 
Example 4
Source File: ContainerListHandler.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    this.elementStack.push(localName);

    if (BlobConstants.CONTAINER_ELEMENT.equals(localName)) {
        this.containerName = Constants.EMPTY_STRING;
        this.attributes = new BlobContainerAttributes();
        this.attributes.getProperties().setPublicAccess(BlobContainerPublicAccessType.OFF);
    }
}
 
Example 5
Source File: SharedAccessBlobPolicy.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Converts this policy's permissions to a string.
 * 
 * @return A <code>String</code> that represents the shared access permissions in the "racwdl" format,
 *         which is described at {@link #setPermissionsFromString(String)}.
 */
@Override
public String permissionsToString() {
    if (this.permissions == null) {
        return Constants.EMPTY_STRING;
    }

    // The service supports a fixed order => racwdl
    final StringBuilder builder = new StringBuilder();

    if (this.permissions.contains(SharedAccessBlobPermissions.READ)) {
        builder.append("r");
    }

    if (this.permissions.contains(SharedAccessBlobPermissions.ADD)) {
        builder.append("a");
    }

    if (this.permissions.contains(SharedAccessBlobPermissions.CREATE)) {
        builder.append("c");
    }

    if (this.permissions.contains(SharedAccessBlobPermissions.WRITE)) {
        builder.append("w");
    }

    if (this.permissions.contains(SharedAccessBlobPermissions.DELETE)) {
        builder.append("d");
    }

    if (this.permissions.contains(SharedAccessBlobPermissions.LIST)) {
        builder.append("l");
    }

    return builder.toString();
}
 
Example 6
Source File: FileListHandler.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    this.elementStack.push(localName);

    if (FileConstants.FILE_ELEMENT.equals(localName)) {
        this.name = Constants.EMPTY_STRING;
        this.fileProperties = new FileProperties();
    }

    if (FileConstants.DIRECTORY_ELEMENT.equals(localName)) {
        this.name = Constants.EMPTY_STRING;
        this.directoryProperties = new FileDirectoryProperties();
    }
}
 
Example 7
Source File: SharedAccessFilePolicy.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Converts this policy's permissions to a string.
 * 
 * @return A <code>String</code> that represents the shared access permissions in the "rcwdl" format,
 *         which is described at {@link #setPermissionsFromString(String)}.
 */
@Override
public String permissionsToString() {
    if (this.permissions == null) {
        return Constants.EMPTY_STRING;
    }

    // The service supports a fixed order => rcwdl
    final StringBuilder builder = new StringBuilder();

    if (this.permissions.contains(SharedAccessFilePermissions.READ)) {
        builder.append("r");
    }

    if (this.permissions.contains(SharedAccessFilePermissions.CREATE)) {
        builder.append("c");
    }

    if (this.permissions.contains(SharedAccessFilePermissions.WRITE)) {
        builder.append("w");
    }

    if (this.permissions.contains(SharedAccessFilePermissions.DELETE)) {
        builder.append("d");
    }

    if (this.permissions.contains(SharedAccessFilePermissions.LIST)) {
        builder.append("l");
    }

    return builder.toString();
}
 
Example 8
Source File: ShareListHandler.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    this.elementStack.push(localName);

    if (FileConstants.SHARE_ELEMENT.equals(localName)) {
        this.shareName = Constants.EMPTY_STRING;
        this.snapshotID = null;
        this.attributes = new FileShareAttributes();
    }
}
 
Example 9
Source File: SharedAccessTablePolicy.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Converts this policy's permissions to a string.
 * 
 * @return A <code>String</code> that represents the shared access permissions in the "raud" format, which is
 *         described at {@link SharedAccessTablePolicy#setPermissionsFromString(String)}.
 */
@Override
public String permissionsToString() {
    if (this.permissions == null) {
        return Constants.EMPTY_STRING;
    }

    // The service supports a fixed order => raud
    final StringBuilder builder = new StringBuilder();

    if (this.permissions.contains(SharedAccessTablePermissions.QUERY)) {
        builder.append("r");
    }

    if (this.permissions.contains(SharedAccessTablePermissions.ADD)) {
        builder.append("a");
    }

    if (this.permissions.contains(SharedAccessTablePermissions.UPDATE)) {
        builder.append("u");
    }

    if (this.permissions.contains(SharedAccessTablePermissions.DELETE)) {
        builder.append("d");
    }

    return builder.toString();
}
 
Example 10
Source File: QueueListHandler.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    this.elementStack.push(localName);

    if (QueueConstants.QUEUE_ELEMENT.equals(localName)) {
        this.queueName = Constants.EMPTY_STRING;
        this.metadata = new HashMap<String, String>();
    }
}
 
Example 11
Source File: TableOperation.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Reserved for internal use. Generates the request identity, consisting of the specified entry name, or the
 * PartitionKey and RowKey pair from the operation, to identify the operation target.
 * 
 * @param isSingleIndexEntry
 *            Pass <code>true</code> to use the specified <code>entryName</code> parameter, or <code>false</code> to
 *            use PartitionKey and RowKey values from the operation as the request identity.
 * @param entryName
 *            The entry name to use as the request identity if the <code>isSingleIndexEntry</code> parameter is
 *            <code>true</code>.
 * @return
 *         A <code>String</code> which represents the formatted request identity string.
 * @throws StorageException
 *             If a storage service error occurred.
 */
protected String generateRequestIdentity(boolean isSingleIndexEntry, final String entryName)
        throws StorageException {
    if (isSingleIndexEntry) {
        return String.format("'%s'", entryName.replace("'", "''"));
    }

    if (this.opType == TableOperationType.INSERT) {
        return Constants.EMPTY_STRING;
    }
    else {
        String pk = null;
        String rk = null;

        if (this.opType == TableOperationType.RETRIEVE) {
            final QueryTableOperation qOp = (QueryTableOperation) this;
            pk = qOp.getPartitionKey();
            rk = qOp.getRowKey();
        }
        else {
            pk = this.getEntity().getPartitionKey();
            rk = this.getEntity().getRowKey();
        }

        return String.format("%s='%s',%s='%s'", 
                TableConstants.PARTITION_KEY, pk.replace("'", "''"), 
                TableConstants.ROW_KEY, rk.replace("'", "''"));
    }
}
 
Example 12
Source File: Utility.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Performs safe encoding of the specified string, taking care to insert <code>%20</code> for each space character,
 * instead of inserting the <code>+</code> character.
 * 
 * @param stringToEncode
 *            A <code>String</code> that represents the string to encode.
 * 
 * @return A <code>String</code> that represents the encoded string.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
public static String safeEncode(final String stringToEncode) throws StorageException {
    if (stringToEncode == null) {
        return null;
    }
    if (stringToEncode.length() == 0) {
        return Constants.EMPTY_STRING;
    }

    try {
        final String tString = URLEncoder.encode(stringToEncode, Constants.UTF8_CHARSET);

        if (stringToEncode.contains(" ")) {
            final StringBuilder outBuilder = new StringBuilder();

            int startDex = 0;
            for (int m = 0; m < stringToEncode.length(); m++) {
                if (stringToEncode.charAt(m) == ' ') {
                    if (m > startDex) {
                        outBuilder.append(URLEncoder.encode(stringToEncode.substring(startDex, m),
                                Constants.UTF8_CHARSET));
                    }

                    outBuilder.append("%20");
                    startDex = m + 1;
                }
            }

            if (startDex != stringToEncode.length()) {
                outBuilder.append(URLEncoder.encode(stringToEncode.substring(startDex, stringToEncode.length()),
                        Constants.UTF8_CHARSET));
            }

            return outBuilder.toString();
        }
        else {
            return tString;
        }

    }
    catch (final UnsupportedEncodingException e) {
        throw Utility.generateNewUnexpectedStorageException(e);
    }
}
 
Example 13
Source File: Utility.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Performs safe decoding of the specified string, taking care to preserve each <code>+</code> character, rather
 * than replacing it with a space character.
 * 
 * @param stringToDecode
 *            A <code>String</code> that represents the string to decode.
 * 
 * @return A <code>String</code> that represents the decoded string.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
public static String safeDecode(final String stringToDecode) throws StorageException {
    if (stringToDecode == null) {
        return null;
    }

    if (stringToDecode.length() == 0) {
        return Constants.EMPTY_STRING;
    }

    try {
        if (stringToDecode.contains("+")) {
            final StringBuilder outBuilder = new StringBuilder();

            int startDex = 0;
            for (int m = 0; m < stringToDecode.length(); m++) {
                if (stringToDecode.charAt(m) == '+') {
                    if (m > startDex) {
                        outBuilder.append(URLDecoder.decode(stringToDecode.substring(startDex, m),
                                Constants.UTF8_CHARSET));
                    }

                    outBuilder.append("+");
                    startDex = m + 1;
                }
            }

            if (startDex != stringToDecode.length()) {
                outBuilder.append(URLDecoder.decode(stringToDecode.substring(startDex, stringToDecode.length()),
                        Constants.UTF8_CHARSET));
            }

            return outBuilder.toString();
        }
        else {
            return URLDecoder.decode(stringToDecode, Constants.UTF8_CHARSET);
        }
    }
    catch (final UnsupportedEncodingException e) {
        throw Utility.generateNewUnexpectedStorageException(e);
    }
}
 
Example 14
Source File: MimeHelper.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Reserved for internal use. A static factory method that generates a {@link MimePart} containing the next MIME
 * part read from the {@link BufferedReader}.
 * The {@link BufferedReader} is left positioned at the start of the next MIME boundary header.
 * 
 * @param reader
 *            The {@link BufferedReader} containing the response stream to parse.
 * @param boundary
 *            A <code>String</code> containing the MIME part boundary string.
 *            An {@link OperationContext} object for tracking the current operation. Specify <code>null</code> to
 *            safely ignore operation context.
 * @return
 *         A {@link MimePart} constructed by parsing the next MIME part data from the {@link BufferedReader}.
 * @throws IOException
 *             if an error occured accessing the input stream.
 * @throws StorageException
 *             if an error occured parsing the input stream.
 */
private static MimePart readMimePart(final BufferedReader reader, final String boundary,
        final OperationContext opContext) throws IOException, StorageException {
    final MimePart retPart = new MimePart();
    // Read HttpStatus code
    String tempStr = getNextLineSkippingBlankLines(reader);
    if (!tempStr.startsWith("HTTP/1.1 ")) {
        throw generateMimeParseException();
    }

    final String[] headerVals = tempStr.split(" ");

    if (headerVals.length < 3) {
        throw generateMimeParseException();
    }

    retPart.httpStatusCode = Integer.parseInt(headerVals[1]);
    // "HTTP/1.1 XXX ".length() => 13
    retPart.httpStatusMessage = tempStr.substring(13);

    // Read headers
    tempStr = reader.readLine();
    while (tempStr != null && tempStr.length() > 0) {
        final String[] headerParts = tempStr.split(": ");
        if (headerParts.length < 2) {
            throw generateMimeParseException();
        }

        retPart.headers.put(headerParts[0], headerParts[1]);
        tempStr = reader.readLine();
    }

    // Store json payload
    reader.mark(1024 * 1024);
    tempStr = getNextLineSkippingBlankLines(reader);

    if (tempStr == null) {
        throw generateMimeParseException();
    }

    // empty body
    if (tempStr.startsWith(boundary)) {
        reader.reset();
        retPart.payload = Constants.EMPTY_STRING;
        return retPart;
    }
    final StringBuilder payloadBuilder = new StringBuilder();
    // read until mime closure or end of file
    while (!tempStr.startsWith(boundary)) {
        payloadBuilder.append(tempStr);
        reader.mark(1024 * 1024);
        tempStr = getNextLineSkippingBlankLines(reader);
        if (tempStr == null) {
            throw generateMimeParseException();
        }
    }

    // positions stream at start of next MIME Header
    reader.reset();

    retPart.payload = payloadBuilder.toString();

    return retPart;
}
 
Example 15
Source File: CloudBlobDirectory.java    From azure-storage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a result segment containing a collection of blob items whose names begin with the specified prefix, using
 * the specified flat or hierarchical option, listing details options, request options, and operation context.
 * 
 * @param prefix
 *            A <code>String</code> that represents the prefix of the blob name.
 * @param useFlatBlobListing
 *            <code>true</code> to indicate that the returned list will be flat; <code>false</code> to indicate that
 *            the returned list will be hierarchical.
 * @param listingDetails
 *            A <code>java.util.EnumSet</code> object that contains {@link BlobListingDetails} values that indicate
 *            whether snapshots, metadata, and/or uncommitted blocks are returned. Committed blocks are always
 *            returned.
 * @param maxResults
 *            The maximum number of results to retrieve.
 * @param continuationToken
 *            A {@link ResultContinuation} object that represents a continuation token returned by a previous
 *            listing operation.
 * @param options
 *            A {@link BlobRequestOptions} 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 CloudBlobClient}).
 * @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 ListBlobItem} objects that represent the block items whose names begin with the specified prefix
 *         in the directory.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException
 *             If the resource URI is invalid.
 */
@DoesServiceRequest
public ResultSegment<ListBlobItem> listBlobsSegmented(String prefix, final boolean useFlatBlobListing,
        final EnumSet<BlobListingDetails> listingDetails, final Integer maxResults,
        final ResultContinuation continuationToken, final BlobRequestOptions options,
        final OperationContext opContext) throws StorageException, URISyntaxException {
    prefix = prefix == null ? Constants.EMPTY_STRING : prefix;
    return this.getContainer().listBlobsSegmented(this.getPrefix().concat(prefix), useFlatBlobListing,
            listingDetails, maxResults, continuationToken, options, opContext);
}
 
Example 16
Source File: Utility.java    From azure-storage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the standard header value from the specified connection request, or an empty string if no header value
 * has been specified for the request.
 * 
 * @param conn
 *            An <code>HttpURLConnection</code> object that represents the request.
 * @param headerName
 *            A <code>String</code> that represents the name of the header being requested.
 * 
 * @return A <code>String</code> that represents the header value, or <code>null</code> if there is no corresponding
 *         header value for <code>headerName</code>.
 */
public static String getStandardHeaderValue(final HttpURLConnection conn, final String headerName) {
    final String headerValue = conn.getRequestProperty(headerName);

    // Coalesce null value
    return headerValue == null ? Constants.EMPTY_STRING : headerValue;
}
 
Example 17
Source File: CloudBlobDirectory.java    From azure-storage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an enumerable collection of blob items whose names begin with the specified prefix, using the specified
 * flat or hierarchical option, listing details options, request options, and operation context.
 * 
 * @param prefix
 *            A <code>String</code> that represents the prefix of the blob name.
 * @param useFlatBlobListing
 *            <code>true</code> to indicate that the returned list will be flat; <code>false</code> to indicate that
 *            the returned list will be hierarchical.
 * @param listingDetails
 *            A <code>java.util.EnumSet</code> object that contains {@link BlobListingDetails} values that indicate
 *            whether snapshots, metadata, and/or uncommitted blocks are returned. Committed blocks are always
 *            returned.
 * @param options
 *            A {@link BlobRequestOptions} 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 CloudBlobClient}).
 * @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 ListBlobItem} objects that represent the block items whose names begin
 *         with the specified prefix in this directory.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException
 *             If the resource URI is invalid.
 */
@DoesServiceRequest
public Iterable<ListBlobItem> listBlobs(String prefix, final boolean useFlatBlobListing,
        final EnumSet<BlobListingDetails> listingDetails, final BlobRequestOptions options,
        final OperationContext opContext) throws URISyntaxException, StorageException {
    prefix = prefix == null ? Constants.EMPTY_STRING : prefix;
    return this.getContainer().listBlobs(this.getPrefix().concat(prefix), useFlatBlobListing, listingDetails,
            options, opContext);
}
 
Example 18
Source File: CloudBlobDirectory.java    From azure-storage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a result segment containing a collection of blob items whose names begin with the specified prefix.
 * 
 * @param prefix
 *            A <code>String</code> that represents the prefix of the blob name.
 * 
 * @return A {@link ResultSegment} object that contains a segment of the enumerable collection of
 *         {@link ListBlobItem} objects that represent the blob items whose names begin with the specified prefix in
 *         the directory.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException
 *             If the resource URI is invalid.
 */
@DoesServiceRequest
public ResultSegment<ListBlobItem> listBlobsSegmented(String prefix) throws StorageException, URISyntaxException {
    prefix = prefix == null ? Constants.EMPTY_STRING : prefix;
    return this.getContainer().listBlobsSegmented(this.getPrefix().concat(prefix));
}
 
Example 19
Source File: CloudBlobDirectory.java    From azure-storage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an enumerable collection of blob items whose names begin with the specified prefix for the directory.
 * 
 * @param prefix
 *            A <code>String</code> that represents the blob name prefix.
 * 
 * @return An enumerable collection of {@link ListBlobItem} objects that represent the block items whose names begin
 *         with the specified prefix in this directory.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException
 *             If the resource URI is invalid.
 */
@DoesServiceRequest
public Iterable<ListBlobItem> listBlobs(String prefix) throws URISyntaxException, StorageException {
    prefix = prefix == null ? Constants.EMPTY_STRING : prefix;
    return this.getContainer().listBlobs(this.getPrefix().concat(prefix));
}