Java Code Examples for com.microsoft.azure.storage.core.Utility#getXmlSerializer()
The following examples show how to use
com.microsoft.azure.storage.core.Utility#getXmlSerializer() .
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: QueueMessageSerializer.java From azure-storage-android with Apache License 2.0 | 6 votes |
/** * Generates the message request body from a string containing the message. * The message must be encodable as UTF-8. To be included in a web request, * this message request body must be written to the output stream of the web * request. * * @param message * A <code>String<code> containing the message to wrap in a message request body. * * @return An array of <code>byte</code> containing the message request body * encoded as UTF-8. * @throws IOException * if there is an error writing the queue message. * @throws IllegalStateException * if there is an error writing the queue message. * @throws IllegalArgumentException * if there is an error writing the queue message. */ public static byte[] generateMessageRequestBody(final String message) throws IllegalArgumentException, IllegalStateException, IOException { final StringWriter outWriter = new StringWriter(); final XmlSerializer xmlw = Utility.getXmlSerializer(outWriter); // default is UTF8 xmlw.startDocument(Constants.UTF8_CHARSET, true); xmlw.startTag(Constants.EMPTY_STRING, QueueConstants.QUEUE_MESSAGE_ELEMENT); Utility.serializeElement(xmlw, QueueConstants.MESSAGE_TEXT_ELEMENT, message); // end QueueMessage_ELEMENT xmlw.endTag(Constants.EMPTY_STRING, QueueConstants.QUEUE_MESSAGE_ELEMENT); // end doc xmlw.endDocument(); return outWriter.toString().getBytes(Constants.UTF8_CHARSET); }
Example 2
Source File: BlockEntryListSerializer.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * Writes a Block List and returns the corresponding UTF8 bytes. * * @param blockList * the Iterable of BlockEntry to write * @param opContext * a tracking object for the request * @return a byte array of the UTF8 bytes representing the serialized block list. * @throws IOException * if there is an error writing the block list. * @throws IllegalStateException * if there is an error writing the block list. * @throws IllegalArgumentException * if there is an error writing the block list. */ public static byte[] writeBlockListToStream(final Iterable<BlockEntry> blockList, final OperationContext opContext) throws IllegalArgumentException, IllegalStateException, IOException { final StringWriter outWriter = new StringWriter(); final XmlSerializer xmlw = Utility.getXmlSerializer(outWriter); // default is UTF8 xmlw.startDocument(Constants.UTF8_CHARSET, true); xmlw.startTag(Constants.EMPTY_STRING, BlobConstants.BLOCK_LIST_ELEMENT); for (final BlockEntry block : blockList) { if (block.getSearchMode() == BlockSearchMode.COMMITTED) { Utility.serializeElement(xmlw, BlobConstants.COMMITTED_ELEMENT, block.getId()); } else if (block.getSearchMode() == BlockSearchMode.UNCOMMITTED) { Utility.serializeElement(xmlw, BlobConstants.UNCOMMITTED_ELEMENT, block.getId()); } else if (block.getSearchMode() == BlockSearchMode.LATEST) { Utility.serializeElement(xmlw, BlobConstants.LATEST_ELEMENT, block.getId()); } } // end BlockListElement xmlw.endTag(Constants.EMPTY_STRING, BlobConstants.BLOCK_LIST_ELEMENT); // end doc xmlw.endDocument(); return outWriter.toString().getBytes(Constants.UTF8_CHARSET); }
Example 3
Source File: SharedAccessPolicySerializer.java From azure-storage-android with Apache License 2.0 | 4 votes |
/** * RESERVED FOR INTERNAL USE. Writes a collection of shared access policies to the specified stream in XML format. * * @param <T> * * @param sharedAccessPolicies * A collection of shared access policies * @param outWriter * a sink to write the output to. * @throws IOException * if there is an error writing the shared access identifiers. * @throws IllegalStateException * if there is an error writing the shared access identifiers. * @throws IllegalArgumentException * if there is an error writing the shared access identifiers. */ public static <T extends SharedAccessPolicy> void writeSharedAccessIdentifiersToStream( final HashMap<String, T> sharedAccessPolicies, final StringWriter outWriter) throws IllegalArgumentException, IllegalStateException, IOException { Utility.assertNotNull("sharedAccessPolicies", sharedAccessPolicies); Utility.assertNotNull("outWriter", outWriter); final XmlSerializer xmlw = Utility.getXmlSerializer(outWriter); if (sharedAccessPolicies.keySet().size() > Constants.MAX_SHARED_ACCESS_POLICY_IDENTIFIERS) { final String errorMessage = String.format(SR.TOO_MANY_SHARED_ACCESS_POLICY_IDENTIFIERS, sharedAccessPolicies.keySet().size(), Constants.MAX_SHARED_ACCESS_POLICY_IDENTIFIERS); throw new IllegalArgumentException(errorMessage); } // default is UTF8 xmlw.startDocument(Constants.UTF8_CHARSET, true); xmlw.startTag(Constants.EMPTY_STRING, Constants.SIGNED_IDENTIFIERS_ELEMENT); for (final Entry<String, T> entry : sharedAccessPolicies.entrySet()) { final SharedAccessPolicy policy = entry.getValue(); xmlw.startTag(Constants.EMPTY_STRING, Constants.SIGNED_IDENTIFIER_ELEMENT); // Set the identifier Utility.serializeElement(xmlw, Constants.ID, entry.getKey()); xmlw.startTag(Constants.EMPTY_STRING, Constants.ACCESS_POLICY); // Set the Start Time Utility.serializeElement(xmlw, Constants.START, Utility .getUTCTimeOrEmpty(policy.getSharedAccessStartTime()).toString()); // Set the Expiry Time Utility.serializeElement(xmlw, Constants.EXPIRY, Utility.getUTCTimeOrEmpty(policy.getSharedAccessExpiryTime()).toString()); // Set the Permissions Utility.serializeElement(xmlw, Constants.PERMISSION, policy.permissionsToString()); // end AccessPolicy xmlw.endTag(Constants.EMPTY_STRING, Constants.ACCESS_POLICY); // end SignedIdentifier xmlw.endTag(Constants.EMPTY_STRING, Constants.SIGNED_IDENTIFIER_ELEMENT); } // end SignedIdentifiers xmlw.endTag(Constants.EMPTY_STRING, Constants.SIGNED_IDENTIFIERS_ELEMENT); // end doc xmlw.endDocument(); }
Example 4
Source File: ServicePropertiesSerializer.java From azure-storage-android with Apache License 2.0 | 4 votes |
/** * Writes the contents of the ServiceProperties to the stream in xml format. * * @return a byte array of the content to write to the stream. * @throws IOException * if there is an error writing the service properties. * @throws IllegalStateException * if there is an error writing the service properties. * @throws IllegalArgumentException * if there is an error writing the service properties. */ public static byte[] serializeToByteArray(final ServiceProperties properties) throws IllegalArgumentException, IllegalStateException, IOException { final StringWriter outWriter = new StringWriter(); final XmlSerializer xmlw = Utility.getXmlSerializer(outWriter); // default is UTF8 xmlw.startDocument(Constants.UTF8_CHARSET, true); xmlw.startTag(Constants.EMPTY_STRING, Constants.AnalyticsConstants.STORAGE_SERVICE_PROPERTIES_ELEMENT); if (properties.getLogging() != null) { // Logging Properties writeLoggingProperties(xmlw, properties.getLogging()); } if (properties.getHourMetrics() != null) { // Hour Metrics writeMetricsProperties(xmlw, properties.getHourMetrics(), Constants.AnalyticsConstants.HOUR_METRICS_ELEMENT); } if (properties.getMinuteMetrics() != null) { // Minute Metrics writeMetricsProperties(xmlw, properties.getMinuteMetrics(), Constants.AnalyticsConstants.MINUTE_METRICS_ELEMENT); } if (properties.getCors() != null) { // CORS Properties writeCorsProperties(xmlw, properties.getCors()); } // Default Service Version if (properties.getDefaultServiceVersion() != null) { Utility.serializeElement(xmlw, Constants.AnalyticsConstants.DEFAULT_SERVICE_VERSION, properties.getDefaultServiceVersion()); } // end StorageServiceProperties xmlw.endTag(Constants.EMPTY_STRING, Constants.AnalyticsConstants.STORAGE_SERVICE_PROPERTIES_ELEMENT); // end doc xmlw.endDocument(); return outWriter.toString().getBytes(Constants.UTF8_CHARSET); }