All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flipkart.hbaseobjectmapper.codec.JavaObjectStreamCodec Maven / Gradle / Ivy

Go to download

HBase ORM is a light-weight, thread-safe and performant library that enables: [1] object-oriented access of HBase rows (Data Access Object) with minimal code and good testability [2] reading from and/or writing to HBase tables in Hadoop MapReduce jobs

There is a newer version: 1.19
Show newest version
package com.flipkart.hbaseobjectmapper.codec;

import java.io.*;
import java.lang.reflect.Type;
import java.util.Map;

public class JavaObjectStreamCodec implements Codec {
    /*
     * @inherit
     */
    @Override
    public byte[] serialize(Serializable object, Map flags) throws SerializationException {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(object);
            return bos.toByteArray();
        } catch (Exception e) {
            throw new SerializationException("Could not serialize object to byte stream", e);
        }
    }

    /*
    * @inherit
    */
    @Override
    public Serializable deserialize(byte[] bytes, Type type, Map flags) throws DeserializationException {
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bis);
            return (Serializable) ois.readObject();
        } catch (Exception e) {
            throw new DeserializationException("Could not deserialize byte stream into an object", e);
        }
    }

    /*
    * @inherit
    */
    @Override
    public boolean canDeserialize(Type type) {
        return true;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy