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
2
votes
3 answers

Abnormal CPU usage - Okio Watchdog

I am using OkHttp (first the original verison, then I upgraded to OkHttp3), some users of my App have been reporting significant battery life loss when the App isn't running. I ran a profiler and this is the result: As you can see, Okio Watchdog is…
Knossos
  • 15,802
  • 10
  • 54
  • 91
2
votes
1 answer

java.lang.VerifyError when using OkHttp

I use this code in my android studio project: HttpUrl url = new HttpUrl.Builder().scheme("http").host("www.somesite.com") .addPathSegment("kontakt") …
Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166
1
vote
1 answer

Access files in commonMain resources directory with OKIO - Kotlin Multiplatform

I wanted to include into my app (Kotlin Multiplatform Mobile) iOS + Android a .json file to be parsed and saved into Realm DB on the first launch using .initialData{}. I use expect/actual pattern and try to access file in…
Igro182
  • 17
  • 7
1
vote
1 answer

Okio vs java.io performance

I read the following blog: https://medium.com/@jerzy.chalupski/a-closer-look-at-the-okio-library-90336e37261 It is said that" the Sinks and Sources are often connected into a pipe. Smart folks at Square realized that there’s no need to copy the data…
唐子玄
  • 11
  • 2
1
vote
1 answer

Is it possible to run okio in javascript

I have query about okio , is it possible to run the okio in javascript, is there is any okio package available for javascript ? i got this query due to this commands in release notes of okio. Version 3.0.0-alpha.3¶ 2021-04-06 New: Move…
sreeramu
  • 1,213
  • 12
  • 19
1
vote
2 answers

How to implement seek() function in BufferedSink (or BufferedSource) in OKHttp?

How to implement seek() function in BufferSink (or BufferedSource) in OKHttp? We all know that in Java, the RandomAccessFile class has a method seek(long), which enable us to start reading/writing a file from a specific position, and the bytes…
vainquit
  • 491
  • 6
  • 13
1
vote
0 answers

BadPaddingException: pad block corrupted while trying to decode

I'm facing with BadPaddingException while I'm trying to decode InputStream. I was able to encode/decode OutputStream/InputStream while I'm using jackson but when I tried to do with Okio it throws BadPaddingException. getEncodeStream() and…
M D
  • 39
  • 1
  • 7
1
vote
1 answer

Efficient okio Source backed by an already allocated ByteString?

When using the OkHttp Websocket the listener uses a ByteString to provide the binary payload to the application. I want to feed these bytes into some code which takes a okio.Source (in this particular case, a GzipSource), but I cannot find any good…
Johan Ström
  • 105
  • 6
1
vote
1 answer

Writing file on Android with Okio

Hi All I'm reading raw audio from Android device and I want to write it into a file using Okio like this: BufferedSink sink = Okio.buffer(Okio.sink(file)); I have a callback to retrieve audio data, and then write the audio data to…
miibpa
  • 235
  • 1
  • 4
  • 15
1
vote
0 answers

can't find referenced class issue?

We are using shopify Android buy sdk to develop this app compile 'com.shopify.mobilebuysdk:buy3:3.1.1' compile 'com.shopify.mobilebuysdk:buy3-pay-support:1.0.2' Error and Warning warning: com.facebook.cache.common.cacheerrorlogger: can't find…
Midhilaj
  • 4,905
  • 9
  • 45
  • 88
1
vote
0 answers

Circular BufferedSink using Okio

I'm using an Okio Pipe to read and send audio bytes from Android device mic, and I'd like to have a kind of fixed size pre-buffer of audio, removing the first received bytes when the buffer is full and adding the new ones. Does anybody know if I can…
miibpa
  • 235
  • 1
  • 4
  • 15
1
vote
2 answers

Okio/Okhttp download file using BufferedSink and decode Base64 without having whole file in memory multiple times

Got a bit of a problem atm. for my "inapp"-update im downloading the new base64 encoded .apk from my webspace. I have the functionality pretty much down, this is the code without decoding. public void onResponse(Call call, Response…
p_d
  • 101
  • 1
  • 12
1
vote
1 answer

okhttp3 ResponseBody to String Issue

i'm working a spark app (language > scala) , and using okhttp3 3.6.0 ver. An error occurs when calling the below method. val client = new OkHttpClient() .... val response = client.newCall(request).execute() response.body().string() Exception…
hyeyoung
  • 87
  • 10
1
vote
1 answer

An exception:gzip finished without exhausting source, about Okhttp,okio

I encountered this error while using okhttp. Please help me analyze the reason for the error and give me a solution @Override public long read(Buffer sink, long byteCount) throws IOException { if (byteCount < 0) throw new…
Arison
  • 15
  • 7
1
vote
0 answers

java.lang.NoClassDefFoundError: Failed resolution of: Lokio/ForwardingTimeout

I am using a android project as library, which are using the following library added as a jar okhttp-2.2.0.jar okhttp-urlconnection-2.2.0.jar okio-1.2.0.jar retrofit-1.9.0.jar And in my main project I am using the following library compile…
Mithun Sarker Shuvro
  • 3,902
  • 6
  • 32
  • 64