add typed put method

This commit is contained in:
tursom 2020-01-21 12:27:06 +08:00
parent 43836eb8b4
commit 5e7d84e856
2 changed files with 35 additions and 1 deletions

View File

@ -0,0 +1,16 @@
package cn.tursom.core
import java.text.SimpleDateFormat
class ThreadLocalSimpleDateFormat(val format: String) {
private val threadLocal = ThreadLocal<SimpleDateFormat>()
fun get(): SimpleDateFormat {
var simpleDateFormat: SimpleDateFormat? = threadLocal.get()
if (simpleDateFormat == null) {
simpleDateFormat = SimpleDateFormat(format)
threadLocal.set(simpleDateFormat)
}
return simpleDateFormat
}
}

View File

@ -3,7 +3,6 @@ package cn.tursom.core.buffer
import cn.tursom.core.forEachIndex
import java.io.Closeable
import java.io.OutputStream
import java.nio.Buffer
import kotlin.math.min
/**
@ -199,6 +198,25 @@ interface ByteBuffer : Closeable {
array.forEachIndex(index, index + size - 1, this::put)
}
fun putByte(byte: Byte): Unit = put(byte)
fun putChar(char: Char): Unit = put(char)
fun putShort(short: Short): Unit = put(short)
fun putInt(int: Int): Unit = put(int)
fun putLong(long: Long): Unit = put(long)
fun putFloat(float: Float): Unit = put(float)
fun putDouble(double: Double): Unit = put(double)
fun putString(str: String): Unit = put(str)
fun putBuffer(buffer: ByteBuffer): Int = put(buffer)
fun putBytes(byteArray: ByteArray, startIndex: Int = 0, endIndex: Int = byteArray.size - startIndex) =
put(byteArray, startIndex, endIndex)
fun putChars(array: CharArray, index: Int = 0, size: Int = array.size - index) = put(array, index, size)
fun putShorts(array: ShortArray, index: Int = 0, size: Int = array.size - index) = put(array, index, size)
fun putInts(array: IntArray, index: Int = 0, size: Int = array.size - index) = put(array, index, size)
fun putLongs(array: LongArray, index: Int = 0, size: Int = array.size - index) = put(array, index, size)
fun putFloats(array: FloatArray, index: Int = 0, size: Int = array.size - index) = put(array, index, size)
fun putDoubles(array: DoubleArray, index: Int = 0, size: Int = array.size - index) = put(array, index, size)
fun fill(byte: Byte) {
readPosition = 0
writePosition = 0