class GzipCompressionService implements CompressionService {

    @Override
    public ByteArrayOutputStream compress(final InputStream inputStream) {
        InputStream source = inputStream;
        ByteArrayOutputStream baos = outputStreamFactory.createByteArrayOutputStream();
        try {
            GZIPOutputStream gout = gzipOutputStreamFactory.createOutputStream(baos);
            //... Code to read from your original uncompressed data and write to gout.
            IOUtils.copy(source, gout);
            gout.finish();
            gout.close();
        } catch (IOException e) {
            throw new SystemException("Could not gzip message body!", e);
        }
        return baos;
    }

}