![JAR search and dependency download from the Maven repository](/logo.png)
net.glorat.ledger.BinarySerializer.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dlstore_2.11 Show documentation
Show all versions of dlstore_2.11 Show documentation
Ledger state machine framework backed by Kafka distributed ledger store
The newest version!
package net.glorat.ledger
import java.io.{ByteArrayInputStream, ObjectInputStream}
/**
* Created by kevin on 25/4/2018.
*/
object BinarySerializer {
import java.io.{ByteArrayOutputStream, IOException, ObjectOutputStream}
val serializer = (data: Object) => {
try {
val baos = new ByteArrayOutputStream
val oos = new ObjectOutputStream(baos)
oos.writeObject(data)
oos.close()
val b = baos.toByteArray
b
} catch {
case e: IOException =>
new Array[Byte](0)
}
}
val deserializer = (bytes: Array[Byte]) => {
val bais = new ByteArrayInputStream(bytes)
val ois = new ObjectInputStream(bais)
val obj = ois.readObject()
ois.close()
obj
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy