将数字(short、int、long、float、double、bigint)转换为字节数组:Scala/Java
下面是将(short、int、long、float、double、bigint)转换为字节数组的scala代码将数字(short、int、long、float、double、bigint)转换为字节数组:Scala/Java,java,scala,bytebuffer,Java,Scala,Bytebuffer,下面是将(short、int、long、float、double、bigint)转换为字节数组的scala代码 def getByteArray(value: Any, of_type: String) = { of_type match { case "short" => ByteBuffer.allocate(2).putShort(value.asInstanceOf[Short]).array() case "int" => ByteBuffe
def getByteArray(value: Any, of_type: String) = {
of_type match {
case "short" => ByteBuffer.allocate(2).putShort(value.asInstanceOf[Short]).array()
case "int" => ByteBuffer.allocate(4).putInt(value.asInstanceOf[Int]).array()
case "long" => ByteBuffer.allocate(8).putLong(value.asInstanceOf[Long]).array()
case "float" => ByteBuffer.allocate(4).putFloat(value.asInstanceOf[Float]).array()
case "double" => ByteBuffer.allocate(8).putDouble(value.asInstanceOf[Double]).array()
case "bigint" => BigInt(value.toString).toByteArray
}
}
clear()
,mark()
,reset()
,以确保没有ByteBuffer泄漏allocateDirect
方法时,它抛出以下异常。那么,这是否意味着allocateDirect
方法没有支持数组