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

com.addc.commons.queue.persistence.DefaultElementSerializer Maven / Gradle / Ivy

Go to download

The addc-queues library supplies support for internal persistent queues using an optional DERBY database for storage.

The newest version!
package com.addc.commons.queue.persistence;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.addc.commons.queue.ElementSerializer;


/**
 * The MessageSerializer
 *
 */
public class DefaultElementSerializer implements ElementSerializer {

    @Override
    @SuppressWarnings("unchecked")
    public E deserializeItem(byte[] data) throws IOException, ClassNotFoundException {
        ByteArrayInputStream byteArrayInStream= new ByteArrayInputStream(data);
        ObjectInputStream objectInStream= new ObjectInputStream(byteArrayInStream);
        E message= (E) objectInStream.readObject();
        objectInStream.close();
        return message;
    }

    @Override
    public byte[] serializeItem(E element) throws IOException {
        ByteArrayOutputStream byteArrayOutStream= new ByteArrayOutputStream();
        ObjectOutputStream objectOutStream= new ObjectOutputStream(byteArrayOutStream);
        objectOutStream.writeObject(element);
        objectOutStream.flush();
        byte[] serializedEvent= byteArrayOutStream.toByteArray();
        objectOutStream.close();
        return serializedEvent;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy