Questions tagged [okio]

Okio is a library that complements java.io and java.nio to make it easier to access, store, and process data.

Okio is a library that complements java.io and java.nio to make it easier to access, store, and process data. It is built around two types:

ByteString is an immutable sequence of bytes. For character data, String is fundamental.

ByteString is String's long-lost brother, making it easy to treat binary data as a value. This class is ergonomic: it knows how to encode and decode itself as hex, base64, and UTF-8.

Buffer is a mutable sequence of bytes. Like ArrayList, you don't need to size your buffer in advance. You read and write buffers as a queue: write data to the end and read it from the front. There's no obligation to manage positions, limits, or capacities.

Internally, ByteString and Buffer do some clever things to save CPU and memory. If you encode a UTF-8 string as a ByteString, it caches a reference to that string so that if you decode it later, there's no work to do.

Buffer is implemented as a linked list of segments. When you move data from one buffer to another, it reassigns ownership of the segments rather than copying the data across. This approach is particularly helpful for multithreaded programs: a thread that talks to the network can exchange data with a worker thread without any copying or ceremony.

84 questions
0
votes
1 answer

How can I handle long response in OkHttp Java?

I am attempting to use okhttp-3.12.0 and okio-1.9.0 in my JAVA project to make POST call to a web service. I am able to successfully create the record, however, the web service returns a response of data type long which then throws a…
0
votes
1 answer

Okhttp3 jar missing okio?

I am trying to make a simple Java program to upload a bunch of images I have to imgur. But I am running into problem after problem and cannot just get okhttp to work. At this point the time I have spent trying to solve this has been way longer than…
parakeet
  • 53
  • 6
0
votes
1 answer

How read a file in chunks correctly using Okio?

I'm trying to consume a file upload API that requires the file to be uploaded in chunks of a size in bytes that it specifies from a previous API call. So.... for example if the file is small it will say upload it in chunks of 1MB (in bytes) but it…
mez.pahlan
  • 1,053
  • 2
  • 11
  • 25
0
votes
1 answer

How to rollback/revert IO operations incase of exceptions during writing? - Java

Is it possible to roll back the current IO operation incase of any exceptions during writing? I'm trying to write a UTF-8 string to a file with Okio library using the below expression file.sink().buffer().writeUtf8(fileContent).close() It works for…
Vijay
  • 545
  • 1
  • 5
  • 15
0
votes
1 answer

Cancel downloading a File with OkHttp3

I want to cancel downloaded File with Okio ,it runs in AsyncTaks When I cancel Asynctask downloadedFilerunTask.cancel() I can get rid of downlaoding process with using break, but downloaded process not cancelled,how can I cancel downloaded stream…
Diego
  • 937
  • 8
  • 24
0
votes
0 answers

When Downloading File Show ProgressBar in Okio

I downloaded file using OKHTTP3 library, and then I saved file to disk using Okio.buffer,but I want to show progressBar when downloading continously,how can I do this with Okio? try { okhttp3.Response response =…
Diego
  • 937
  • 8
  • 24
0
votes
0 answers

How to resolve Retrofit write from Timimg Out when POSTing large requests

My Android application has started failing as follows when POSTing large (17048 Bytes) API requests 2019-09-20 08:20:01.198 15645-15862/org.aaa.bbb.ccc.mycompany D/GraphqlNetworkControlle: mutation…
Hector
  • 4,016
  • 21
  • 112
  • 211
0
votes
0 answers

Downloading pdf with okhttp and okio

I'm facing some problems downloading pdf inside my app. Some pdfs cannot be opened, because of the following message (invalid format) Error = cannot create document: File not in PDF format or corrupted Code for Okhttp setup: val file =…
pawlinsky
  • 420
  • 1
  • 6
  • 18
0
votes
1 answer

How to make a post request using Okio?

I'm using Okio to download a file....with my request i'm sending some parameters, but since I wasn't getting my file and I was able to log my request and this is what is see: Why tags is null? that means that the parameters are null Request:…
Pedro
  • 1,440
  • 2
  • 15
  • 36
0
votes
1 answer

Okio's BufferedSource request() only fires once

I'm downloading a file using a Retrofit2 implementation of a REST API, per the nice tutorial at https://futurestud.io/tutorials/retrofit-2-how-to-download-files-from-server. My API interface declares the @GET as @Streaming, and indeed when I read…
QED
  • 9,803
  • 7
  • 50
  • 87
0
votes
1 answer

How to decode a http request packet with okio/okhttp

Can I use Okio and/or OkHTTP to decode a packet read from ParcelFileDescriptor ? I'm trying to write a VpnService based ad-blocker on android. I've found a few open source projects using VpnService (NetGuard, NetKnight), so I could learn from…
DevDengChao
  • 198
  • 15
0
votes
0 answers

How do I import ok.io into android studio locally?

I have been trying to use ok.io, (version 1.14.1), locally in my project and it's been quite a struggle getting through the gradle requirements. My project requires that I include the source locally. I have managed to import the module but when…
angryITguy
  • 9,332
  • 8
  • 54
  • 82
0
votes
0 answers

IllegalArgumentException when running retrofit api unit test

I am getting the below IllegalArgumentException when trying to run my unit test: java.lang.IllegalArgumentException: in == null at okio.Okio.source(Okio.java:128) at okio.Okio.source(Okio.java:124) at…
oznecro
  • 457
  • 5
  • 16
0
votes
0 answers

How to use OkIo Buffer as RequestBody in Okhttp

I'm developing anAndroid SDK and i have to send a post request with raw audio bytes from mic as being generated, I'm currently witting bytes into an OkIo Buffer like this public void onAudioData(byte[] data, int size) { …
miibpa
  • 235
  • 1
  • 4
  • 15
0
votes
2 answers

Retrofit 2 dependencies issue

I am using retrofit 2 library for network calls.Project is not builing up even after adding dependencies. I have attached the screenshot.