Commit a5fbf6b4 authored by Janne Koschinski's avatar Janne Koschinski

Minor cleanup

parent 75cb68d9
......@@ -21,36 +21,32 @@ package de.kuschku.quasseldroid.util.backport
import android.content.Context
import org.threeten.bp.zone.TzdbZoneRulesProvider
import org.threeten.bp.zone.ZoneRulesInitializer
import org.threeten.bp.zone.ZoneRulesProvider
import java.io.IOException
import java.io.InputStream
import java.util.concurrent.atomic.AtomicBoolean
object AndroidThreeTenBackport {
private val initialized = AtomicBoolean()
fun init(context: Context) {
if (initialized.getAndSet(true)) {
return
fun init(context: Context, assetPath: String = "TZDB.dat") {
if (!initialized.getAndSet(true)) {
ZoneRulesInitializer.setInitializer(AndroidThreeTenBackportInitializer(context, assetPath))
}
}
val provider: TzdbZoneRulesProvider
var inputStream: InputStream? = null
try {
inputStream = context.assets.open("TZDB.dat")
provider = TzdbZoneRulesProvider(inputStream)
} catch (e: IOException) {
throw IllegalStateException("TZDB.dat missing from assets.", e)
} finally {
if (inputStream != null) {
try {
inputStream.close()
} catch (ignored: IOException) {
}
class AndroidThreeTenBackportInitializer(
private val context: Context,
private val assetPath: String
) : ZoneRulesInitializer() {
override fun initializeProviders() {
try {
ZoneRulesProvider.registerProvider(context.assets.open(assetPath).use {
TzdbZoneRulesProvider(it)
})
} catch (exception: IOException) {
throw IllegalStateException("$assetPath missing from assets", exception)
}
}
ZoneRulesProvider.registerProvider(provider)
}
}
......@@ -41,9 +41,10 @@ class BackportedSyncFlushDeflaterOutputStream(
private fun createSyncFlushDeflater(): Deflater? {
val def = Deflater()
try {
val f = def.javaClass.getDeclaredField("flushParm")
f.isAccessible = true
f.setInt(def, 2) // Z_SYNC_FLUSH
def.javaClass.getDeclaredField("flushParm").apply {
isAccessible = true
setInt(def, 2) // Z_SYNC_FLUSH
}
} catch (e: Exception) {
return null
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment