Android Open Source - gm-httpengine-studio Multi Part Parser






From Project

Back to project page gm-httpengine-studio.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project gm-httpengine-studio 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.httpengine.library;
/* w w w.ja  v a 2  s . c  o m*/
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Set;

/**
 * Created by geminiwen on 14-7-26.
 *
 * file part parser
 */
public class MultiPartParser implements HttpRequestParser{

    private ByteArrayOutputStream mByteArrayBufferStream = new ByteArrayOutputStream();
    private MultipartEntity multipartEntity;

    @Override
    public byte[] parse(GMHttpParameters httpParameters) throws IOException {
        multipartEntity = new MultipartEntity();
        Set<String> keySet = httpParameters.getNames();
        for (String name : keySet) {
            Object value = httpParameters.getParameter(name);
            if (value instanceof  File) {
                multipartEntity.addPart(name, (File) value);
            } else {
                multipartEntity.addPart(name, value.toString());
            }
        }
        mByteArrayBufferStream.reset();
        multipartEntity.writeTo(mByteArrayBufferStream);
        byte[] result = mByteArrayBufferStream.toByteArray();
        mByteArrayBufferStream.reset();
        return result;
    }

    @Override
    public String getContentType() {
        return multipartEntity.getContentType();
    }

    @Override
    public void setEncoding(String encoding) {

    }

    @Override
    public long getContentLength() {
        return multipartEntity.getContentLength();
    }
}




Java Source Code List

org.gemini.httpengine.examples.LoginAPI.java
org.gemini.httpengine.examples.MainActivity.java
org.gemini.httpengine.library.Config.java
org.gemini.httpengine.library.FormUrlEncodedParser.java
org.gemini.httpengine.library.GMHttpEngine.java
org.gemini.httpengine.library.GMHttpException.java
org.gemini.httpengine.library.GMHttpLoader.java
org.gemini.httpengine.library.GMHttpMethodExecutor.java
org.gemini.httpengine.library.GMHttpParameters.java
org.gemini.httpengine.library.GMHttpRequest.java
org.gemini.httpengine.library.GMHttpResponse.java
org.gemini.httpengine.library.GMHttpResult.java
org.gemini.httpengine.library.GMHttpService.java
org.gemini.httpengine.library.GMModelParser.java
org.gemini.httpengine.library.GMTrustManager.java
org.gemini.httpengine.library.HttpMethod.java
org.gemini.httpengine.library.HttpParameter.java
org.gemini.httpengine.library.HttpRequestParser.java
org.gemini.httpengine.library.HttpResponseParser.java
org.gemini.httpengine.library.LOG.java
org.gemini.httpengine.library.MultiPartParser.java
org.gemini.httpengine.library.MultipartEntity.java
org.gemini.httpengine.library.OnProgressUpdateListener.java
org.gemini.httpengine.library.OnResponseListener.java