Remove dav4jvm InputStream hack as not needed with latest version

This commit is contained in:
Torsten Grote 2024-06-24 13:53:08 -03:00
parent 6e84d727c2
commit a1f6be0447
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF

View file

@ -22,14 +22,12 @@ import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import okhttp3.ConnectionSpec
import okhttp3.HttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.RequestBody
import okhttp3.internal.closeQuietly
import okio.BufferedSink
import org.xmlpull.v1.XmlPullParser
import java.io.IOException
@ -113,28 +111,10 @@ internal abstract class WebDavStorage(
protected fun getInputStream(location: HttpUrl): InputStream {
val davCollection = DavCollection(okHttpClient, location)
val pipedInputStream = PipedExceptionInputStream()
val pipedOutputStream = PipedOutputStream(pipedInputStream)
GlobalScope.launch(Dispatchers.IO) {
try {
davCollection.get(accept = "", headers = null) { response ->
val inputStream = response.body?.byteStream()
?: throw IOException("No response body")
debugLog { "getInputStream($location) = $response" }
pipedOutputStream.use { outputStream ->
inputStream.copyTo(outputStream)
}
}
} catch (e: Exception) {
debugLog { "Exception while getting input stream: $e" }
// pass exception to stream, so it gets thrown when stream is closed
// if we'd just throw it here, it would be uncaught, on a different thread
pipedInputStream.throwable = e
pipedOutputStream.closeQuietly()
}
}
return pipedInputStream
val response = davCollection.get(accept = "", headers = null)
debugLog { "getInputStream($location) = $response" }
if (response.code / 100 != 2) throw IOException("HTTP error ${response.code}")
return response.body?.byteStream() ?: throw IOException()
}
/**
@ -233,18 +213,6 @@ internal abstract class WebDavStorage(
}
}
private class PipedExceptionInputStream : PipedInputStream() {
var throwable: Throwable? = null
override fun close() {
super.close()
throwable?.let { e ->
if (e is IOException) throw e
else throw IOException(e)
}
}
}
}
/**