ultrasonic-app-subsonic-and.../ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/APIDataSource.kt

337 lines
12 KiB
Kotlin
Raw Normal View History

2022-04-03 23:57:50 +02:00
/*
* APIDataSource.kt
* Copyright (C) 2009-2022 Ultrasonic developers
*
* Distributed under terms of the GNU GPLv3 license.
*/
package org.moire.ultrasonic.playback
import android.annotation.SuppressLint
2022-04-03 23:57:50 +02:00
import android.net.Uri
import androidx.core.net.toUri
import androidx.media3.common.C
import androidx.media3.common.PlaybackException
import androidx.media3.common.util.Assertions
import androidx.media3.common.util.Util
import androidx.media3.datasource.BaseDataSource
import androidx.media3.datasource.DataSourceException
import androidx.media3.datasource.DataSpec
import androidx.media3.datasource.HttpDataSource
import androidx.media3.datasource.HttpDataSource.HttpDataSourceException
import androidx.media3.datasource.HttpDataSource.InvalidResponseCodeException
import androidx.media3.datasource.HttpDataSource.RequestProperties
import androidx.media3.datasource.HttpUtil
import androidx.media3.datasource.TransferListener
import com.google.common.net.HttpHeaders
2022-04-04 17:59:12 +02:00
import java.io.IOException
import java.io.InputStream
import java.io.InterruptedIOException
2022-04-03 23:57:50 +02:00
import okhttp3.Call
import okhttp3.ResponseBody
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
import org.moire.ultrasonic.api.subsonic.response.StreamResponse
import org.moire.ultrasonic.api.subsonic.throwOnFailure
import org.moire.ultrasonic.api.subsonic.toStreamResponse
import timber.log.Timber
/**
* An [HttpDataSource] that delegates to Square's [Call.Factory].
*
*
* Note: HTTP request headers will be set using all parameters passed via (in order of decreasing
* priority) the `dataSpec`, [.setRequestProperty] and the default parameters used to
* construct the instance.
*/
@SuppressLint("UnsafeOptInUsageError")
2022-04-04 18:18:52 +02:00
@Suppress("MagicNumber")
2022-04-04 17:59:12 +02:00
open class APIDataSource private constructor(
subsonicAPIClient: SubsonicAPIClient
2022-04-03 23:57:50 +02:00
) : BaseDataSource(true),
HttpDataSource {
2022-04-04 17:59:12 +02:00
/** [DataSource.Factory] for [APIDataSource] instances. */
class Factory(private var subsonicAPIClient: SubsonicAPIClient) : HttpDataSource.Factory {
2022-04-03 23:57:50 +02:00
private val defaultRequestProperties: RequestProperties = RequestProperties()
private var transferListener: TransferListener? = null
2022-04-04 17:59:12 +02:00
override fun setDefaultRequestProperties(
defaultRequestProperties: Map<String, String>
): Factory {
2022-04-03 23:57:50 +02:00
this.defaultRequestProperties.clearAndSet(defaultRequestProperties)
return this
}
/**
* Sets the [TransferListener] that will be used.
*
* See [DataSource.addTransferListener].
*
* @param transferListener The listener that will be used.
* @return This factory.
*/
fun setTransferListener(transferListener: TransferListener?): Factory {
this.transferListener = transferListener
return this
}
fun setAPIClient(newClient: SubsonicAPIClient) {
this.subsonicAPIClient = newClient
}
2022-04-04 17:59:12 +02:00
override fun createDataSource(): APIDataSource {
val dataSource = APIDataSource(
subsonicAPIClient
2022-04-03 23:57:50 +02:00
)
if (transferListener != null) {
dataSource.addTransferListener(transferListener!!)
}
return dataSource
}
}
private val subsonicAPIClient: SubsonicAPIClient = Assertions.checkNotNull(subsonicAPIClient)
2022-04-04 17:59:12 +02:00
private val requestProperties: RequestProperties = RequestProperties()
2022-04-03 23:57:50 +02:00
private var dataSpec: DataSpec? = null
private var response: retrofit2.Response<ResponseBody>? = null
private var responseByteStream: InputStream? = null
private var openedNetwork = false
private var bytesToRead: Long = 0
private var bytesRead: Long = 0
override fun getUri(): Uri? {
2022-04-04 17:59:12 +02:00
return when (response) {
null -> null
2022-04-03 23:57:50 +02:00
else -> response!!.raw().request.url.toString().toUri()
}
}
override fun getResponseCode(): Int {
return if (response == null) -1 else response!!.code()
}
override fun getResponseHeaders(): Map<String, List<String>> {
return if (response == null) emptyMap() else response!!.headers().toMultimap()
}
override fun setRequestProperty(name: String, value: String) {
Assertions.checkNotNull(name)
Assertions.checkNotNull(value)
requestProperties[name] = value
}
override fun clearRequestProperty(name: String) {
Assertions.checkNotNull(name)
requestProperties.remove(name)
}
override fun clearAllRequestProperties() {
requestProperties.clear()
}
2022-04-04 18:18:52 +02:00
@Suppress("LongMethod", "NestedBlockDepth")
2022-04-03 23:57:50 +02:00
@Throws(HttpDataSourceException::class)
override fun open(dataSpec: DataSpec): Long {
2022-04-12 17:12:17 +02:00
Timber.i(
"APIDatasource: Open: %s %s %s",
dataSpec.uri,
dataSpec.position,
dataSpec.toString()
)
2022-04-03 23:57:50 +02:00
this.dataSpec = dataSpec
bytesRead = 0
bytesToRead = 0
transferInitializing(dataSpec)
val components = dataSpec.uri.toString().split('|')
val id = components[0]
val bitrate = components[1].toInt()
val request = subsonicAPIClient.api.stream(id, bitrate, offset = dataSpec.position)
2022-04-03 23:57:50 +02:00
val response: retrofit2.Response<ResponseBody>?
val streamResponse: StreamResponse
2022-04-12 17:12:17 +02:00
2022-04-03 23:57:50 +02:00
try {
this.response = request.execute()
response = this.response
streamResponse = response!!.toStreamResponse()
responseByteStream = streamResponse.stream
} catch (e: IOException) {
throw HttpDataSourceException.createForIOException(
e, dataSpec, HttpDataSourceException.TYPE_OPEN
)
}
streamResponse.throwOnFailure()
val responseCode = response.code()
// Check for a valid response code.
if (!response.isSuccessful) {
if (responseCode == 416) {
val documentSize =
HttpUtil.getDocumentSize(response.headers()[HttpHeaders.CONTENT_RANGE])
if (dataSpec.position == documentSize) {
openedNetwork = true
transferStarted(dataSpec)
return if (dataSpec.length != C.LENGTH_UNSET.toLong()) dataSpec.length else 0
}
}
val errorResponseBody: ByteArray = try {
Util.toByteArray(Assertions.checkNotNull(responseByteStream))
2022-04-04 18:18:52 +02:00
} catch (ignore: IOException) {
2022-04-03 23:57:50 +02:00
Util.EMPTY_BYTE_ARRAY
}
val headers = response.headers().toMultimap()
closeConnectionQuietly()
val cause: IOException? =
2022-04-04 17:59:12 +02:00
if (responseCode == 416) DataSourceException(
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE
) else null
2022-04-03 23:57:50 +02:00
throw InvalidResponseCodeException(
responseCode, response.message(), cause, headers, dataSpec, errorResponseBody
)
}
// If we requested a range starting from a non-zero position and received a 200 rather than a
// 206, then the server does not support partial requests. We'll need to manually skip to the
// requested position.
val bytesToSkip =
if (responseCode == 200 && dataSpec.position != 0L) dataSpec.position else 0
// Determine the length of the data to be read, after skipping.
bytesToRead = if (dataSpec.length != C.LENGTH_UNSET.toLong()) {
dataSpec.length
} else {
val contentLength = response.body()!!.contentLength()
if (contentLength != -1L) contentLength - bytesToSkip else C.LENGTH_UNSET.toLong()
}
openedNetwork = true
transferStarted(dataSpec)
try {
skipFully(bytesToSkip, dataSpec)
} catch (e: HttpDataSourceException) {
closeConnectionQuietly()
throw e
}
return bytesToRead
}
@Throws(HttpDataSourceException::class)
override fun read(buffer: ByteArray, offset: Int, length: Int): Int {
// Timber.d("APIDatasource: Read: %s %s", offset, length)
2022-04-03 23:57:50 +02:00
return try {
readInternal(buffer, offset, length)
} catch (e: IOException) {
throw HttpDataSourceException.createForIOException(
e, Util.castNonNull(dataSpec), HttpDataSourceException.TYPE_READ
)
}
}
override fun close() {
2022-04-12 17:12:17 +02:00
Timber.i("APIDatasource: Close")
2022-04-03 23:57:50 +02:00
if (openedNetwork) {
openedNetwork = false
transferEnded()
closeConnectionQuietly()
}
}
/**
* Attempts to skip the specified number of bytes in full.
*
* @param bytesToSkip The number of bytes to skip.
* @param dataSpec The [DataSpec].
* @throws HttpDataSourceException If the thread is interrupted during the operation, or an error
* occurs while reading from the source, or if the data ended before skipping the specified
* number of bytes.
*/
2022-04-04 18:18:52 +02:00
@Suppress("ThrowsCount")
2022-04-03 23:57:50 +02:00
@Throws(HttpDataSourceException::class)
private fun skipFully(bytesToSkip: Long, dataSpec: DataSpec) {
Merge update build tools #755 by Holger Müller Squashed commit of the following: commit 4491c65b1bfa8f507e9c998878254d61bc52f962 Merge: 51ff716f 77865a14 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 20:50:05 2022 +0200 Merge branch 'develop' into gradle-update commit 51ff716ff5fc8aeb29bc557844747c0127ab1f78 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:52 2022 +0200 fixed lint warning commit 18c31a5704e7d92a04009e2f3ed8f8b9ca28b577 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:35 2022 +0200 fixed lint warning commit 603654c262ed86a66b4127513764cd252cdedfff Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:51 2022 +0200 API is > lollipop ... target removed commit b38a7211de0f206465640d39f8f3189695afbd38 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:07 2022 +0200 new created after fixes commit 4929a526f7e9154755cae2c16fdf431550ae2c2a Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:43:16 2022 +0200 Disable ObsoleteLintCustomCheck commit d0c30f0b6b1d4de2f3c46a166a4f1058223ad3a8 Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:14:06 2022 +0200 Update more libs commit e2fa447bbfbd19119393297c19de0f3237e1ccd3 Merge: d4ead495 ff9c7b24 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 09:47:03 2022 +0200 Merge branch 'develop' into gradle-update commit d4ead49548d11f51dd9c29478972dcd4553d352a Merge: 2dac6a7e 9a73d72f Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 08:50:42 2022 +0200 merged with develop branch commit 2dac6a7e01e4ce5dc619426553ea08743bd9524e Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 21:45:22 2022 +0200 update to android image tag 2022.06.1 commit f3dc259c390c256a66f96c3f003e34daf0fdea14 Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:56:37 2022 +0200 rebuild lint-baseline.xml commit c71bc1212a8570f8ee99a80926c7b3b6036c672f Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:55:00 2022 +0200 removed unneeded cast commit eca136dabedab838e8a02be1a6fd740c4d0934ec Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:58:37 2022 +0200 commit signed commit 540f47633485cddeb4e68626532e54707a66bab8 Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:40:59 2022 +0200 commit signed Signed-off-by: Holger Müller <github@euhm.de> commit 986bd013a49afc56ff8992634f2ce126339eecfc Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:27:20 2022 +0200 push to latest gradle version, set targetSdk to 33 Signed-off-by: tzugen <tzugen@riseup.net>
2022-06-21 21:05:58 +02:00
var bytesToSkipCpy = bytesToSkip
if (bytesToSkipCpy == 0L) {
2022-04-03 23:57:50 +02:00
return
}
val skipBuffer = ByteArray(4096)
try {
Merge update build tools #755 by Holger Müller Squashed commit of the following: commit 4491c65b1bfa8f507e9c998878254d61bc52f962 Merge: 51ff716f 77865a14 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 20:50:05 2022 +0200 Merge branch 'develop' into gradle-update commit 51ff716ff5fc8aeb29bc557844747c0127ab1f78 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:52 2022 +0200 fixed lint warning commit 18c31a5704e7d92a04009e2f3ed8f8b9ca28b577 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:35 2022 +0200 fixed lint warning commit 603654c262ed86a66b4127513764cd252cdedfff Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:51 2022 +0200 API is > lollipop ... target removed commit b38a7211de0f206465640d39f8f3189695afbd38 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:07 2022 +0200 new created after fixes commit 4929a526f7e9154755cae2c16fdf431550ae2c2a Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:43:16 2022 +0200 Disable ObsoleteLintCustomCheck commit d0c30f0b6b1d4de2f3c46a166a4f1058223ad3a8 Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:14:06 2022 +0200 Update more libs commit e2fa447bbfbd19119393297c19de0f3237e1ccd3 Merge: d4ead495 ff9c7b24 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 09:47:03 2022 +0200 Merge branch 'develop' into gradle-update commit d4ead49548d11f51dd9c29478972dcd4553d352a Merge: 2dac6a7e 9a73d72f Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 08:50:42 2022 +0200 merged with develop branch commit 2dac6a7e01e4ce5dc619426553ea08743bd9524e Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 21:45:22 2022 +0200 update to android image tag 2022.06.1 commit f3dc259c390c256a66f96c3f003e34daf0fdea14 Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:56:37 2022 +0200 rebuild lint-baseline.xml commit c71bc1212a8570f8ee99a80926c7b3b6036c672f Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:55:00 2022 +0200 removed unneeded cast commit eca136dabedab838e8a02be1a6fd740c4d0934ec Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:58:37 2022 +0200 commit signed commit 540f47633485cddeb4e68626532e54707a66bab8 Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:40:59 2022 +0200 commit signed Signed-off-by: Holger Müller <github@euhm.de> commit 986bd013a49afc56ff8992634f2ce126339eecfc Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:27:20 2022 +0200 push to latest gradle version, set targetSdk to 33 Signed-off-by: tzugen <tzugen@riseup.net>
2022-06-21 21:05:58 +02:00
while (bytesToSkipCpy > 0) {
2022-04-03 23:57:50 +02:00
val readLength =
Merge update build tools #755 by Holger Müller Squashed commit of the following: commit 4491c65b1bfa8f507e9c998878254d61bc52f962 Merge: 51ff716f 77865a14 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 20:50:05 2022 +0200 Merge branch 'develop' into gradle-update commit 51ff716ff5fc8aeb29bc557844747c0127ab1f78 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:52 2022 +0200 fixed lint warning commit 18c31a5704e7d92a04009e2f3ed8f8b9ca28b577 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:35 2022 +0200 fixed lint warning commit 603654c262ed86a66b4127513764cd252cdedfff Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:51 2022 +0200 API is > lollipop ... target removed commit b38a7211de0f206465640d39f8f3189695afbd38 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:07 2022 +0200 new created after fixes commit 4929a526f7e9154755cae2c16fdf431550ae2c2a Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:43:16 2022 +0200 Disable ObsoleteLintCustomCheck commit d0c30f0b6b1d4de2f3c46a166a4f1058223ad3a8 Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:14:06 2022 +0200 Update more libs commit e2fa447bbfbd19119393297c19de0f3237e1ccd3 Merge: d4ead495 ff9c7b24 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 09:47:03 2022 +0200 Merge branch 'develop' into gradle-update commit d4ead49548d11f51dd9c29478972dcd4553d352a Merge: 2dac6a7e 9a73d72f Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 08:50:42 2022 +0200 merged with develop branch commit 2dac6a7e01e4ce5dc619426553ea08743bd9524e Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 21:45:22 2022 +0200 update to android image tag 2022.06.1 commit f3dc259c390c256a66f96c3f003e34daf0fdea14 Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:56:37 2022 +0200 rebuild lint-baseline.xml commit c71bc1212a8570f8ee99a80926c7b3b6036c672f Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:55:00 2022 +0200 removed unneeded cast commit eca136dabedab838e8a02be1a6fd740c4d0934ec Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:58:37 2022 +0200 commit signed commit 540f47633485cddeb4e68626532e54707a66bab8 Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:40:59 2022 +0200 commit signed Signed-off-by: Holger Müller <github@euhm.de> commit 986bd013a49afc56ff8992634f2ce126339eecfc Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:27:20 2022 +0200 push to latest gradle version, set targetSdk to 33 Signed-off-by: tzugen <tzugen@riseup.net>
2022-06-21 21:05:58 +02:00
bytesToSkipCpy.coerceAtMost(skipBuffer.size.toLong()).toInt()
2022-04-03 23:57:50 +02:00
val read = Util.castNonNull(responseByteStream).read(skipBuffer, 0, readLength)
if (Thread.currentThread().isInterrupted) {
throw InterruptedIOException()
}
if (read == -1) {
throw HttpDataSourceException(
dataSpec,
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
HttpDataSourceException.TYPE_OPEN
)
}
Merge update build tools #755 by Holger Müller Squashed commit of the following: commit 4491c65b1bfa8f507e9c998878254d61bc52f962 Merge: 51ff716f 77865a14 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 20:50:05 2022 +0200 Merge branch 'develop' into gradle-update commit 51ff716ff5fc8aeb29bc557844747c0127ab1f78 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:52 2022 +0200 fixed lint warning commit 18c31a5704e7d92a04009e2f3ed8f8b9ca28b577 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:35 2022 +0200 fixed lint warning commit 603654c262ed86a66b4127513764cd252cdedfff Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:51 2022 +0200 API is > lollipop ... target removed commit b38a7211de0f206465640d39f8f3189695afbd38 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:07 2022 +0200 new created after fixes commit 4929a526f7e9154755cae2c16fdf431550ae2c2a Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:43:16 2022 +0200 Disable ObsoleteLintCustomCheck commit d0c30f0b6b1d4de2f3c46a166a4f1058223ad3a8 Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:14:06 2022 +0200 Update more libs commit e2fa447bbfbd19119393297c19de0f3237e1ccd3 Merge: d4ead495 ff9c7b24 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 09:47:03 2022 +0200 Merge branch 'develop' into gradle-update commit d4ead49548d11f51dd9c29478972dcd4553d352a Merge: 2dac6a7e 9a73d72f Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 08:50:42 2022 +0200 merged with develop branch commit 2dac6a7e01e4ce5dc619426553ea08743bd9524e Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 21:45:22 2022 +0200 update to android image tag 2022.06.1 commit f3dc259c390c256a66f96c3f003e34daf0fdea14 Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:56:37 2022 +0200 rebuild lint-baseline.xml commit c71bc1212a8570f8ee99a80926c7b3b6036c672f Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:55:00 2022 +0200 removed unneeded cast commit eca136dabedab838e8a02be1a6fd740c4d0934ec Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:58:37 2022 +0200 commit signed commit 540f47633485cddeb4e68626532e54707a66bab8 Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:40:59 2022 +0200 commit signed Signed-off-by: Holger Müller <github@euhm.de> commit 986bd013a49afc56ff8992634f2ce126339eecfc Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:27:20 2022 +0200 push to latest gradle version, set targetSdk to 33 Signed-off-by: tzugen <tzugen@riseup.net>
2022-06-21 21:05:58 +02:00
bytesToSkipCpy -= read.toLong()
2022-04-03 23:57:50 +02:00
bytesTransferred(read)
}
return
} catch (e: IOException) {
if (e is HttpDataSourceException) {
throw e
} else {
throw HttpDataSourceException(
dataSpec,
PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
HttpDataSourceException.TYPE_OPEN
)
}
}
}
/**
* Reads up to `length` bytes of data and stores them into `buffer`, starting at index
* `offset`.
*
*
* This method blocks until at least one byte of data can be read, the end of the opened range
* is detected, or an exception is thrown.
*
* @param buffer The buffer into which the read data should be stored.
* @param offset The start offset into `buffer` at which data should be written.
* @param readLength The maximum number of bytes to read.
* @return The number of bytes read, or [C.RESULT_END_OF_INPUT] if the end of the opened
* range is reached.
* @throws IOException If an error occurs reading from the source.
*/
@Throws(IOException::class)
private fun readInternal(buffer: ByteArray, offset: Int, readLength: Int): Int {
Merge update build tools #755 by Holger Müller Squashed commit of the following: commit 4491c65b1bfa8f507e9c998878254d61bc52f962 Merge: 51ff716f 77865a14 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 20:50:05 2022 +0200 Merge branch 'develop' into gradle-update commit 51ff716ff5fc8aeb29bc557844747c0127ab1f78 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:52 2022 +0200 fixed lint warning commit 18c31a5704e7d92a04009e2f3ed8f8b9ca28b577 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:35 2022 +0200 fixed lint warning commit 603654c262ed86a66b4127513764cd252cdedfff Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:51 2022 +0200 API is > lollipop ... target removed commit b38a7211de0f206465640d39f8f3189695afbd38 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:07 2022 +0200 new created after fixes commit 4929a526f7e9154755cae2c16fdf431550ae2c2a Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:43:16 2022 +0200 Disable ObsoleteLintCustomCheck commit d0c30f0b6b1d4de2f3c46a166a4f1058223ad3a8 Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:14:06 2022 +0200 Update more libs commit e2fa447bbfbd19119393297c19de0f3237e1ccd3 Merge: d4ead495 ff9c7b24 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 09:47:03 2022 +0200 Merge branch 'develop' into gradle-update commit d4ead49548d11f51dd9c29478972dcd4553d352a Merge: 2dac6a7e 9a73d72f Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 08:50:42 2022 +0200 merged with develop branch commit 2dac6a7e01e4ce5dc619426553ea08743bd9524e Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 21:45:22 2022 +0200 update to android image tag 2022.06.1 commit f3dc259c390c256a66f96c3f003e34daf0fdea14 Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:56:37 2022 +0200 rebuild lint-baseline.xml commit c71bc1212a8570f8ee99a80926c7b3b6036c672f Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:55:00 2022 +0200 removed unneeded cast commit eca136dabedab838e8a02be1a6fd740c4d0934ec Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:58:37 2022 +0200 commit signed commit 540f47633485cddeb4e68626532e54707a66bab8 Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:40:59 2022 +0200 commit signed Signed-off-by: Holger Müller <github@euhm.de> commit 986bd013a49afc56ff8992634f2ce126339eecfc Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:27:20 2022 +0200 push to latest gradle version, set targetSdk to 33 Signed-off-by: tzugen <tzugen@riseup.net>
2022-06-21 21:05:58 +02:00
var readLengthCpy = readLength
if (readLengthCpy == 0) {
2022-04-03 23:57:50 +02:00
return 0
}
if (bytesToRead != C.LENGTH_UNSET.toLong()) {
val bytesRemaining = bytesToRead - bytesRead
if (bytesRemaining == 0L) {
return C.RESULT_END_OF_INPUT
}
Merge update build tools #755 by Holger Müller Squashed commit of the following: commit 4491c65b1bfa8f507e9c998878254d61bc52f962 Merge: 51ff716f 77865a14 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 20:50:05 2022 +0200 Merge branch 'develop' into gradle-update commit 51ff716ff5fc8aeb29bc557844747c0127ab1f78 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:52 2022 +0200 fixed lint warning commit 18c31a5704e7d92a04009e2f3ed8f8b9ca28b577 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:35 2022 +0200 fixed lint warning commit 603654c262ed86a66b4127513764cd252cdedfff Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:51 2022 +0200 API is > lollipop ... target removed commit b38a7211de0f206465640d39f8f3189695afbd38 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:07 2022 +0200 new created after fixes commit 4929a526f7e9154755cae2c16fdf431550ae2c2a Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:43:16 2022 +0200 Disable ObsoleteLintCustomCheck commit d0c30f0b6b1d4de2f3c46a166a4f1058223ad3a8 Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:14:06 2022 +0200 Update more libs commit e2fa447bbfbd19119393297c19de0f3237e1ccd3 Merge: d4ead495 ff9c7b24 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 09:47:03 2022 +0200 Merge branch 'develop' into gradle-update commit d4ead49548d11f51dd9c29478972dcd4553d352a Merge: 2dac6a7e 9a73d72f Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 08:50:42 2022 +0200 merged with develop branch commit 2dac6a7e01e4ce5dc619426553ea08743bd9524e Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 21:45:22 2022 +0200 update to android image tag 2022.06.1 commit f3dc259c390c256a66f96c3f003e34daf0fdea14 Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:56:37 2022 +0200 rebuild lint-baseline.xml commit c71bc1212a8570f8ee99a80926c7b3b6036c672f Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:55:00 2022 +0200 removed unneeded cast commit eca136dabedab838e8a02be1a6fd740c4d0934ec Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:58:37 2022 +0200 commit signed commit 540f47633485cddeb4e68626532e54707a66bab8 Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:40:59 2022 +0200 commit signed Signed-off-by: Holger Müller <github@euhm.de> commit 986bd013a49afc56ff8992634f2ce126339eecfc Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:27:20 2022 +0200 push to latest gradle version, set targetSdk to 33 Signed-off-by: tzugen <tzugen@riseup.net>
2022-06-21 21:05:58 +02:00
readLengthCpy = readLengthCpy.toLong().coerceAtMost(bytesRemaining).toInt()
2022-04-03 23:57:50 +02:00
}
Merge update build tools #755 by Holger Müller Squashed commit of the following: commit 4491c65b1bfa8f507e9c998878254d61bc52f962 Merge: 51ff716f 77865a14 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 20:50:05 2022 +0200 Merge branch 'develop' into gradle-update commit 51ff716ff5fc8aeb29bc557844747c0127ab1f78 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:52 2022 +0200 fixed lint warning commit 18c31a5704e7d92a04009e2f3ed8f8b9ca28b577 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:38:35 2022 +0200 fixed lint warning commit 603654c262ed86a66b4127513764cd252cdedfff Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:51 2022 +0200 API is > lollipop ... target removed commit b38a7211de0f206465640d39f8f3189695afbd38 Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 20:37:07 2022 +0200 new created after fixes commit 4929a526f7e9154755cae2c16fdf431550ae2c2a Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:43:16 2022 +0200 Disable ObsoleteLintCustomCheck commit d0c30f0b6b1d4de2f3c46a166a4f1058223ad3a8 Author: tzugen <tzugen@riseup.net> Date: Tue Jun 21 10:14:06 2022 +0200 Update more libs commit e2fa447bbfbd19119393297c19de0f3237e1ccd3 Merge: d4ead495 ff9c7b24 Author: tzugen <67737443+tzugen@users.noreply.github.com> Date: Tue Jun 21 09:47:03 2022 +0200 Merge branch 'develop' into gradle-update commit d4ead49548d11f51dd9c29478972dcd4553d352a Merge: 2dac6a7e 9a73d72f Author: Holger Müller <github@euhm.de> Date: Tue Jun 21 08:50:42 2022 +0200 merged with develop branch commit 2dac6a7e01e4ce5dc619426553ea08743bd9524e Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 21:45:22 2022 +0200 update to android image tag 2022.06.1 commit f3dc259c390c256a66f96c3f003e34daf0fdea14 Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:56:37 2022 +0200 rebuild lint-baseline.xml commit c71bc1212a8570f8ee99a80926c7b3b6036c672f Author: Holger Müller <github@euhm.de> Date: Mon Jun 20 20:55:00 2022 +0200 removed unneeded cast commit eca136dabedab838e8a02be1a6fd740c4d0934ec Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:58:37 2022 +0200 commit signed commit 540f47633485cddeb4e68626532e54707a66bab8 Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:40:59 2022 +0200 commit signed Signed-off-by: Holger Müller <github@euhm.de> commit 986bd013a49afc56ff8992634f2ce126339eecfc Author: Holger Müller <github@euhm.de> Date: Fri Jun 17 23:27:20 2022 +0200 push to latest gradle version, set targetSdk to 33 Signed-off-by: tzugen <tzugen@riseup.net>
2022-06-21 21:05:58 +02:00
val read = Util.castNonNull(responseByteStream).read(buffer, offset, readLengthCpy)
2022-04-03 23:57:50 +02:00
if (read == -1) {
return C.RESULT_END_OF_INPUT
}
bytesRead += read.toLong()
2022-04-12 17:12:17 +02:00
bytesTransferred(read)
2022-04-03 23:57:50 +02:00
return read
}
/** Closes the current connection quietly, if there is one. */
private fun closeConnectionQuietly() {
if (response != null) {
Assertions.checkNotNull(response!!.body()).close()
response = null
}
responseByteStream = null
}
}