All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zink.scala.fly.stub.SerializingFieldCodec.scala Maven / Gradle / Ivy

Go to download

Fly Scala is a scala client library for working with a Fly Server. Fly is an object space server that is specifically written to provide lightweight object based messaging between computers running on a network. This distribution does not contain the server, please go to http://www.flyobjectspace.com/ for the server that matches the version of Fly Scala you want to use.

The newest version!
package com.zink.scala.fly.stub

import com.zink.scala.fly.{FieldCodec, FlyPrime}
import com.zink.scala.fly.FlyAccessException._

import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.ObjectInputStream
import java.io.ObjectOutputStream

class SerializingFieldCodec extends FieldCodec {

  // buffer for coding objects into byte arrays
  private val bos = new ByteArrayOutputStream(FlyPrime.DEFAULT_BUFFER_SIZE)

  override def writeField(field: AnyRef): Array[Byte] = wrapExceptionIfThrown {
      bos.reset()
      val oos = new ObjectOutputStream(bos)
      oos.writeObject(field)
      oos.flush()
      bos.toByteArray
    }

  override def readField(fieldBytes: Array[Byte]): Option[AnyRef] = wrapExceptionIfThrown {
	  Option(new ObjectInputStream(new ByteArrayInputStream(fieldBytes)).readObject)
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy