/**
   * Uploads data in the form of streams to a server
   *
   * @param callback Callback object responsible for updating UI upon message delivery / request
   *     timeout
   */
  public void uploadStream(final String uploadUri, final ResponseCallback callback) {

    MonitoredDestinationListener responseListener;

    try {
      final URI uri = URI.create(uploadUri + ";deviceSide=true");

      responseListener =
          new MonitoredDestinationListener(
              "StreamData MessageListener [id: " + _listenerId++ + "]");
      final SenderDestination senderDestination =
          DestinationFactory.createNonBlockingSenderDestination(_context, uri, responseListener);

      // Create a byte array of size 10000
      final byte[] input = new byte[10000];
      for (int i = 0; i < input.length; i++) {
        input[i] = '5';
      }

      final ByteArrayInputStream bais = new ByteArrayInputStream(input);

      final StreamMessage message = senderDestination.createStreamMessage();
      ((HttpMessage) message).setMethod(HttpMessage.POST);

      message.setStreamPayload(bais);
      message.setPriority(2);
      message.setTransportHeader("Transfer-Encoding", "chunked");

      final TimeoutMonitor timeoutThread =
          new TimeoutMonitor(senderDestination, true, callback, responseListener, message);
      final Thread t1 = new Thread(timeoutThread, "monitor");

      t1.start();

    } catch (final Exception e) {
      alertDialog(e.toString());
    }
  }
    public void run() {

      try {
        final Object lock = _responseListener.getLock();

        // Send message to retrieve the response
        if (_message == null) {

          ((NonBlockingSenderDestination) _destination).send();
        } else {
          ((NonBlockingSenderDestination) _destination).send(_message);
        }

        // Wait till a response is received by the message listener
        synchronized (lock) {
          try {
            lock.wait(TIMEOUT * 1000);
          } catch (final InterruptedException ex) {
            //
          }
        }

        if (_responseListener.isOnMessage()) {
          final Message responseMsg = _responseListener.getResponse();
          _responseCallback.updateUI(responseMsg);
        } else {
          _responseCallback.timeoutDialog(TIMEOUT);
        }

      } catch (final Exception e) {
        alertDialog(e.toString());
      } finally {
        if (_releaseDestination && _destination != null) {
          _destination.release();
        }
      }
    }