public Object prepareWrite(IRemoteMessage message) {
Object objectToWrite = message;
ObjectOutputStream oos = null;
GZIPOutputStream gzos = null;
try {
// serialize obj
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
// oos.reset(); -- not needed here because the oos is
// always a new instance, reseted.
oos.writeUnshared(message);
byte[] byteObj = baos.toByteArray();
baos.reset();
// compact the serialization
gzos = new GZIPOutputStream(baos);
gzos.write(byteObj);
gzos.finish();
byteObj = baos.toByteArray();
objectToWrite = byteObj;
}
catch (Exception e) {
throw new RuntimeException("Can't prepare message", e); //$NON-NLS-1$
}
finally {
if (gzos != null)
try {
gzos.close();
} catch (IOException e) {}
if (oos != null)
try {
oos.close();