@Override
public BSPCompressedBundle compressBundle(BSPMessageBundle<M> bundle) {
BSPCompressedBundle compMsgBundle = null;
ByteArrayOutputStream bos = null;
CompressionOutputStream sos = null;
DataOutputStream dos = null;
try {
bos = new ByteArrayOutputStream();
sos = codec.createOutputStream(bos);
dos = new DataOutputStream(sos);
bundle.write(dos);
dos.close(); // Flush the stream as no more data will be sent.
byte[] data = bos.toByteArray();
compMsgBundle = new BSPCompressedBundle(data);
} catch (IOException ioe) {
LOG.error("Unable to compress", ioe);
} finally {
try {
sos.close();
bos.close();
} catch (IOException e) {
LOG.warn("Failed to close compression streams.", e);
}
}