Android Open Source - EvokeFramework Request Object






From Project

Back to project page EvokeFramework.

License

The source code is released under:

Apache License

If you think the Android project EvokeFramework 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.fs.net.evoke.data;
/* w  w w  .j a v  a2 s . c o m*/
import android.net.Uri;

import org.fs.net.evoke.DownloadManager;
import org.fs.net.evoke.util.StringUtility;
import java.io.File;

/**
 * Created by Fatih on 31/01/15.
 * as org.fs.net.evoke.data.RequestObject
 */
public final class RequestObject {
    
    private final String urlString;
    private final File   moveTo;
    private final long   limit;
    private final DownloadManager.RequestCallback callback;

    private RequestObject(final String urlString, final File moveTo, final long limit, final DownloadManager.RequestCallback callback) {
        this.urlString = urlString;
        this.moveTo = moveTo;
        this.limit = limit;
        this.callback = callback;
    }

    public String getUrlString() {
        return urlString;
    }

    public File getMoveTo() {
        return moveTo;
    }

    public long getLimit() {
        return limit;
    }

    public Builder newBuilder() {
        return new Builder()
                    .urlString(urlString)
                    .moveTo(moveTo)
                    .limit(limit)
                    .requestCallback(callback);                        
    }

    @Override
    public String toString() {
        return getClass().getSimpleName() + " {" +
                urlString                 + ","  +
                hashCode()                + ","  +
                (moveTo == null ? "" : moveTo.toString()) + ","  +
                (callback == null ? "" : callback.toString()) + "," +
                limit                     + " }";
    }

    public static class Builder {
        String urlString = null;
        File   moveTo    = null;
        long   limit     = 0;
        DownloadManager.RequestCallback callback = null;
        
        public Builder() { }
        
        public Builder urlString(String urlString) {
            if(StringUtility.isNullOrEmpty(urlString)) {
               throw new IllegalArgumentException("urlString can not null"); 
            }
            
            Uri uri = Uri.parse(urlString);
            String scheme = uri.getScheme();
            if(!("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme))) {
                throw new IllegalArgumentException("only http or https scheme acceptable.");
            }
            this.urlString = urlString;
            return this;
        }
        
        public Builder requestCallback(DownloadManager.RequestCallback callback) {
            this.callback = callback;
            return this;
        }
        
        public Builder moveTo(File moveTo) {
            this.moveTo = moveTo;
            return this;
        }
        
        public Builder limit(long limit) {
            this.limit = limit;
            return this;
        }
        
        public RequestObject build() {
            return new RequestObject(urlString, moveTo, limit, callback);            
        }
    }
}




Java Source Code List

org.fs.net.ApplicationTest.java
org.fs.net.MainActivity.java
org.fs.net.evoke.ApplicationTest.java
org.fs.net.evoke.DownloadManager.java
org.fs.net.evoke.core.AbstractObject.java
org.fs.net.evoke.data.Download.java
org.fs.net.evoke.data.Error.java
org.fs.net.evoke.data.HeadObject.java
org.fs.net.evoke.data.PartObject.java
org.fs.net.evoke.data.RequestObject.java
org.fs.net.evoke.database.DatabaseHelper.java
org.fs.net.evoke.listener.HeadCallback.java
org.fs.net.evoke.listener.PartCallback.java
org.fs.net.evoke.request.HeadRequest.java
org.fs.net.evoke.request.PartRequest.java
org.fs.net.evoke.th.AbstractRunnable.java
org.fs.net.evoke.util.JsonUtility.java
org.fs.net.evoke.util.LogUtil.java
org.fs.net.evoke.util.RequestUtility.java
org.fs.net.evoke.util.StringUtility.java
org.fs.net.evoke.util.Util.java