Search in sources :

Example 1 with SeekableByteArrayOutputStream

use of util.misc.SeekableByteArrayOutputStream in project GIPC by pdewan.

the class ASimpleSerializer method outputBufferFromObjects.

public ByteBuffer outputBufferFromObjects(Object[] objects) {
    try {
        SeekableByteArrayOutputStream byteArrayOutputStream = new SeekableByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        for (int i = 0; i < objects.length; i++) {
            Tracer.info(this, "Serializing object " + objects[i]);
            objectOutputStream.writeObject(objects[i]);
        }
        objectOutputStream.flush();
        ByteBuffer retVal = ByteBuffer.wrap(byteArrayOutputStream.getBuffer(), 0, byteArrayOutputStream.size());
        // Tracer.info(this, "Converted serialized data " + retVal);
        Tracer.info(this, "Buffer with serialized objects:" + retVal);
        return retVal;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : ObjectOutputStream(java.io.ObjectOutputStream) ByteBuffer(java.nio.ByteBuffer) SeekableByteArrayOutputStream(util.misc.SeekableByteArrayOutputStream) EOFException(java.io.EOFException)

Aggregations

EOFException (java.io.EOFException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 SeekableByteArrayOutputStream (util.misc.SeekableByteArrayOutputStream)1