1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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;
- /**
- * <pre>
- *
- * Created by IntelliJ IDEA.
- * User: zhenqin
- * Date: 15/1/23
- * Time: 10:02
- * To change this template use File | Settings | File Templates.
- *
- * </pre>
- *
- * @author zhenqin
- */
- public class WritableKryoSerializer extends com.esotericsoftware.kryo.Serializer<Writable> {
- @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<Writable> type) {
- try {
- Writable object = type.newInstance();
- object.readFields(new DataInputStream(input));
- return object;
- } catch (Exception ex) {
- throw new IllegalArgumentException("Cannot serialize", ex);
- }
- }
- }
|