本文整理汇总了Scala中org.apache.flume.source.avro.AvroFlumeEvent类的典型用法代码示例。如果您正苦于以下问题:Scala AvroFlumeEvent类的具体用法?Scala AvroFlumeEvent怎么用?Scala AvroFlumeEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AvroFlumeEvent类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: AvroFlumeEventEncoder
//设置package包名称以及导入依赖的类
package contrib.kafka.serializer
import kafka.serializer.Encoder
import kafka.utils.VerifiableProperties
import org.apache.avro.io.BinaryEncoder
import org.apache.avro.io.EncoderFactory
import org.apache.avro.specific.SpecificDatumWriter
import org.apache.flume.source.avro.AvroFlumeEvent
import java.io.ByteArrayOutputStream
import java.io.InputStream
class AvroFlumeEventEncoder(props: VerifiableProperties = null)
extends Encoder[AvroFlumeEvent] {
private val writer: SpecificDatumWriter[AvroFlumeEvent] =
new SpecificDatumWriter[AvroFlumeEvent](classOf[AvroFlumeEvent])
private var encoder: BinaryEncoder = null.asInstanceOf[BinaryEncoder]
private var tempOutStream = new ByteArrayOutputStream()
override def toBytes(event: AvroFlumeEvent): Array[Byte] = {
tempOutStream.reset()
encoder = EncoderFactory.get.directBinaryEncoder(tempOutStream, encoder)
writer.write(event, encoder)
tempOutStream.toByteArray
}
}
示例2: AvroFlumeEventDecoder
//设置package包名称以及导入依赖的类
package contrib.kafka.serializer
import kafka.serializer.Decoder
import kafka.utils.VerifiableProperties
import org.apache.avro.io.BinaryDecoder
import org.apache.avro.io.DecoderFactory
import org.apache.avro.specific.SpecificDatumReader
import org.apache.flume.Event
import org.apache.flume.event.EventBuilder
import org.apache.flume.source.avro.AvroFlumeEvent
import java.io.ByteArrayInputStream
class AvroFlumeEventDecoder(props: VerifiableProperties = null)
extends Decoder[Event] {
private val reader: SpecificDatumReader[AvroFlumeEvent] =
new SpecificDatumReader[AvroFlumeEvent](classOf[AvroFlumeEvent])
private var decoder: BinaryDecoder = null.asInstanceOf[BinaryDecoder]
override def fromBytes(bytes: Array[Byte]): Event = {
val inputStream = new ByteArrayInputStream(bytes)
decoder = DecoderFactory.get.directBinaryDecoder(inputStream, decoder)
val avroEvent: AvroFlumeEvent = reader.read(null, decoder)
EventBuilder.withBody(
avroEvent.getBody.array,
toStringJavaMap(avroEvent.getHeaders))
}
def toStringJavaMap(
charSeqMap: JMap[CharSequence, CharSequence]): JMap[String, String] = {
import scala.collection.JavaConversions._
for ((k: CharSequence, v: CharSequence) <- charSeqMap)
yield (k.toString, v.toString)
}
}