Ich habe folgenden Scala-Code zu konvertieren (short, int, long, float, double, bigint) in Byte-Array.Konvertierung von Zahlen (short, int, long, float, double, bigint) in Byte-Array: Scala/Java
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
}
}
Ist das alles benötigt? Muss ich am Ende alle Reinigungsmethoden nennen solche
clear()
,mark()
,reset()
, um sicherzustellen, gibt es keine ByteBufferLecks Wenn ich
allocateDirect
Methoden zu verwenden, unter Ausnahme auslöst. Also, bedeutet esallocateDirect
Methode hat keine Backing-Array?
Exception in thread "main" java.lang.UnsupportedOperationException bei java.nio.ByteBuffer.array (ByteBuffer.java:994)