本文整理汇总了Scala中java.io.ObjectInput类的典型用法代码示例。如果您正苦于以下问题:Scala ObjectInput类的具体用法?Scala ObjectInput怎么用?Scala ObjectInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectInput类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: PlaceHolderSerializer
//设置package包名称以及导入依赖的类
package com.theseventhsense.utils.collections.mapdb
import java.io.{ObjectInput, _}
import cats.implicits._
import com.theseventhsense.utils.collections.mapdb.MapDBOffHeapIterator.SerializerProvider
import io.circe._
import org.mapdb.Serializer
object PlaceHolderSerializer extends Serializable {}
class CirceSerializer[A](implicit encoder: Encoder[A], decoder: Decoder[A]) extends Serializer[A] with Externalizable {
override def readExternal(in: ObjectInput): Unit = {}
override def writeExternal(out: ObjectOutput): Unit = {}
override def fixedSize(): Int = -1
def readLines(in: DataInput): String = {
try {
val inputLine = new StringBuffer()
var tmp: String = in.readLine
while (Option(tmp).isDefined) {
inputLine.append(tmp)
tmp = in.readLine
}
inputLine.toString
} catch {
case ioe: IOException ? ""
}
}
override def serialize(out: DataOutput, value: A): Unit = {
out.writeUTF(encoder.apply(value).noSpaces)
}
override def deserialize(in: DataInput, available: Int): A = {
val json = in.readUTF()
parser.decode[A](json).getOrElse(throw new RuntimeException(s"Unable to decode $json"))
}
}
object CirceSerializer {
class CirceSerializerProvider[A](implicit encoder: Encoder[A], decoder: Decoder[A]) extends SerializerProvider[A] {
def serializer: org.mapdb.Serializer[A] = new CirceSerializer[A]()
}
object Implicits {
implicit def serializer[A](implicit encoder: Encoder[A], decoder: Decoder[A]): SerializerProvider[A] =
new CirceSerializerProvider()
}
}