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.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import okhttp3.ConnectionSpec import okhttp3.ConnectionSpec
import okhttp3.HttpUrl import okhttp3.HttpUrl
import okhttp3.MediaType.Companion.toMediaType import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.RequestBody import okhttp3.RequestBody
import okhttp3.internal.closeQuietly
import okio.BufferedSink import okio.BufferedSink
import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParser
import java.io.IOException import java.io.IOException
@ -113,28 +111,10 @@ internal abstract class WebDavStorage(
protected fun getInputStream(location: HttpUrl): InputStream { protected fun getInputStream(location: HttpUrl): InputStream {
val davCollection = DavCollection(okHttpClient, location) val davCollection = DavCollection(okHttpClient, location)
val pipedInputStream = PipedExceptionInputStream() val response = davCollection.get(accept = "", headers = null)
val pipedOutputStream = PipedOutputStream(pipedInputStream) debugLog { "getInputStream($location) = $response" }
if (response.code / 100 != 2) throw IOException("HTTP error ${response.code}")
GlobalScope.launch(Dispatchers.IO) { return response.body?.byteStream() ?: throw IOException()
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
} }
/** /**
@ -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)
}
}
}
} }
/** /**