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
1
vote
1 answer

Okio explicit termination method close not called

I have following code in my Android app running in strict mode. I see following exception being thrown. I am closing the response item returned by the code below by invoking response.close() fwiw I am using okio 1.10 and okhttp3 version 3.4.1 Am I…
Subodh Nijsure
  • 3,305
  • 5
  • 26
  • 45
1
vote
1 answer

Creating WAV file with Okio

My system needs to create a single WAV file using bytes of an array of WAV files. Currently it uses Okio to read and write the data on buffers, and then, write the data on a final file. I'm following this document and this stack overflow…
Pedro Paulo Amorim
  • 1,838
  • 2
  • 27
  • 50
1
vote
0 answers

Reading UTF String on okio that was sent using DataOutputStream writeUTF() method

I am using okhttp and okio on my current android project to get and read some binary stream I am sending , within the stream I am sending some UTF values using the method DataOutputStream.writeUTF(). the "okhttp" gives you 2 options either get the…
A.Alqadomi
  • 1,529
  • 3
  • 25
  • 33
1
vote
1 answer

Reading OKIO stream twice

I am using OKHTTP for networking and currently get a charStream from response.charStream() which I then pass for GSON for parsing. Once parsed and inflated, I deflate the model again to save to disk using a stream. It seems like extra work to have…
FriendlyMikhail
  • 2,857
  • 23
  • 39
1
vote
0 answers

Problems decoding an image file copied using Okio and ContentResolver.openInputStream()

I have the following setup: a gallery image gets selected using Intent.ACTION_GET_CONTENT intent and then in onActivityResult() I get an Intent with an Uri. Next I try to do the following: Source source =…
dimsuz
  • 8,969
  • 8
  • 54
  • 88
1
vote
2 answers

Opening the connection using okhttp

I'm trying to Open the connection using okhttp. something like, urlConnection = client.open(url); does not work with the new ok-http.jar file. It was working with 1.5.x of okhttp version Any suggestions? Thanks
user2334150
  • 11
  • 1
  • 2
0
votes
0 answers

org.apache.hadoop/hadoop-client-api always including com.squareup.okio 1.6.0 version

We have a CVE reported CVE-2023-3635 which requires the package com.squareup.okio_okio to be upgraded to 3.4.0. I have explicitly pinned this version in pom.xml ex: com.squareup.okio
Gary
  • 31
  • 4
0
votes
1 answer

Are Retrofit and Okhttp abandoned?

Retrofit Version 2.9.0 (2020-05-20) Okhttp Version 4.10.0 (2022-06-12) Version 5.0.0-alpha.11 (2022-12-24) Retrofit has 36 opened pull request and 147 opened bug, Okhttp 9 opened pull request and 161 opened bug. I know that this question hurts,…
Alessandro Scarozza
  • 4,273
  • 6
  • 31
  • 39
0
votes
1 answer

How do I check if a path is a directory using Okio?

I am using Okio in Kotlin/Native. How do I check if a path (for example /path/to/directory) denotes a directory? The scope of the check has to involve using the file system to check if the path denotes a file or a…
xdevs23
  • 3,824
  • 3
  • 20
  • 33
0
votes
2 answers

How to check if a path is inside another path using Okio?

I am using Okio in Kotlin/Native and I would like to check if one path is inside another path. Although there is a equal/greater than/less than operator, it looks like it only compares the…
xdevs23
  • 3,824
  • 3
  • 20
  • 33
0
votes
0 answers

Okio and other issues

I am trying to execute this set of code but when I do I get these errors. I can't find anything on "okio" let alone how to fix the issue. See below for the list of the problems that show up each time I run Java. I know the codes are correct as this…
0
votes
0 answers

How to handle out of memory exception in okio sink?

I have a progress emitting request body.. class ProgressEmittingRequestBody( private val delegate: RequestBody, private val progressListener: ProgressListener, ) : RequestBody() { override fun contentType(): MediaType? =…
Diken Mhrz
  • 327
  • 2
  • 14
0
votes
1 answer

Can okhttp response body data be read after the call was cancelled?

In okhttp interceptor code, is it possible, after a call was cancelled, to read whatever partial response data might have been returned by the server? The end goal is to cache partial content so that we can later resume with an http range request.
Roger
  • 563
  • 5
  • 12
0
votes
0 answers

How to store a loaded asset to a file in app data folder

I have a file loaded from assets with the next code I can access: context.resources.assets.open("abi/${Build.SUPPORTED_ABIS[0]}/lib.so") But now I need to store inside my app data folder using the library Okio from square,…
Víctor Martín
  • 3,352
  • 7
  • 48
  • 94
0
votes
1 answer

Okio source cannot be read inside a Kotlin Coroutine

I am trying to generate a Bitmap from an Okio source using this implementation val file = /* ... */ Okio.source(file).use { CoroutineScope(Dispatchers.IO).launch { Okio.buffer(source).use { bufferedSource -> val bitmap…
Nicolás Arias
  • 1,053
  • 1
  • 12
  • 29