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

org.mydotey.codec.AbstractCodec Maven / Gradle / Ivy

The newest version!
package org.mydotey.codec;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Objects;

/**
 * @author koqizhao
 *
 * Nov 12, 2018
 */
public abstract class AbstractCodec implements Codec {

    @Override
    public byte[] encode(Object obj) {
        Objects.requireNonNull(obj, "obj is null");

        return doEncode(obj);
    }

    @Override
    public  T decode(byte[] is, Class clazz) {
        Objects.requireNonNull(is, "is is null");
        Objects.requireNonNull(clazz, "clazz is null");

        return doDecode(is, clazz);
    }

    @Override
    public void encode(OutputStream os, Object obj) {
        Objects.requireNonNull(os, "os is null");
        Objects.requireNonNull(obj, "obj is null");

        doEncode(os, obj);
    }

    @Override
    public  T decode(InputStream is, Class clazz) {
        Objects.requireNonNull(is, "is is null");
        Objects.requireNonNull(clazz, "clazz is null");

        return doDecode(is, clazz);
    }

    protected abstract byte[] doEncode(Object obj);

    protected abstract  T doDecode(byte[] is, Class clazz);

    protected abstract void doEncode(OutputStream os, Object obj);

    protected abstract  T doDecode(InputStream is, Class clazz);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy