-
-
Save alterakey/8ca992df0be9b2faedd1 to your computer and use it in GitHub Desktop.
OkHttpStack ported to OkHttp 2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.android.volley.toolbox.HurlStack; | |
import com.squareup.okhttp.OkHttpClient; | |
import com.squareup.okhttp.OkUrlFactory; | |
import java.io.IOException; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
/** | |
* Ported to OkHttp 2.0, based on https://gist.github.com/JakeWharton/5616899 . | |
* | |
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation which | |
* uses OkHttp as its transport. | |
*/ | |
public class OkHttpStack extends HurlStack { | |
private final OkHttpClient client; | |
private final OkUrlFactory factory; | |
public OkHttpStack() { | |
this(new OkHttpClient()); | |
} | |
public OkHttpStack(OkHttpClient client) { | |
if (client == null) { | |
throw new NullPointerException("Client must not be null."); | |
} | |
this.client = client; | |
this.factory = new OkUrlFactory(client); | |
} | |
@Override protected HttpURLConnection createConnection(URL url) throws IOException { | |
return factory.open(url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment