import java.io.ByteArrayOutputStream
import java.io.ByteArrayInputStream
import java.io.ObjectOutputStream
import java.io.ObjectInputStream
import org.apache.avro.Schema
class AvroSchemaConverter(schema: Schema) extends Serializable {
private val schemaBytes = AvroSchemaConverter.serializeSchema(schema)
def getSchema: Schema = AvroSchemaConverter.deserializeSchema(schemaBytes)
}
object AvroSchemaConverter {
def serializeSchema(schema: Schema): Array[Byte] = {
val stream = new ByteArrayOutputStream()
val oos = new ObjectOutputStream(stream)
oos.writeObject(schema)
oos.close()
stream.toByteArray
}
def deserializeSchema(bytes: Array[Byte]): Schema = {
val stream = new ByteArrayInputStream(bytes)
val ois = new ObjectInputStream(stream)
val schema = ois.readObject.asInstanceOf[Schema]
ois.close()
schema
}
}