package ch.rmy.android.http_shortcuts.extensions

import android.content.Context
import android.net.Uri
import ch.rmy.android.http_shortcuts.exceptions.ResponseTooLargeException
import ch.rmy.android.http_shortcuts.utils.SizeLimitedReader
import java.io.BufferedReader
import java.io.InputStreamReader

private const val BUFFER_SIZE = 16384

fun Uri.readIntoString(context: Context, limit: Long): String =
    InputStreamReader(context.contentResolver.openInputStream(this))
        .use { reader ->
            try {
                BufferedReader(SizeLimitedReader(reader, limit), BUFFER_SIZE)
                    .use(BufferedReader::readText)
            } catch (e: SizeLimitedReader.LimitReachedException) {
                throw ResponseTooLargeException(e.limit)
            }
        }

package ch.rmy.android.http_shortcuts.extensions

import android.content.Context
import android.net.Uri
import ch.rmy.android.http_shortcuts.utils.SizeLimitedReader
import java.io.BufferedReader
import java.io.InputStreamReader

private const val BUFFER_SIZE = 16384

fun Uri.readIntoString(context: Context, limit: Long): String =
    InputStreamReader(context.contentResolver.openInputStream(this))
        .use { reader ->
            BufferedReader(SizeLimitedReader(reader, limit), BUFFER_SIZE)
                .use(BufferedReader::readText)
        }

Handle correct exception for large responses
Bugfix: Handle correct exception for large responses

Waboodoo/HTTP-Shortcuts,Waboodoo/HTTP-Shortcuts,Waboodoo/HTTP-Shortcuts