Android Open Source - AndroidUploader Stream Bridge






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.bridge;
//from   w  w w .j a va  2  s.c o  m
import java.io.IOException;
import java.io.OutputStream;

/**
 * ?????
 * Created by holmes on 10/15/14.
 */
public abstract class StreamBridge implements Bridge{

    protected OutputStream outStream;

    private boolean mCloseStreamOnFinish = true;

    public StreamBridge(){

    }

    /**
     * ????????
     * ?????? this.outStream ??
     * @param out
     */
    public void setOutStream(OutputStream out){
        outStream = out;
    }

    public void setCloseStreamOnFinish(boolean close){
        mCloseStreamOnFinish = close;
    }

    public boolean isCloseStreamOnFinish(){
        return mCloseStreamOnFinish;
    }

    @Override
    public int uploadData(byte[] data, int len) throws IOException {
        if (outStream == null){
            throw new NullPointerException("outStream can not be null");
        }

        int uploadLen = len > data.length ? data.length : len;
        outStream.write(data, 0, uploadLen);

        return uploadLen;
    }

    @Override
    public boolean finish() {
        if (mCloseStreamOnFinish){
            if (outStream != null){
                try {
                    outStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    return false;
                }
            }
        }
        return true;
    }
}




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