code: private void shiftBufData() {
      if (bufRead != buf.limit()) {
        throw new IllegalStateException("bufRead should be same as " +
                                        "buf.limit()");
      }
      
      //shift the remaining data on buf to the front
      if (buf.position() > 0) {
        int dataLeft = buf.remaining();
        if (dataLeft > 0) {
          byte[] b = buf.array();
          System.arraycopy(b, buf.position(), b, 0, dataLeft);
        }
        buf.position(0);
        bufRead = dataLeft;
        buf.limit(bufRead);
      }
    }
docs: Makes sure buf.position() is zero without modifying buf.remaining().
  It moves the data if position needs to be changed.