mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-05 00:57:05 +08:00
Chain calling of ExternalResource.toExternalResource()
; fix #1588
This commit is contained in:
parent
b31f7b1ba7
commit
07d5a6ca7d
@ -5732,6 +5732,7 @@ public abstract interface class net/mamoe/mirai/utils/ExternalResource : java/io
|
||||
public static fun sendTo (Ljava/io/File;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static fun sendTo (Ljava/io/File;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
public static fun sendTo (Ljava/io/File;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun toAutoCloseable ()Lnet/mamoe/mirai/utils/ExternalResource;
|
||||
public static fun uploadAsFile (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public static fun uploadAsFile (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static fun uploadAsFile (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
|
@ -5732,6 +5732,7 @@ public abstract interface class net/mamoe/mirai/utils/ExternalResource : java/io
|
||||
public static fun sendTo (Ljava/io/File;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static fun sendTo (Ljava/io/File;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
public static fun sendTo (Ljava/io/File;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun toAutoCloseable ()Lnet/mamoe/mirai/utils/ExternalResource;
|
||||
public static fun uploadAsFile (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public static fun uploadAsFile (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static fun uploadAsFile (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/contact/FileSupported;Ljava/lang/String;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
|
@ -150,7 +150,7 @@ public interface ExternalResource : Closeable {
|
||||
* - 不要返回 [String], 没有约定 [String] 代表什么
|
||||
* - 数据源外漏会严重影响 [inputStream] 等的执行的可以返回 `null` (如 [RandomAccessFile])
|
||||
*
|
||||
* @since TODO
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public val origin: Any? get() = null
|
||||
|
||||
@ -226,21 +226,23 @@ public interface ExternalResource : Closeable {
|
||||
public fun InputStream.toExternalResource(formatName: String? = null): ExternalResource =
|
||||
Mirai.FileCacheStrategy.newCache(this, formatName)
|
||||
|
||||
/**
|
||||
* 创建一个在 _使用一次_ 后就会自动 [close] 的 [ExternalResource].
|
||||
*
|
||||
* @since 2.8
|
||||
|
||||
/* note:
|
||||
于 2.8.0-M1 添加 (#1392)
|
||||
|
||||
于 2.8.0-RC 移动至 `toExternalResource`(#1588)
|
||||
|
||||
Fixme: 在 2.8.0 标为 HIDDEN
|
||||
*/
|
||||
@JvmName("createAutoCloseable")
|
||||
@JvmStatic
|
||||
public fun ExternalResource.toAutoCloseable(): ExternalResource {
|
||||
return if (isAutoClose) this else {
|
||||
val delegate = this
|
||||
object : ExternalResource by delegate {
|
||||
override val isAutoClose: Boolean get() = true
|
||||
override fun toString(): String = "ExternalResourceWithAutoClose(delegate=$delegate)"
|
||||
}
|
||||
}
|
||||
@Deprecated(
|
||||
level = DeprecationLevel.ERROR,
|
||||
message = "Moved to `toExternalResource()`",
|
||||
replaceWith = ReplaceWith("resource.toAutoCloseable()"),
|
||||
)
|
||||
public fun createAutoCloseable(resource: ExternalResource): ExternalResource {
|
||||
return resource.toAutoCloseable()
|
||||
}
|
||||
|
||||
// endregion
|
||||
@ -484,6 +486,33 @@ public interface ExternalResource : Closeable {
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// region Java Friendly Functions
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 创建一个在 _使用一次_ 后就会自动 [close] 的 [ExternalResource].
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public fun toAutoCloseable(): ExternalResource {
|
||||
return if (isAutoClose) this else {
|
||||
val delegate = this
|
||||
object : ExternalResource by delegate {
|
||||
override val isAutoClose: Boolean get() = true
|
||||
override fun toString(): String = "ExternalResourceWithAutoClose(delegate=$delegate)"
|
||||
override fun toAutoCloseable(): ExternalResource {
|
||||
return this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// endregion
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user