kotlin

How to use coroutine inside the router.route(“/api/*”).handler?

蓝咒 提交于 2021-01-05 08:53:54
问题 I am trying to use coroutine inside the route handler lambda as follows: private suspend fun createRoutes(router: Router, auth: OAuth2Auth): Unit { val oauth2 = OAuth2AuthHandler.create(vertx, auth) val authz = KeycloakAuthorization.create() router.route().handler(LoggerHandler.create()) router.route("/api/*").handler(oauth2) router.route("/api/greet").handler { println(RoleBasedAuthorization.create("ad-admins").match(it.user())) authz.getAuthorizations(it.user()).await() } } The compiler

How to convert a Data Class to ByteBuffer in Kotlin?

和自甴很熟 提交于 2021-01-05 07:50:28
问题 I am trying to use Kinesis, which expects data in byte buffer format. All the examples I have seen so far are in Java and pass simple strings. Can anybody give an idea of how to convert a kotlin data class to bytebuffer? e.g. data class abc ( var a: Long, var b: String, var c: Double ) 回答1: Check the below method fun toByteArray(): ByteArray? { val size: Int = 8 + 8 + string.Size val byteBuffer = ByteBuffer.allocate(size) .put(long) //long veriable .put(double) // double veriable .put(string)

Testing Spring cloud stream with kafka stream binder: using TopologyTestDriver I get the error of “The class is not in the trusted packages”

泪湿孤枕 提交于 2021-01-05 07:38:28
问题 I have this simple stream processor (not a consumer/producer) using kafka streams binder. @Bean fun processFoo():Function<KStream<FooName, FooAddress>, KStream<FooName, FooAddressPlus>> { return Function { input-> input.map { key, value -> println("\nPAYLOAD KEY: ${key.name}\n"); println("\nPAYLOAD value: ${value.address}\n"); val output = FooAddressPlus() output.address = value.address output.name = value.name output.plus = "$value.name-$value.address" KeyValue(key, output) }} } I'm trying

Is it possible to invoke a function with a unaryPlus in kotlin?

纵饮孤独 提交于 2021-01-05 07:19:25
问题 This is a followup question on another question I asked yesterday. How can I build a nested list using builder pattern? Credit to: Pelocho for giving nice answer. I used this Tutorial to do a type safe graphQL query builder: What I want to do now is to simplify what I made And I know that kotlin must have some nice features to do that. Right now I have to invoke functions when I want to add an entity to my query: fun main() { events{ title() // I don't like to do () when it is an edge case }

use a kotlin multiplatform lib in another kotlin multiplatfor lib

安稳与你 提交于 2021-01-05 07:10:14
问题 I have create a multiplatform kotlin librarie (L1)using intellij in gradle, who build in JS and JVM. I want to reuse this lib in another multiplatform kotlin lib L2 How can I do it? I have issue with importing the "common" part of L1 in the common target of L2, (the eror are a lot of Unresolved reference ), basicaly the common target of L2 cannot find the implementation contained in L1. I have only this issue with the common target, the js and jvm work fine. the gradle of L1, the lib to be

use a kotlin multiplatform lib in another kotlin multiplatfor lib

有些话、适合烂在心里 提交于 2021-01-05 07:09:33
问题 I have create a multiplatform kotlin librarie (L1)using intellij in gradle, who build in JS and JVM. I want to reuse this lib in another multiplatform kotlin lib L2 How can I do it? I have issue with importing the "common" part of L1 in the common target of L2, (the eror are a lot of Unresolved reference ), basicaly the common target of L2 cannot find the implementation contained in L1. I have only this issue with the common target, the js and jvm work fine. the gradle of L1, the lib to be

Kotlin MutableStateFlow.collect is dropping values

♀尐吖头ヾ 提交于 2021-01-05 07:08:51
问题 I have an android app in which I'm trying to use coroutine flows to replace the existing Otto EventBus using my own event bus library. I'm seeing dropped values when setting the MutableStateFlow's value and then collecting in my app's code. I've created a much simpler project that demonstrates the same issue. Any thoughts on why values are being dropped from the MutableStateFlow? Project's build.gradle buildscript { ext.kotlin_version = "1.4.10" repositories { google() jcenter() }

Kotlin MutableStateFlow.collect is dropping values

我怕爱的太早我们不能终老 提交于 2021-01-05 07:07:29
问题 I have an android app in which I'm trying to use coroutine flows to replace the existing Otto EventBus using my own event bus library. I'm seeing dropped values when setting the MutableStateFlow's value and then collecting in my app's code. I've created a much simpler project that demonstrates the same issue. Any thoughts on why values are being dropped from the MutableStateFlow? Project's build.gradle buildscript { ext.kotlin_version = "1.4.10" repositories { google() jcenter() }

SourceSets - Groovy -> Kotlin DSL

久未见 提交于 2021-01-05 06:49:57
问题 sourceSets { main { java.srcDirs = ['src/main/kotlin', 'src/main/java'] res.srcDirs = [ 'src/main/res/layouts/activity', 'src/main/res/layouts/fragment', 'src/main/res/layouts/dialog', 'src/main/res/layouts/items', 'src/main/res/layouts/views', 'src/main/res/layouts', 'src/main/res' ] } } Here for java.srcDirs we convert it in kotlin DSL like java.sourceSets { getByName("main").java.srcDirs("src/main/kotlin") } But I don't know how to change sub folders within 'layout' res folder code in DSL

SourceSets - Groovy -> Kotlin DSL

試著忘記壹切 提交于 2021-01-05 06:46:25
问题 sourceSets { main { java.srcDirs = ['src/main/kotlin', 'src/main/java'] res.srcDirs = [ 'src/main/res/layouts/activity', 'src/main/res/layouts/fragment', 'src/main/res/layouts/dialog', 'src/main/res/layouts/items', 'src/main/res/layouts/views', 'src/main/res/layouts', 'src/main/res' ] } } Here for java.srcDirs we convert it in kotlin DSL like java.sourceSets { getByName("main").java.srcDirs("src/main/kotlin") } But I don't know how to change sub folders within 'layout' res folder code in DSL