当前位置: 首页>>代码示例>>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;未经允许,请勿转载。