package com.sdyc.ndmp.protobuf.serializer; import com.esotericsoftware.kryo.Kryo; import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; import org.apache.hadoop.io.Writable; import java.io.DataInputStream; import java.io.DataOutputStream; /** *
 *
 * Created by IntelliJ IDEA.
 * User: zhenqin
 * Date: 15/1/23
 * Time: 10:02
 * To change this template use File | Settings | File Templates.
 *
 * 
* * @author zhenqin */ public class WritableKryoSerializer extends com.esotericsoftware.kryo.Serializer { @Override public void write(Kryo kryo, Output output, Writable object) { try { object.write(new DataOutputStream(output)); } catch (Exception ex) { throw new IllegalArgumentException("Cannot deserialize", ex); } } @Override public Writable read(Kryo kryo, Input input, Class type) { try { Writable object = type.newInstance(); object.readFields(new DataInputStream(input)); return object; } catch (Exception ex) { throw new IllegalArgumentException("Cannot serialize", ex); } } }