code: public static int compress(ByteBuffer uncompressed, ByteBuffer compressed)
              throws IOException
      {
  
          if (!uncompressed.isDirect()) {
              throw new SnappyError(SnappyErrorCode.NOT_A_DIRECT_BUFFER, "input is not a direct buffer");
          }
          if (!compressed.isDirect()) {
              throw new SnappyError(SnappyErrorCode.NOT_A_DIRECT_BUFFER, "destination is not a direct buffer");
          }
  
          // input: uncompressed[pos(), limit())
          // output: compressed
          int uPos = uncompressed.position();
          int uLen = uncompressed.remaining();
          int compressedSize = impl.rawCompress(uncompressed, uPos, uLen, compressed,
                  compressed.position());
  
          //         pos  limit
          // [ ......BBBBBBB.........]
          compressed.limit(compressed.position() + compressedSize);
  
          return compressedSize;
      }
docs: Compress the content in the given input buffer. After the compression,
  you can retrieve the compressed data from the output buffer [pos() ...
  limit()) (compressed data size = limit() - pos() = remaining())
  
  @param uncompressed buffer[pos() ... limit()) containing the input data
  @param compressed output of the compressed data. Uses range [pos()..].
  @return byte size of the compressed data.
  @throws SnappyError when the input is not a direct buffer