Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Jul 11, 2024
1 parent 8431deb commit 93b6a55
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
17 changes: 9 additions & 8 deletions ktor-io/jvm/src/io/ktor/utils/io/core/ByteOrderJVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ public actual enum class ByteOrder(public val nioOrder: java.nio.ByteOrder) {
LITTLE_ENDIAN(java.nio.ByteOrder.LITTLE_ENDIAN);

public actual companion object {
private val native: io.ktor.utils.io.core.ByteOrder = orderOf(java.nio.ByteOrder.nativeOrder())
private val native: ByteOrder = orderOf(java.nio.ByteOrder.nativeOrder())

public fun of(nioOrder: java.nio.ByteOrder): io.ktor.utils.io.core.ByteOrder = orderOf(nioOrder)
public fun of(nioOrder: java.nio.ByteOrder): ByteOrder = orderOf(nioOrder)

public actual fun nativeOrder(): io.ktor.utils.io.core.ByteOrder = native
public actual fun nativeOrder(): ByteOrder = native
}
}

private fun orderOf(nioOrder: java.nio.ByteOrder): io.ktor.utils.io.core.ByteOrder =
if (nioOrder === java.nio.ByteOrder.BIG_ENDIAN)
io.ktor.utils.io.core.ByteOrder.BIG_ENDIAN
else
io.ktor.utils.io.core.ByteOrder.LITTLE_ENDIAN
private fun orderOf(nioOrder: java.nio.ByteOrder): ByteOrder =
if (nioOrder === java.nio.ByteOrder.BIG_ENDIAN) {
ByteOrder.BIG_ENDIAN
} else {
ByteOrder.LITTLE_ENDIAN
}
1 change: 0 additions & 1 deletion ktor-io/wasmJs/src/io/ktor/utils/io/charsets/Decoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package io.ktor.utils.io.charsets

import io.ktor.utils.io.js.JsTextDecoder


internal fun Decoder(encoding: String, fatal: Boolean = true): Decoder =
JsTextDecoder.tryCreate(encoding, fatal)
?: ISO8859TextDecoder.tryCreate(encoding, fatal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public actual abstract class Charset(internal val _name: String) {
else -> null
}

@Suppress("LocalVariableName")
public fun forName(name: String): Charset =
getCharset(name) ?: throw IllegalArgumentException("Charset $name is not supported")

Expand Down Expand Up @@ -91,8 +90,8 @@ public actual fun CharsetDecoder.decode(
}

private data class CharsetImpl(val name: String) : Charset(name) {
override fun newEncoder(): CharsetEncoder = object : CharsetEncoder(this) { }
override fun newDecoder(): CharsetDecoder = object : CharsetDecoder(this) { }
override fun newEncoder(): CharsetEncoder = object : CharsetEncoder(this) {}
override fun newDecoder(): CharsetDecoder = object : CharsetDecoder(this) {}
}

// ----------------------------- REGISTRY ------------------------------------------------------------------------------
Expand Down Expand Up @@ -122,7 +121,7 @@ internal actual fun CharsetEncoder.encodeToByteArrayImpl(
fromIndex: Int,
toIndex: Int
): ByteArray {
var start = fromIndex
var start = fromIndex
if (start >= toIndex) return ByteArray(0)

val dst = Buffer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private fun decodeStream(decoder: TextDecoder, buffer: Int8Array): String? =
private inline fun decodeOrFail(body: () -> String?): String =
body() ?: error("Buffer decode fail")

internal class JsTextDecoder private constructor(private val decoder: TextDecoder): Decoder {
internal class JsTextDecoder private constructor(private val decoder: TextDecoder) : Decoder {
override fun decode(): String =
decodeOrFail { decode(decoder) }

Expand Down
8 changes: 4 additions & 4 deletions ktor-network/jvm/src/io/ktor/network/sockets/CIOWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ internal fun CoroutineScope.attachForWritingDirectImpl(
}
}

if (rc == 0) {
selectable.interestOp(SelectInterest.WRITE, true)
selector.select(selectable, SelectInterest.WRITE)
}
if (rc == 0) {
selectable.interestOp(SelectInterest.WRITE, true)
selector.select(selectable, SelectInterest.WRITE)
}
}

timeout?.finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import io.ktor.util.internal.*
import io.ktor.util.logging.*
import io.ktor.utils.io.charsets.*
import io.ktor.utils.io.core.*
import io.ktor.utils.io.errors.*
import kotlinx.coroutines.*
import kotlinx.io.IOException
import kotlinx.io.*
import kotlinx.serialization.json.*

private val Logger: Logger = KtorSimpleLogger("io.ktor.auth.oauth")
Expand Down Expand Up @@ -201,15 +200,15 @@ private suspend fun oauth2RequestAccessToken(

val (contentType, content) = try {
if (response.status == HttpStatusCode.NotFound) {
throw kotlinx.io.IOException("Access token query failed with http status 404 for the page $baseUrl")
throw IOException("Access token query failed with http status 404 for the page $baseUrl")
}
val contentType = response.headers[HttpHeaders.ContentType]?.let { ContentType.parse(it) } ?: ContentType.Any

Pair(contentType, body)
} catch (ioe: kotlinx.io.IOException) {
} catch (ioe: IOException) {
throw ioe
} catch (t: Throwable) {
throw kotlinx.io.IOException("Failed to acquire request token due to wrong content: $body", t)
} catch (cause: Throwable) {
throw IOException("Failed to acquire request token due to wrong content: $body", cause)
}

val contentDecodeResult = Result.runCatching { decodeContent(content, contentType) }
Expand All @@ -222,7 +221,9 @@ private suspend fun oauth2RequestAccessToken(

// ensure status code is successful
if (!response.status.isSuccess()) {
throw kotlinx.io.IOException("Access token query failed with http status ${response.status} for the page $baseUrl")
throw IOException(
"Access token query failed with http status ${response.status} for the page $baseUrl"
)
}

// will fail if content decode failed but status is OK
Expand All @@ -247,6 +248,7 @@ private fun decodeContent(content: String, contentType: ContentType): Parameters
(element as? JsonPrimitive)?.content?.let { append(key, it) }
}
}

else -> {
// some servers may respond with a wrong content type, so we have to try to guess
when {
Expand Down

0 comments on commit 93b6a55

Please sign in to comment.