本文整理汇总了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);
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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]);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}