okio

Downloading files using OkHttp, Okio and RxJava

杀马特。学长 韩版系。学妹 提交于 2019-12-04 21:57:09
I'm trying to download files using OkHttp and writing to disk with Okio. Also I've created an rx observable for this process. It is working, however it is noticeably slower than what I had previously used (Koush's Ion library). Here's how I create the observable: public Observable<FilesWrapper> download(List<Thing> things) { return Observable.from(things) .map(thing -> { File file = new File(getExternalCacheDir() + File.separator + thing.getName()); if (!file.exists()) { Request request = new Request.Builder().url(thing.getUrl()).build(); Response response; try { response = client.newCall

Download progress with RxJava, OkHttp and Okio in Android

谁都会走 提交于 2019-12-02 17:17:32
In our app I download an image file with this code. I need to show download progress( downloaded bytes in percentage ) on UI. How I can get download progress in this code? I searched for solution, but still can't manage to do it on my own. Observable<String> downloadObservable = Observable.create( sub -> { Request request = new Request.Builder() .url(media.getMediaUrl()) .build(); Response response = null; try { response = http_client.newCall(request).execute(); if (response.isSuccessful()) { Log.d(TAG, "response.isSuccessful()"); String mimeType = MimeTypeMap.getFileExtensionFromUrl(media

How to use Retrofit and SimpleXML together in downloading and parsing an XML file from a site?

大城市里の小女人 提交于 2019-11-27 11:36:25
I just started working with Retrofit. I am working on a project that uses SimpleXML. Can somebody provide me an example in which one fetches an XML from a site e.g. http://www.w3schools.com/xml/simple.xml " and reads it out? vandus You will create an interface as a new class in your project: public interface ApiService { @GET("/xml/simple.xml") YourObject getUser(); } Then in your activity you will call the following: RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint("http://www.w3schools.com") .setConverter(new SimpleXmlConverter()) .build(); ApiService apiService = restAdapter

Tracking progress of multipart file upload using OKHTTP

拥有回忆 提交于 2019-11-27 06:08:48
I am trying to implement a a progress bar to indicate the progress of a multipart file upload. I have read from a comment on this answer - https://stackoverflow.com/a/24285633/1022454 that I have to wrap the sink passed to the RequestBody and provide a callback that tracks the bytes moved. I have created a custom RequestBody and wrapped the sink with a CustomSink class, however through debugging I can see that the bytes are being written by RealBufferedSink ln 44 and the custom sink write method is only run once, not allowing me to track the bytes moved. private class CustomRequestBody extends

How to use Retrofit and SimpleXML together in downloading and parsing an XML file from a site?

拈花ヽ惹草 提交于 2019-11-26 15:38:39
问题 I just started working with Retrofit. I am working on a project that uses SimpleXML. Can somebody provide me an example in which one fetches an XML from a site e.g. http://www.w3schools.com/xml/simple.xml" and reads it out? 回答1: You will create an interface as a new class in your project: public interface ApiService { @GET("/xml/simple.xml") YourObject getUser(); } Then in your activity you will call the following: RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint("http://www

Tracking progress of multipart file upload using OKHTTP

孤者浪人 提交于 2019-11-26 12:53:50
问题 I am trying to implement a a progress bar to indicate the progress of a multipart file upload. I have read from a comment on this answer - https://stackoverflow.com/a/24285633/1022454 that I have to wrap the sink passed to the RequestBody and provide a callback that tracks the bytes moved. I have created a custom RequestBody and wrapped the sink with a CustomSink class, however through debugging I can see that the bytes are being written by RealBufferedSink ln 44 and the custom sink write