code: public void compress() {
          IoBuffer tmp = IoBuffer.allocate(0);
          tmp.setAutoExpand(true);
          byte[] tmpData = new byte[data.limit()];
          data.position(0);
          data.get(tmpData);
          try (DeflaterOutputStream deflater = new DeflaterOutputStream(tmp.asOutputStream(), new Deflater(Deflater.BEST_COMPRESSION))) {
              deflater.write(tmpData);
              deflater.finish();
          } catch (IOException e) {
              //docs state that free is optional
              tmp.free();
              throw new RuntimeException("could not compress data", e);
          }
          data.free();
          data = tmp;
          data.flip();
          prepareIO();
      }
docs: Compress contents using zlib.