com.squareup.okhttp.OkUrlFactory Java Examples
The following examples show how to use
com.squareup.okhttp.OkUrlFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IOUtil.java From droidddle with Apache License 2.0 | 6 votes |
static String fetchPlainText(URL url) throws IOException { InputStream in = null; try { OkHttpClient client = new OkHttpClient(); HttpURLConnection conn = new OkUrlFactory(client).open(url); conn.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT); conn.setReadTimeout(DEFAULT_READ_TIMEOUT); in = conn.getInputStream(); return readFullyPlainText(in); } finally { if (in != null) { in.close(); } } }
Example #2
Source File: LoboBrowser.java From LoboBrowser with MIT License | 6 votes |
/** * Initializes the global URLStreamHandlerFactory. * <p> * This method is invoked by {@link #init(boolean, boolean)}. */ public static void initProtocols(final SSLSocketFactory sslSocketFactory) { // Configure URL protocol handlers final StreamHandlerFactory factory = StreamHandlerFactory.getInstance(); URL.setURLStreamHandlerFactory(factory); final OkHttpClient okHttpClient = new OkHttpClient(); final ArrayList<Protocol> protocolList = new ArrayList<>(2); protocolList.add(Protocol.HTTP_1_1); protocolList.add(Protocol.HTTP_2); okHttpClient.setProtocols(protocolList); okHttpClient.setConnectTimeout(100, TimeUnit.SECONDS); // HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory); okHttpClient.setSslSocketFactory(sslSocketFactory); okHttpClient.setFollowRedirects(false); okHttpClient.setFollowSslRedirects(false); factory.addFactory(new OkUrlFactory(okHttpClient)); factory.addFactory(new LocalStreamHandlerFactory()); }
Example #3
Source File: OkHttpStack.java From catnut with MIT License | 5 votes |
public OkHttpStack(OkHttpClient client) { if (client == null) { throw new NullPointerException("client cannot be null!"); } okHttpClient = client; this.client = client; this.urlFactory = new OkUrlFactory(this.client); }
Example #4
Source File: NetworkManager.java From android-skeleton-project with MIT License | 5 votes |
private OkUrlFactory generateDefaultOkUrlFactory() { OkHttpClient client = new com.squareup.okhttp.OkHttpClient(); try { Cache responseCache = new Cache(baseContext.getCacheDir(), SIZE_OF_CACHE); client.setCache(responseCache); } catch (Exception e) { // Log.d(TAG, "Unable to set http cache", e); } client.setConnectTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS); client.setReadTimeout(CONNECT_TIMEOUT, TimeUnit.MILLISECONDS); return new OkUrlFactory(client); }
Example #5
Source File: NetworkUtils.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static HttpURLConnection getHttpURLConnection(final URL url, final Cache cache, final SSLSocketFactory sslSocketFactory) { OkHttpClient client = new OkHttpClient(); if (cache != null) { client.setCache(cache); } if (sslSocketFactory != null) { client.setSslSocketFactory(sslSocketFactory); } HttpURLConnection connection = new OkUrlFactory(client).open(url); connection.setRequestProperty("User-Agent", MapboxUtils.getUserAgent()); return connection; }
Example #6
Source File: OkHttpStack.java From lunzi with Apache License 2.0 | 4 votes |
public OkHttpStack(OkHttpClient client) { if (client == null) { throw new NullPointerException("Client must not be null."); } mFactory = new OkUrlFactory(client); }
Example #7
Source File: OkHttpStack.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 4 votes |
@Override protected HttpURLConnection createConnection(URL url) throws IOException { OkUrlFactory okUrlFactory = new OkUrlFactory(okHttpClient); return okUrlFactory.open(url); }
Example #8
Source File: OkHttpStack.java From TitanjumNote with Apache License 2.0 | 4 votes |
public OkHttpStack(OkHttpClient client) { if (client == null) { throw new NullPointerException("Client must not be null."); } mFactory = new OkUrlFactory(client); }
Example #9
Source File: OkHttpStack.java From IceNet with Apache License 2.0 | 4 votes |
public OkHttpStack(OkHttpClient client) { if (client == null) { throw new NullPointerException("Client must not be null."); } mFactory = new OkUrlFactory(client); }
Example #10
Source File: OkHttpStack.java From something.apk with MIT License | 4 votes |
protected HttpURLConnection createConnection(URL url) throws IOException { return new OkUrlFactory(client).open(url); }
Example #11
Source File: OkHttpStack.java From catnut with MIT License | 4 votes |
public static OkUrlFactory getOkUrlFactory() { return urlFactory; }
Example #12
Source File: GithubAccessor.java From markdown-doclet with GNU General Public License v3.0 | 4 votes |
private OkHttpConnector createCachedHttpConnector() { final File cacheDirectory = getCacheDirectory(); final Cache cache = new Cache(cacheDirectory, this.cacheSize); return new OkHttpConnector(new OkUrlFactory(new OkHttpClient().setCache(cache))); }
Example #13
Source File: OkHttpStack.java From RestVolley with Apache License 2.0 | 2 votes |
/** * constructor. * @param okHttpClient {@link OkHttpClient} */ public OkHttpStack(OkHttpClient okHttpClient) { mOkUrlFactory = new OkUrlFactory(okHttpClient); }