|
|
@@ -2,10 +2,9 @@
|
|
|
|
|
|
package net.mamoe.mirai.utils
|
|
|
|
|
|
-import kotlinx.io.core.Closeable
|
|
|
-import kotlinx.io.core.Input
|
|
|
-import kotlinx.io.core.readAvailable
|
|
|
-import kotlinx.io.core.readBytes
|
|
|
+import kotlinx.io.core.*
|
|
|
+import kotlinx.io.streams.asInput
|
|
|
+import kotlinx.io.streams.asOutput
|
|
|
import net.mamoe.mirai.Bot
|
|
|
import net.mamoe.mirai.utils.internal.InputStream
|
|
|
import net.mamoe.mirai.utils.internal.asReusableInput
|
|
|
@@ -16,10 +15,11 @@ import java.io.IOException
|
|
|
import java.io.OutputStream
|
|
|
import java.net.URL
|
|
|
import java.security.MessageDigest
|
|
|
+import java.util.*
|
|
|
import javax.imageio.ImageIO
|
|
|
-import kotlin.contracts.ExperimentalContracts
|
|
|
import kotlin.contracts.InvocationKind
|
|
|
import kotlin.contracts.contract
|
|
|
+import kotlin.io.use
|
|
|
|
|
|
/**
|
|
|
* 缓存策略.
|
|
|
@@ -44,7 +44,7 @@ actual interface FileCacheStrategy {
|
|
|
*/
|
|
|
@MiraiExperimentalAPI
|
|
|
@Throws(IOException::class)
|
|
|
- actual fun newImageCache(input: InputStream): ExternalImage
|
|
|
+ fun newImageCache(input: InputStream): ExternalImage
|
|
|
|
|
|
/**
|
|
|
* 将 [input] 缓存为 [ExternalImage].
|
|
|
@@ -87,7 +87,7 @@ actual interface FileCacheStrategy {
|
|
|
|
|
|
@MiraiExperimentalAPI
|
|
|
@Throws(IOException::class)
|
|
|
- actual override fun newImageCache(input: InputStream): ExternalImage {
|
|
|
+ override fun newImageCache(input: InputStream): ExternalImage {
|
|
|
return newImageCache(input.readBytes())
|
|
|
}
|
|
|
|
|
|
@@ -186,12 +186,6 @@ actual interface FileCacheStrategy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-internal inline fun <I : Closeable, O : Closeable, R> I.withOut(output: O, block: I.(output: O) -> R): R {
|
|
|
- contract {
|
|
|
- callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
|
|
- }
|
|
|
- return use { output.use { block(this, output) } }
|
|
|
-}
|
|
|
|
|
|
@Throws(IOException::class)
|
|
|
internal fun Input.copyTo(out: OutputStream, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long {
|
|
|
@@ -204,4 +198,4 @@ internal fun Input.copyTo(out: OutputStream, bufferSize: Int = DEFAULT_BUFFER_SI
|
|
|
bytes = readAvailable(buffer)
|
|
|
}
|
|
|
return bytesCopied
|
|
|
-}
|
|
|
+}
|