Android Open Source - AndroidUploader Http Uploader






From Project

Back to project page AndroidUploader.

License

The source code is released under:

Apache License

If you think the Android project AndroidUploader 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 z.hol.uploader;
//w w  w. ja  va 2s  .c  o m
import z.hol.uploader.bridge.Bridge;
import z.hol.uploader.bridge.HttpBridge;

import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * ??http????
 * Created by holmes on 10/19/14.
 */
public class HttpUploader extends StreamUploader {

    private HttpBridge mBridge;
    private AtomicBoolean mIsStarted = new AtomicBoolean(false);

    public HttpUploader(InputStream inputStream, long length, HttpBridge bridge) {
        super(inputStream, length, bridge);
        mBridge = bridge;
    }

    @Override
    public void setBridge(Bridge bridge) {
        if (bridge instanceof HttpBridge){
            mBridge = (HttpBridge) bridge;
            super.setBridge(bridge);
        }else {
            throw new IllegalArgumentException("bridge should be HttpBridge");
        }
    }

    @Override
    public void uploader() {
        super.uploader();
        if (!mIsStarted.get()){
            mIsStarted.set(true);
            asyncUploader();
        }
    }

    /**
     * ????
     */
    protected void asyncUploader(){
        Thread thread = new Thread(this, "Uploader");
        thread.start();
    }

    @Override
    public void run() {
        mBridge.fillEntry(this);
        try {
            mBridge.execute();
        } catch (IOException e) {
            e.printStackTrace();
            onError(4);
        }
        mIsStarted.set(false);
    }
}




Java Source Code List

z.hol.uploader.FileHttpUploader.java
z.hol.uploader.HttpUploader.java
z.hol.uploader.StreamUploader.java
z.hol.uploader.UploadStateCallback.java
z.hol.uploader.UploadUiHandler.java
z.hol.uploader.Uploader.java
z.hol.uploader.bridge.Bridge.java
z.hol.uploader.bridge.HttpBridge.java
z.hol.uploader.bridge.StreamBridge.java