Chain calling of ExternalResource.toExternalResource(); fix #1588

This commit is contained in:
Karlatemp 2021-10-09 21:47:37 +08:00
parent b31f7b1ba7
commit 07d5a6ca7d
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
3 changed files with 44 additions and 13 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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
///////////////////////////////////////////////////////////////////////////
}
/**