private final BZip2Codec codec = new BZip2Codec();
@Override
public byte[] compress(byte[] bytes) {
ByteArrayOutputStream bos = null;
CompressionOutputStream sos = null;
DataOutputStream dos = null;
byte[] compressedBytes = null;
try {
bos = new ByteArrayOutputStream();
sos = codec.createOutputStream(bos);
dos = new DataOutputStream(sos);
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);
}
}