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;
}
}
Aggregations