Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
1e5dcb0e
Commit
1e5dcb0e
authored
Dec 15, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace all transferTo to Kotlinx transfer, downgrade JDK requirement
parent
a2e82e75
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
10 deletions
+29
-10
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/InputUtils.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/io/InputUtils.kt
+2
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/BotSessionJvm.kt
...c/jvmMain/kotlin/net/mamoe/mirai/network/BotSessionJvm.kt
+11
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
+10
-7
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
+6
-2
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/InputUtils.kt
View file @
1e5dcb0e
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
package
net.mamoe.mirai.utils.io
package
net.mamoe.mirai.utils.io
import
kotlinx.io.InputStream
import
kotlinx.io.OutputStream
import
kotlinx.io.core.*
import
kotlinx.io.core.*
import
kotlinx.io.pool.useInstance
import
kotlinx.io.pool.useInstance
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmName
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/BotSessionJvm.kt
View file @
1e5dcb0e
package
net.mamoe.mirai.network
package
net.mamoe.mirai.network
import
io.ktor.util.KtorExperimentalAPI
import
kotlinx.coroutines.Dispatchers.IO
import
kotlinx.coroutines.Dispatchers.IO
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.withContext
import
kotlinx.io.core.copyTo
import
kotlinx.io.core.use
import
kotlinx.io.core.use
import
kotlinx.io.streams.asInput
import
kotlinx.io.streams.asOutput
import
kotlinx.io.streams.inputStream
import
kotlinx.io.streams.inputStream
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.message.Image
import
net.mamoe.mirai.message.Image
...
@@ -31,5 +35,11 @@ actual class BotSession internal actual constructor(
...
@@ -31,5 +35,11 @@ actual class BotSession internal actual constructor(
suspend
inline
fun
Image
.
downloadAsExternalImage
():
ExternalImage
=
download
().
use
{
it
.
toExternalImage
()
}
suspend
inline
fun
Image
.
downloadAsExternalImage
():
ExternalImage
=
download
().
use
{
it
.
toExternalImage
()
}
suspend
inline
fun
Image
.
downloadTo
(
file
:
File
)
=
file
.
outputStream
().
use
{
downloadTo
(
it
)
}
suspend
inline
fun
Image
.
downloadTo
(
file
:
File
)
=
file
.
outputStream
().
use
{
downloadTo
(
it
)
}
suspend
inline
fun
Image
.
downloadTo
(
output
:
OutputStream
)
=
download
().
inputStream
().
use
{
input
->
withContext
(
IO
)
{
input
.
transferTo
(
output
)
}
}
/**
* 需要调用者自行 close [output]
*/
@UseExperimental
(
KtorExperimentalAPI
::
class
)
suspend
inline
fun
Image
.
downloadTo
(
output
:
OutputStream
)
=
download
().
inputStream
().
asInput
().
use
{
input
->
withContext
(
IO
)
{
input
.
copyTo
(
output
.
asOutput
())
}
}
}
}
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
View file @
1e5dcb0e
...
@@ -4,12 +4,15 @@ package net.mamoe.mirai.utils
...
@@ -4,12 +4,15 @@ package net.mamoe.mirai.utils
import
io.ktor.util.asStream
import
io.ktor.util.asStream
import
kotlinx.coroutines.Dispatchers.IO
import
kotlinx.coroutines.Dispatchers.IO
import
kotlinx.coroutines.io.jvm.javaio.copyTo
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.withContext
import
kotlinx.io.core.Input
import
kotlinx.io.core.Input
import
kotlinx.io.core.IoBuffer
import
kotlinx.io.core.IoBuffer
import
kotlinx.io.core.buildPacket
import
kotlinx.io.core.buildPacket
import
kotlinx.io.core.copyTo
import
kotlinx.io.errors.IOException
import
kotlinx.io.errors.IOException
import
kotlinx.io.streams.asInput
import
kotlinx.io.streams.asInput
import
kotlinx.io.streams.asOutput
import
java.awt.image.BufferedImage
import
java.awt.image.BufferedImage
import
java.io.File
import
java.io.File
import
java.io.InputStream
import
java.io.InputStream
...
@@ -81,9 +84,9 @@ suspend fun File.suspendToExternalImage(): ExternalImage = withContext(IO) { toE
...
@@ -81,9 +84,9 @@ suspend fun File.suspendToExternalImage(): ExternalImage = withContext(IO) { toE
@Throws
(
IOException
::
class
)
@Throws
(
IOException
::
class
)
fun
URL
.
toExternalImage
():
ExternalImage
{
fun
URL
.
toExternalImage
():
ExternalImage
{
val
file
=
createTempFile
().
apply
{
deleteOnExit
()
}
val
file
=
createTempFile
().
apply
{
deleteOnExit
()
}
file
.
outputStream
().
use
{
output
->
file
.
outputStream
().
asOutput
().
use
{
output
->
openStream
().
use
{
input
->
openStream
().
asInput
().
use
{
input
->
input
.
transfer
To
(
output
)
input
.
copy
To
(
output
)
}
}
}
}
return
file
.
toExternalImage
()
return
file
.
toExternalImage
()
...
@@ -101,8 +104,8 @@ suspend fun URL.suspendToExternalImage(): ExternalImage = withContext(IO) { toEx
...
@@ -101,8 +104,8 @@ suspend fun URL.suspendToExternalImage(): ExternalImage = withContext(IO) { toEx
@Throws
(
IOException
::
class
)
@Throws
(
IOException
::
class
)
fun
InputStream
.
toExternalImage
():
ExternalImage
{
fun
InputStream
.
toExternalImage
():
ExternalImage
{
val
file
=
createTempFile
().
apply
{
deleteOnExit
()
}
val
file
=
createTempFile
().
apply
{
deleteOnExit
()
}
file
.
outputStream
().
use
{
file
.
outputStream
().
asOutput
().
use
{
this
.
transfer
To
(
it
)
this
.
asInput
().
copy
To
(
it
)
}
}
this
.
close
()
this
.
close
()
return
file
.
toExternalImage
()
return
file
.
toExternalImage
()
...
@@ -120,8 +123,8 @@ suspend fun InputStream.suspendToExternalImage(): ExternalImage = withContext(IO
...
@@ -120,8 +123,8 @@ suspend fun InputStream.suspendToExternalImage(): ExternalImage = withContext(IO
@Throws
(
IOException
::
class
)
@Throws
(
IOException
::
class
)
fun
Input
.
toExternalImage
():
ExternalImage
{
fun
Input
.
toExternalImage
():
ExternalImage
{
val
file
=
createTempFile
().
apply
{
deleteOnExit
()
}
val
file
=
createTempFile
().
apply
{
deleteOnExit
()
}
file
.
outputStream
().
use
{
file
.
outputStream
().
asOutput
().
use
{
this
.
asStream
().
transfer
To
(
it
)
this
.
asStream
().
asInput
().
copy
To
(
it
)
}
}
return
file
.
toExternalImage
()
return
file
.
toExternalImage
()
}
}
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
View file @
1e5dcb0e
...
@@ -4,6 +4,10 @@ package net.mamoe.mirai.utils
...
@@ -4,6 +4,10 @@ package net.mamoe.mirai.utils
import
io.ktor.client.HttpClient
import
io.ktor.client.HttpClient
import
io.ktor.client.engine.cio.CIO
import
io.ktor.client.engine.cio.CIO
import
kotlinx.io.core.Output
import
kotlinx.io.core.copyTo
import
kotlinx.io.streams.asInput
import
kotlinx.io.streams.asOutput
import
java.io.DataInput
import
java.io.DataInput
import
java.io.EOFException
import
java.io.EOFException
import
java.io.InputStream
import
java.io.InputStream
...
@@ -21,13 +25,13 @@ actual fun md5(byteArray: ByteArray): ByteArray = MessageDigest.getInstance("MD5
...
@@ -21,13 +25,13 @@ actual fun md5(byteArray: ByteArray): ByteArray = MessageDigest.getInstance("MD5
fun
InputStream
.
md5
():
ByteArray
{
fun
InputStream
.
md5
():
ByteArray
{
val
digest
=
MessageDigest
.
getInstance
(
"md5"
)
val
digest
=
MessageDigest
.
getInstance
(
"md5"
)
digest
.
reset
()
digest
.
reset
()
this
.
transfer
To
(
object
:
OutputStream
()
{
this
.
asInput
().
copy
To
(
object
:
OutputStream
()
{
override
fun
write
(
b
:
Int
)
{
override
fun
write
(
b
:
Int
)
{
b
.
toByte
().
let
{
b
.
toByte
().
let
{
digest
.
update
(
it
)
digest
.
update
(
it
)
}
}
}
}
})
}
.
asOutput
()
)
return
digest
.
digest
()
return
digest
.
digest
()
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment