Android Open Source - gm-httpengine-eclipse Default Http Request Parser






From Project

Back to project page gm-httpengine-eclipse.

License

The source code is released under:

MIT License

If you think the Android project gm-httpengine-eclipse listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.gemini.parser;
/* w  w  w  .  j  a  v  a 2s . c o m*/
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Set;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;
import org.gemini.net.GMHttpParameters;

public class DefaultHttpRequestParser implements HttpRequestParser {

  /***
   * parse form body
   */
  @Override
  public byte[] parse(GMHttpParameters httpParams) throws IOException {
    Set<String> keySet = httpParams.getNames();
    ArrayList<NameValuePair> nvps = new ArrayList<NameValuePair>();
    for (String name : keySet) {
      String value = httpParams.getStringParameter(name);
      NameValuePair p = new BasicNameValuePair(name, value);
      nvps.add(p);
    }
    HttpEntity entity = new UrlEncodedFormEntity(nvps, "UTF-8");
    InputStream is = entity.getContent();
    int avaliable = is.available();
    byte[] buffer = new byte[avaliable];
    is.read(buffer);
    is.close();
    return buffer;
  }

  @Override
  public String pareContentType() {
    return "application/x-www-form-urlencoded; charset=UTF-8";
  }

}




Java Source Code List

org.gemini.listener.OnProgressUpdateListener.java
org.gemini.listener.OnResponseListener.java
org.gemini.net.GMHttpEngine.java
org.gemini.net.GMHttpParameters.java
org.gemini.net.GMHttpRequest.java
org.gemini.net.GMHttpResponse.java
org.gemini.net.GMHttpService.java
org.gemini.net.GMNetStateManager.java
org.gemini.parser.DefaultHttpRequestParser.java
org.gemini.parser.HttpRequestParser.java
org.gemini.parser.HttpResponseParser.java
org.gemini.util.LOG.java