Skip to content

Instantly share code, notes, and snippets.

@gino2010
Created May 14, 2016 10:38
Show Gist options
  • Save gino2010/55ad8ae112f79c61ac71a5aea587e22e to your computer and use it in GitHub Desktop.
Save gino2010/55ad8ae112f79c61ac71a5aea587e22e to your computer and use it in GitHub Desktop.
OkHttp3Stack extends HrulStack
package com.gino;
import com.android.volley.toolbox.HurlStack;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import okhttp3.OkHttpClient;
import okhttp3.OkUrlFactory;
/**
* Created by gino on 5/14/16.
*/
public class OkHttp3Stack extends HurlStack {
private final OkUrlFactory okUrlFactory;
public OkHttp3Stack() {
this(new OkUrlFactory(new OkHttpClient()));
}
public OkHttp3Stack(OkUrlFactory okUrlFactory) {
if (okUrlFactory == null) {
throw new NullPointerException("Client must not be null.");
}
this.okUrlFactory = okUrlFactory;
}
@Override
protected HttpURLConnection createConnection(URL url) throws IOException {
return okUrlFactory.open(url);
}
}
@gino2010
Copy link
Author

need com.squareup.okhttp3:okhttp-urlconnection lib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment