mirror of
https://github.com/tursom/TursomServer.git
synced 2025-03-13 11:20:10 +08:00
add method ByteBuffer.read(InputStream)
This commit is contained in:
parent
3a11dac3b4
commit
bfebd1e5c6
@ -2,6 +2,7 @@ package cn.tursom.core.buffer
|
||||
|
||||
import cn.tursom.core.forEachIndex
|
||||
import java.io.Closeable
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import kotlin.math.min
|
||||
|
||||
@ -198,6 +199,17 @@ interface ByteBuffer : Closeable {
|
||||
array.forEachIndex(index, index + size - 1, this::put)
|
||||
}
|
||||
|
||||
fun put(inputStream: InputStream) {
|
||||
if (hasArray) {
|
||||
val read = inputStream.read(array, writeOffset, writeable)
|
||||
writePosition += read
|
||||
} else {
|
||||
val buffer = ByteArray(10 * 1024)
|
||||
val read = inputStream.read(buffer)
|
||||
put(buffer, 0, read)
|
||||
}
|
||||
}
|
||||
|
||||
fun putByte(byte: Byte): Unit = put(byte)
|
||||
fun putChar(char: Char): Unit = put(char)
|
||||
fun putShort(short: Short): Unit = put(short)
|
||||
|
Loading…
Reference in New Issue
Block a user