當前位置: 首頁>>代碼示例>>Java>>正文


Java OkUrlFactory類代碼示例

本文整理匯總了Java中com.squareup.okhttp.OkUrlFactory的典型用法代碼示例。如果您正苦於以下問題:Java OkUrlFactory類的具體用法?Java OkUrlFactory怎麽用?Java OkUrlFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OkUrlFactory類屬於com.squareup.okhttp包,在下文中一共展示了OkUrlFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initGithub

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
public GitHub initGithub() {
    String tmpDirPath = System.getProperty("java.io.tmpdir");
    File cacheDirectoryParent = new File(tmpDirPath);
    File cacheDirectory = new File(cacheDirectoryParent, "okhttpCache");
    if (!cacheDirectory.exists()) {
        cacheDirectory.mkdir();
    }
    Cache cache = new Cache(cacheDirectory, 100 * 1024 * 1024);
    try {
        return GitHubBuilder.fromCredentials()
                .withRateLimitHandler(RateLimitHandler.WAIT)
                .withAbuseLimitHandler(AbuseLimitHandler.WAIT)
                .withConnector(new OkHttpConnector(new OkUrlFactory(new OkHttpClient().setCache(cache))))
                .build();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:couchbaselabs,項目名稱:GitTalent,代碼行數:19,代碼來源:GithubImportService.java

示例2: fetch

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
static byte[] fetch(URL url) throws IOException {
    InputStream in = null;

    try {
        OkHttpClient client = new OkHttpClient();
        HttpURLConnection conn = new OkUrlFactory(client).open(url);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        in = conn.getInputStream();
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) > 0) {
            out.write(buffer, 0, bytesRead);
        }
        return out.toByteArray();

    } finally {
        if (in != null) {
            in.close();
        }
    }
}
 
開發者ID:frank-tan,項目名稱:XYZReader,代碼行數:22,代碼來源:RemoteEndpointUtil.java

示例3: fetchPlainText

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
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();
        }
    }
}
 
開發者ID:goodev,項目名稱:droidddle,代碼行數:18,代碼來源:IOUtil.java

示例4: initProtocols

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
/**
 * 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 PlatformStreamHandlerFactory factory = PlatformStreamHandlerFactory.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());
}
 
開發者ID:lobobrowser,項目名稱:LoboBrowser,代碼行數:26,代碼來源:LoboBrowser.java

示例5: buildRequest

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
@Override
protected GapiOkHttpRequest buildRequest(String method, String url) throws IOException {
    Preconditions.checkArgument(supportsMethod(method), "HTTP method %s not supported", method);
    // connection with proxy settings
    URL connUrl = new URL(url);
    OkHttpClient client = new OkHttpClient();
    OkUrlFactory factory = new OkUrlFactory(client);
    SSLContext sslContext;
    try {
        sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, null, null);
    } catch (GeneralSecurityException e) {
        throw new AssertionError(); // The system has no TLS. Just give up.
    }
    client.setSslSocketFactory(sslContext.getSocketFactory());

    if(proxy != null)
        client.setProxy(proxy);

    URLConnection conn = factory.open(connUrl);
    HttpURLConnection connection = (HttpURLConnection) conn;
    connection.setRequestMethod(method);

    return new GapiOkHttpRequest(connection);
}
 
開發者ID:gdgjodhpur,項目名稱:gdgapp,代碼行數:26,代碼來源:GapiOkTransport.java

示例6: createConnection

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
@Override
protected HttpURLConnection createConnection(URL url) throws IOException {
    OkHttpClient client = new OkHttpClient();
    OkUrlFactory factory = new OkUrlFactory(client);
    SSLContext sslContext;
    try {
        TrustManager[] trustAllCerts = new TrustManager[] { new GdgTrustManager(App.getInstance().getApplicationContext()) };

        sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
    } catch (GeneralSecurityException e) {
        throw new AssertionError(); // The system has no TLS. Just give up.
    }
    client.setSslSocketFactory(sslContext.getSocketFactory());
    return factory.open(url);
}
 
開發者ID:gdgjodhpur,項目名稱:gdgapp,代碼行數:17,代碼來源:OkStack.java

示例7: OkHttpStack

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
public OkHttpStack(OkUrlFactory okUrlFactory) {
    this.mUrlRewriter = null;
    this.mSslSocketFactory = null;
    if (okUrlFactory == null) {
        throw new NullPointerException("Client must not be null.");
    }
    this.okUrlFactory = okUrlFactory;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:9,代碼來源:OkHttpStack.java

示例8: OkHttpStack

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
public OkHttpStack(OkHttpClient client) {
    if (client == null) {
        throw new NullPointerException("Client must not be null.");
    }
    client.interceptors().add(new GzipRequestInterceptor());
    mFactory = new OkUrlFactory(client);
}
 
開發者ID:PengSen,項目名稱:VoV,代碼行數:8,代碼來源:OkHttpStack.java

示例9: openFile

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
		throws FileNotFoundException {
	ParcelFileDescriptor[] pipe = null;

	String url = uri.getPath();

	try {
		String decodedUrl = URLDecoder.decode(url.replaceFirst("/", ""),
				"UTF-8");
		pipe = ParcelFileDescriptor.createPipe();

		OkHttpClient httpClient = PopcornApplication.getHttpClient();
		OkUrlFactory factory = new OkUrlFactory(httpClient);
		HttpURLConnection connection = factory.open(new URL(decodedUrl));

		new TransferThread(connection.getInputStream(),
				new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]))
				.start();
	} catch (IOException e) {
		Log.e(getClass().getSimpleName(), "Exception opening pipe", e);
		throw new FileNotFoundException("Could not open pipe for: "
				+ uri.toString());
	}

	return (pipe[0]);
}
 
開發者ID:PTCE,項目名稱:popcorn-android,代碼行數:28,代碼來源:RecommendationContentProvider.java

示例10: getHttpURLConnection

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
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;
}
 
開發者ID:mxiao6,項目名稱:Tower-develop,代碼行數:13,代碼來源:NetworkUtils.java

示例11: OkHttpStack

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
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);
}
 
開發者ID:missmisslonely,項目名稱:fakeweibo,代碼行數:9,代碼來源:OkHttpStack.java

示例12: createConnection

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
protected HttpURLConnection createConnection(String url) throws IOException {
    OkHttpClient okHttpClient = new OkHttpClient();
    //okHttpClient.setSslSocketFactory(HttpRequest.getTrustedFactory());
    //okHttpClient.setHostnameVerifier(HttpRequest.getTrustedVerifier());
    //okHttpClient.networkInterceptors().add(new StethoInterceptor());
    HttpURLConnection conn = new OkUrlFactory(okHttpClient).open(new URL(url));
    return conn;
}
 
開發者ID:yongjhih,項目名稱:facebook-content-provider,代碼行數:9,代碼來源:NetworkPipeContentProvider.java

示例13: getHttpURLConnection

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
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", MapboxConstants.USER_AGENT);
    return connection;
}
 
開發者ID:RoProducts,項目名稱:rastertheque,代碼行數:13,代碼來源:NetworkUtils.java

示例14: generateDefaultOkUrlFactory

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
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);
        }
 
開發者ID:AAverin,項目名稱:android-skeleton-project,代碼行數:15,代碼來源:NetworkManager.java

示例15: OkHttpStack

import com.squareup.okhttp.OkUrlFactory; //導入依賴的package包/類
public OkHttpStack(OkHttpClient client) {
    if (client == null) {
        throw new NullPointerException("Client must not be null.");
    }

    try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, null, null);
        client.setSslSocketFactory(sslContext.getSocketFactory());
    } catch (Exception e) {
        throw new AssertionError(); // The system has no TLS. Just give up.
    }

    mFactory = new OkUrlFactory(client);
}
 
開發者ID:spoqa,項目名稱:battery,代碼行數:16,代碼來源:OkHttpStack.java


注:本文中的com.squareup.okhttp.OkUrlFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。