* Serializes o by getting a Hadoop Serializer based of the object's class.
* @param o object to serialize
* @return the serialized byte[] array.
*/
private byte[] internalSerialize(Object o) {
Serializer serializer = getNewSerializer(o.getClass());
// Write the object into an in-memory byte array.
ByteArrayOutputStream byteOs = new ByteArrayOutputStream();
try {
serializer.open(byteOs);
serializer.serialize(o);
serializer.close();
} catch (IOException ex) {
// This should never happen since we're writing to an in-memory ByteArrayOutputStream.
throw new RuntimeException(ex);
}
return byteOs.toByteArray();