code: private byte [] getBytes(ByteBuffer bb) {
          /*
           * This should never return a BufferOverflowException, as we're
           * careful to allocate just the right amount.
           */
          byte [] buf = null;
  
          /*
           * If it has a usable backing byte buffer, use it.  Use only
           * if the array exactly represents the current ByteBuffer.
           */
          if (bb.hasArray()) {
              byte [] tmp = bb.array();
              if ((tmp.length == bb.capacity()) &&
                      (tmp.length == bb.remaining())) {
                  buf = tmp;
                  bb.position(bb.limit());
              }
          }
  
          if (buf == null) {
              /*
               * This class doesn't have a concept of encode(buf, len, off),
               * so if we have a partial buffer, we must reallocate
               * space.
               */
              buf = new byte[bb.remaining()];
  
              /*
               * position() automatically updated
               */
              bb.get(buf);
          }
  
          return buf;
      }
docs: Return a byte array from the remaining bytes in this ByteBuffer.
  <P>
  The ByteBuffer's position will be advanced to ByteBuffer's limit.
  <P>
  To avoid an extra copy, the implementation will attempt to return the
  byte array backing the ByteBuffer.  If this is not possible, a
  new byte array will be created.