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

Okhttp NoClassDefFoundError

I am using OkHttp 2.0.0 jar in my android application on eclipse. As OkHttp is now dependent on Okio library, I also added Okio 1.0.0 jar in my project.The project compiles fine with no compilation errors but when I run on my android device, it…
Kishu Agarwal
  • 378
  • 3
  • 8
4
votes
0 answers

OkHttp3 socket failed: EMFILE (Too many open files)

I am using Retrofit 2.0.0. OkHttp 3.1.2. Some of my users are getting the following exception: java.net.SocketException: socket failed: EMFILE (Too many open files) at libcore.io.IoBridge.socket(IoBridge.java:619) ~[na:0.0] at…
danidin
  • 371
  • 2
  • 17
4
votes
1 answer

Downloading files using OkHttp, Okio and RxJava

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…
user3307102
  • 305
  • 1
  • 4
  • 15
3
votes
1 answer

Okio Throttler integration with OkHttp

My team is suffering from this issue with slack integration to upload files, so following the comments in that issue I would like to throttle the requests in our Kotlin implementation. I am trying to integrate Okio Throttler within an OkHttp…
BugsBunnyBR
  • 1,004
  • 9
  • 19
3
votes
0 answers

Cannot resolve okhttp request.builder()

I have added my maven dependency as in my pom.xml file.
user2724026
  • 31
  • 1
  • 3
3
votes
1 answer

Is it mandatory to include okio if an app wants to use okhttp3?

I have included okhttp3 and tested PATCH and DELETE methods in android versions less than LOLLIPOP (api 21). I did not include Okio and it worked fine. But, in the okhttp site they mention the following: You'll also need Okio, which OkHttp uses for…
garnet
  • 551
  • 5
  • 12
3
votes
1 answer

Fail to run app using OkHttp on 'Android L' emulator

Our app uses latest version of OkHttp (2.0.0) + Okio (1.0.0) + Picasso (2.3.2) and I wanted to try it out on the new "Android L" emulator (Intel) and it gets installed but when loading the app i get this: 06-27 09:47:16.214: E/AndroidRuntime(2815):…
Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
2
votes
2 answers

Okio native/multiplatform default paths

How do one access the common default paths using okio? The paths I'm specifically interested in are: Application directory (location of the executable(s) that are being run) Working directory (where the app is run from, seems that it's relative to…
Rohde Fischer
  • 1,248
  • 2
  • 10
  • 32
2
votes
1 answer

Does okio FileHandle have something similar to RandomAccessFile.getchannel() in java?

My problem is if the buffer is split, I want to make it contagious. In java, I used FileChannel for this purpose.
2
votes
1 answer

Efficient mapping of byte buffers

I'm looking into the source code for Okio in order to understand efficient byte transferring better, and as a toy example made a little ForwardingSource which inverts individual bytes as they come along. For example, it transforms (unsigned) 0b1011…
Maarten
  • 6,894
  • 7
  • 55
  • 90
2
votes
1 answer

Convert OutputStream to Okio Source

I am trying to find elegant way to convert OutputStream produced by bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream) method to Okio's Source / InputStream (needed to further manipulate data - encoding) while maintaining the data buffer. I…
Bresiu
  • 2,123
  • 2
  • 19
  • 31
2
votes
3 answers

Testing OkHttp with MockWebServer and MockResponse with a Buffer body

I am trying to test some download code involving OkHttp3 and failing miserably. Goal: test downloading an image file and verify it worked. Platform: Android. This code is working in production but the test code just isn't making any sense. Prod…
AutonomousApps
  • 4,229
  • 4
  • 32
  • 42
2
votes
4 answers

Spark and Influx: OKIO conflict

I'm running a job on Spark Yarn and trying to emit messages to Influx DB but I'm crashing on an okio conflict: 22:17:54 ERROR ApplicationMaster - User class threw exception: java.lang.NoSuchMethodError:…
alexP_Keaton
  • 349
  • 5
  • 18
2
votes
1 answer

How do I encrypt an Okio BufferedSource?

Due to HIPAA requirements, I need to encrypt data at rest. I have a BufferedSource that contains data from my api call. The Okio documentation says Sinks may be layered to transform received data, such as to compress, encrypt, throttle, or add…
Spencer
  • 311
  • 1
  • 3
  • 7
2
votes
1 answer

how to solve java.lang.NoClassDefFoundError: okio.Okio?

I have an app that work very well but some times when I add some class and code to my program my app crashes. In my logcat error is for this: 8871-8929/com.example.first E/AndroidRuntime﹕ FATAL EXCEPTION:…
android
  • 37
  • 1
  • 2
  • 5