All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avito.http.RequestBodies.kt Maven / Gradle / Ivy

Go to download

Collection of infrastructure libraries and gradle plugins of Avito Android project

There is a newer version: 2023.22
Show newest version
package com.avito.http

import com.avito.http.internal.isPlaintext
import okhttp3.RequestBody
import okio.Buffer
import java.nio.charset.Charset

private val utf8 = Charset.forName("UTF-8")

public fun RequestBody.toPlainText(): String? {
    val buffer = Buffer()
    writeTo(buffer)

    var charset: Charset? = utf8

    val contentType = contentType()
    if (contentType != null) {
        charset = contentType.charset(utf8)
    }

    return if (buffer.isPlaintext()) {
        buffer.readString(charset!!)
    } else {
        null
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy