Created
January 30, 2018 12:35
-
-
Save fayimora/119ab972cdbc045ba97db8154a7c13a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream} | |
object Serialization extends App { | |
def serialise(value: Any): Array[Byte] = { | |
val stream: ByteArrayOutputStream = new ByteArrayOutputStream() | |
val oos = new ObjectOutputStream(stream) | |
oos.writeObject(value) | |
oos.close | |
stream.toByteArray | |
} | |
def deserialise(bytes: Array[Byte]): Any = { | |
val ois = new ObjectInputStream(new ByteArrayInputStream(bytes)) | |
val value = ois.readObject | |
ois.close | |
value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment