Example #1
0
 /**
  * Find an item in the list
  *
  * @param name String
  * @return NameValue
  */
 public final NameValue findItem(String name) {
   for (int i = 0; i < m_list.size(); i++) {
     NameValue nameVal = m_list.get(i);
     if (nameVal.getName().compareTo(name) == 0) return nameVal;
   }
   return null;
 }
Example #2
0
 /**
  * Find an item in the list using a caseless search
  *
  * @param name String
  * @return NameValue
  */
 public final NameValue findItemCaseless(String name) {
   for (int i = 0; i < m_list.size(); i++) {
     NameValue nameVal = m_list.get(i);
     if (nameVal.getName().equalsIgnoreCase(name)) return nameVal;
   }
   return null;
 }
  @Override
  public void setHeaders(
      List<NameValue> requestHeaders, boolean isFixedLengthStreamingMode, long totalBodyBytes)
      throws IOException {
    if (isFixedLengthStreamingMode) {
      if (android.os.Build.VERSION.SDK_INT >= 19) {
        mConnection.setFixedLengthStreamingMode(totalBodyBytes);

      } else {
        if (totalBodyBytes > Integer.MAX_VALUE)
          throw new RuntimeException(
              "You need Android API version 19 or newer to "
                  + "upload more than 2GB in a single request using "
                  + "fixed size content length. Try switching to "
                  + "chunked mode instead, but make sure your server side supports it!");

        mConnection.setFixedLengthStreamingMode((int) totalBodyBytes);
      }
    } else {
      mConnection.setChunkedStreamingMode(0);
    }

    for (final NameValue param : requestHeaders) {
      mConnection.setRequestProperty(param.getName(), param.getValue());
    }
  }
 /**
  * Store nv list to hash map.
  *
  * @param filename the filename
  * @param options the options
  * @param dstMap the dst map
  */
 public static void storeNVListToHashMap(
     String filename, OptionList options, Map<String, String> dstMap) {
   if (options == null || options.getOption() == null || options.getOption().isEmpty()) {
     return;
   }
   List<NameValue> optionNvList = options.getOption();
   for (int i = 0; i < optionNvList.size(); i++) {
     NameValue nv = optionNvList.get(i);
     dstMap.put(nv.getName(), nv.getValue());
   }
 }
Example #5
0
  /**
   * Return the name/value list as a string
   *
   * @return String
   */
  public String toString() {
    StringBuffer str = new StringBuffer(256);

    str.append("[");
    for (int i = 0; i < numberOfItems(); i++) {
      if (str.length() > 1) str.append(",");
      NameValue nameVal = getItemAt(i);

      str.append(nameVal.getName());
      str.append("=");
      str.append(nameVal.getValue());
    }
    str.append("]");

    return str.toString();
  }
Example #6
0
  /**
   * Find all items with the specified name and return as a new list
   *
   * @param name String
   * @return NameValueList
   */
  public final NameValueList findAllItems(String name) {

    //	Allocate the list to hold the matching items

    NameValueList list = new NameValueList();

    //	Find the matching items

    for (int i = 0; i < m_list.size(); i++) {
      NameValue nameVal = m_list.get(i);
      if (nameVal.getName().compareTo(name) == 0) list.addItem(nameVal);
    }

    //	Check if the list is empty, return the list

    if (list.numberOfItems() == 0) list = null;
    return list;
  }