List of usage examples for com.squareup.okhttp OkHttpClient OkHttpClient
public OkHttpClient()
From source file:com.facebook.stetho.okhttp.StethoInterceptorTest.java
License:Open Source License
@Before public void setUp() { PowerMockito.mockStatic(NetworkEventReporterImpl.class); mMockEventReporter = Mockito.mock(NetworkEventReporter.class); Mockito.when(mMockEventReporter.isEnabled()).thenReturn(true); PowerMockito.when(NetworkEventReporterImpl.get()).thenReturn(mMockEventReporter); mInterceptor = new StethoInterceptor(); mClientWithInterceptor = new OkHttpClient(); mClientWithInterceptor.networkInterceptors().add(mInterceptor); }
From source file:com.felkertech.n.cumulustv.activities.MainActivity.java
public void moreClick() { String[] actions = new String[] { getString(R.string.settings_browse_plugins), getString(R.string.settings_switch_google_drive), getString(R.string.settings_refresh_cloud_local), getString(R.string.settings_view_licenses), getString(R.string.settings_reset_channel_data), getString(R.string.settings_about)/*, getString(R.string.about_mlc)*/ };//from w ww. j a v a 2 s . co m new MaterialDialog.Builder(this).title(R.string.more_actions).items(actions) .itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) { switch (i) { case 0: ActivityUtils.browsePlugins(MainActivity.this); break; case 1: ActivityUtils.switchGoogleDrive(MainActivity.this, gapi); break; case 2: ActivityUtils.readDriveData(MainActivity.this, gapi); break; case 3: ActivityUtils.oslClick(MainActivity.this); break; case 4: ActivityUtils.deleteChannelData(MainActivity.this, gapi); break; case 5: ActivityUtils.openAbout(MainActivity.this); break; case 6: new MaterialDialog.Builder(MainActivity.this).title(R.string.about_mlc) .content(R.string.about_mlc_summary).positiveText(R.string.about_mlc_issues) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); Intent gi = new Intent(Intent.ACTION_VIEW); gi.setData(Uri .parse("https://bitbucket.org/fleker/mlc-music-live-channels")); startActivity(gi); } }).show(); case 13: final OkHttpClient client = new OkHttpClient(); new Thread(new Runnable() { @Override public void run() { Request request = new Request.Builder() .url("http://felkerdigitalmedia.com/sampletv.xml").build(); Response response = null; try { response = client.newCall(request).execute(); // Log.d(TAG, response.body().string().substring(0,36)); String s = response.body().string(); List<Program> programs = XMLTVParser.parse(s); /*Log.d(TAG, programs.toString()); Log.d(TAG, "Parsed "+programs.size()); Log.d(TAG, "Program 1: "+ programs.get(0).getTitle());*/ } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } } }).start(); break; } } }).show(); }
From source file:com.frostwire.http.HttpClient.java
License:Open Source License
private static OkHttpClient buildDefaultClient() { OkHttpClient c = new OkHttpClient(); c.setFollowRedirects(true);/*w w w .j a va 2 s .co m*/ c.setFollowSslRedirects(true); c.setConnectTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); c.setReadTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); c.setWriteTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); c.setHostnameVerifier(buildHostnameVerifier()); c.setSslSocketFactory(buildSSLSocketFactory()); c.interceptors().add(new GzipInterceptor()); return c; }
From source file:com.fullcontact.api.libs.fullcontact4j.http.FCUrlClient.java
License:Apache License
private static OkHttpClient generateDefaultOkHttp() { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); return client; }
From source file:com.geek.geekmall.utils.ImageLoader.java
License:Apache License
/** * Create avatar helper//from ww w . j ava2 s . c o m * * @param context */ private ImageLoader(final Context context) { this.context = context; OkHttpClient client = new OkHttpClient(); // Install an HTTP cache in the application cache directory. File cacheDir = new File(SDCardUtils.getSDCardPath(), "geekmall"); Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE); client.setCache(cache); p = new Picasso.Builder(context).downloader(new OkHttpDownloader(client)).build(); // p.setIndicatorsEnabled(true); // p.setLoggingEnabled(true); bitmapUtils = new BitmapUtils(context, cacheDir.getPath(), 0.15f, DISK_CACHE_SIZE); mUniverImageLoader = com.nostra13.universalimageloader.core.ImageLoader.getInstance(); ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(context) .diskCache(new UnlimitedDiskCache(cacheDir)).diskCacheSize(500 * 1024 * 1024) .diskCacheFileCount(500).writeDebugLogs() // Remove for release app .build(); mUniverImageLoader.init(configuration); }
From source file:com.github.airk.tool.sobitmap.NetworkHunter.java
License:Apache License
NetworkHunter() { super();//from w ww. j a v a 2 s .c o m client = new OkHttpClient(); client.setConnectTimeout(15000, TimeUnit.MILLISECONDS); client.setReadTimeout(20000, TimeUnit.MILLISECONDS); client.setWriteTimeout(20000, TimeUnit.MILLISECONDS); }
From source file:com.github.arven.rest.AccountServiceTests.java
public AccountServiceTests() { client = new OkHttpClient(); map = new ObjectMapper(); }
From source file:com.github.baoti.pioneer.data.DataModule.java
License:Apache License
static OkHttpClient createOkHttpClient(Application app) { OkHttpClient client = new OkHttpClient(); // Install an HTTP cache in the application cache directory. File cacheDir = new File(app.getCacheDir(), "http"); Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE); client.setCache(cache);/*w w w . ja va2 s . c o m*/ return client; }
From source file:com.github.kskelm.baringo.BaringoClient.java
License:Open Source License
private RetrofittedImgur create() { client = new OkHttpClient(); client.interceptors().add(new ImgurInterceptor()); HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(Level.BODY); client.interceptors().add(logging);// w w w . j ava2s. c om final GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Date.class, new DateAdapter()); // create the various domain-specific // services, giving them a chance to register any Gson // type adapters they're going to need. this.acctSvc = new AccountService(this, gsonBuilder); this.albSvc = new AlbumService(this, gsonBuilder); this.imgSvc = new ImageService(this, gsonBuilder); this.galSvc = new GalleryService(this, gsonBuilder); this.comSvc = new CommentService(this, gsonBuilder); this.cusGalSvc = new CustomGalleryService(this, gsonBuilder); this.topSvc = new TopicService(this, gsonBuilder); this.cnvSvc = new ConversationService(this, gsonBuilder); this.noteSvc = new NotificationService(this, gsonBuilder); this.memeSvc = new MemeService(this, gsonBuilder); this.authSvc = new AuthService(this, clientId, clientSecret); // build the gson object final Gson gson = gsonBuilder.create(); // start up the API client GsonConverterFactory gcf = GsonConverterFactory.create(gson); Retrofit retrofit = new Retrofit.Builder().baseUrl(apiEndpoint).addConverterFactory(gcf).client(client) .build(); return retrofit.create(RetrofittedImgur.class); }
From source file:com.github.kskelm.baringo.ImageService.java
License:Open Source License
/** * Given an image id and an output stream, download the image * and write it to the stream. It is the caller's responsibility * to close everything./* w w w . j av a 2 s. c o m*/ * <p> * NOTE: This is synchronous. * <p> * <b>ACCESS: ANONYMOUS</b> * @param imageLink the image link to download (could be a thumb too) * @param outStream an output stream to write the data to * @return the number of bytes written * @throws IOException could be anything really * @throws BaringoApiException Imgur didn't like something */ public long downloadImage(String imageLink, OutputStream outStream) throws IOException, BaringoApiException { Request request = new Request.Builder().url(imageLink).build(); OkHttpClient client = new OkHttpClient(); com.squareup.okhttp.Response resp = client.newCall(request).execute(); if (resp.code() != 200 || !resp.isSuccessful()) { throw new BaringoApiException(request.urlString() + ": " + resp.message(), resp.code()); } // if if (resp.body() == null) { throw new BaringoApiException("No response body found"); } // if InputStream is = resp.body().byteStream(); BufferedInputStream input = new BufferedInputStream(is); byte[] data = new byte[8192]; // because powers of two are magic long total = 0; int count = 0; while ((count = input.read(data)) != -1) { total += count; outStream.write(data, 0, count); } // while return total; }