BSPMessageCompressor<M> {
@Override
public byte[] compress(byte[] bytes) {
ByteArrayOutputStream bos = null;
SnappyOutputStream sos = null;
DataOutputStream dos = null;
byte[] compressedBytes = null;
try {
bos = new ByteArrayOutputStream();
sos = new SnappyOutputStream(bos);
dos = new DataOutputStream(sos);
dos.write(bytes);
dos.close(); // Flush the stream as no more data will be sent.
compressedBytes = bos.toByteArray();
} 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);
}
}