/** Function to send obex header back to client such as get phonebook size request */
  private final int pushHeader(final Operation op, final HeaderSet reply) {
    OutputStream outputStream = null;

    if (D) Log.d(TAG, "Push Header");
    if (D) Log.d(TAG, reply.toString());

    int pushResult = ResponseCodes.OBEX_HTTP_OK;
    try {
      op.sendHeaders(reply);
      outputStream = op.openOutputStream();
      outputStream.flush();
    } catch (IOException e) {
      Log.e(TAG, e.toString());
      pushResult = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
    } finally {
      if (!closeStream(outputStream, op)) {
        pushResult = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
      }
    }
    return pushResult;
  }
  /** Function to send vcard data to client */
  private final int pushBytes(Operation op, final String vcardString) {
    if (vcardString == null) {
      Log.w(TAG, "vcardString is null!");
      return ResponseCodes.OBEX_HTTP_OK;
    }

    int vcardStringLen = vcardString.length();
    if (D) Log.d(TAG, "Send Data: len=" + vcardStringLen);

    OutputStream outputStream = null;
    int pushResult = ResponseCodes.OBEX_HTTP_OK;
    try {
      outputStream = op.openOutputStream();
    } catch (IOException e) {
      Log.e(TAG, "open outputstrem failed" + e.toString());
      return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
    }

    int position = 0;
    long timestamp = 0;
    int outputBufferSize = op.getMaxPacketSize();
    if (V) Log.v(TAG, "outputBufferSize = " + outputBufferSize);
    while (position != vcardStringLen) {
      if (sIsAborted) {
        ((ServerOperation) op).isAborted = true;
        sIsAborted = false;
        break;
      }
      if (V) timestamp = System.currentTimeMillis();
      int readLength = outputBufferSize;
      if (vcardStringLen - position < outputBufferSize) {
        readLength = vcardStringLen - position;
      }
      String subStr = vcardString.substring(position, position + readLength);
      try {
        outputStream.write(subStr.getBytes(), 0, readLength);
      } catch (IOException e) {
        Log.e(TAG, "write outputstrem failed" + e.toString());
        pushResult = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
        break;
      }
      if (V) {
        Log.v(
            TAG,
            "Sending vcard String position = "
                + position
                + " readLength "
                + readLength
                + " bytes took "
                + (System.currentTimeMillis() - timestamp)
                + " ms");
      }
      position += readLength;
    }

    if (V) Log.v(TAG, "Send Data complete!");

    if (!closeStream(outputStream, op)) {
      pushResult = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
    }

    return pushResult;
  }