/**
   * Reads BlobItems from the XMLStreamReader, reader must be at Start element of BlobsElement
   *
   * @param xmlr the XMLStreamReader to read from
   * @param serviceClient the CloudBlobClient associated with the objects.
   * @param container the container associated with the objects.
   * @return the BlobItems from the stream
   * @throws XMLStreamException if there is an error parsing the stream
   * @throws ParseException if there is an error in parsing a date
   * @throws URISyntaxException if the uri is invalid
   * @throws StorageException
   */
  public static ArrayList<ListBlobItem> readBlobItems(
      final XMLStreamReader xmlr,
      final CloudBlobClient serviceClient,
      final CloudBlobContainer container)
      throws XMLStreamException, ParseException, URISyntaxException, StorageException {
    int eventType = xmlr.getEventType();
    final ArrayList<ListBlobItem> retBlobs = new ArrayList<ListBlobItem>();

    xmlr.require(XMLStreamConstants.START_ELEMENT, null, BlobConstants.BLOBS_ELEMENT);

    // check if there are more events in the input stream
    while (xmlr.hasNext()) {
      eventType = xmlr.next();
      final String name = xmlr.getName().toString();

      if (eventType == XMLStreamConstants.START_ELEMENT) {
        if (name.equals(BlobConstants.BLOB_ELEMENT)) {
          retBlobs.add(BlobDeserializationHelper.readBlob(xmlr, serviceClient, container));
        } else if (name.equals(BlobConstants.BLOB_PREFIX_ELEMENT)) {
          retBlobs.add(BlobDeserializationHelper.readDirectory(xmlr, serviceClient, container));
        } else {
          throw new StorageException(
              StorageErrorCodeStrings.INVALID_XML_DOCUMENT,
              "The response received is invalid or improperly formatted.",
              Constants.HeaderConstants.HTTP_UNUSED_306,
              null,
              null);
        }
      } else {
        break;
      }
    }

    xmlr.require(XMLStreamConstants.END_ELEMENT, null, BlobConstants.BLOBS_ELEMENT);
    return retBlobs;
  }