code: public String substringTrimmed(final int beginIndex, final int endIndex) {
          if (beginIndex < 0) {
              throw new IndexOutOfBoundsException("Negative beginIndex: " + beginIndex);
          }
          if (endIndex > this.len) {
              throw new IndexOutOfBoundsException("endIndex: " + endIndex + " > length: " + this.len);
          }
          if (beginIndex > endIndex) {
              throw new IndexOutOfBoundsException("beginIndex: " + beginIndex + " > endIndex: " + endIndex);
          }
          int beginIndex0 = beginIndex;
          int endIndex0 = endIndex;
          while (beginIndex0 < endIndex && isWhitespace(this.array[beginIndex0])) {
              beginIndex0++;
          }
          while (endIndex0 > beginIndex0 && isWhitespace(this.array[endIndex0 - 1])) {
              endIndex0--;
          }
          return new String(this.array, beginIndex0, endIndex0 - beginIndex0);
      }
docs: Returns a substring of this buffer with leading and trailing whitespace
  omitted. The substring begins with the first non-whitespace character
  from {@code beginIndex} and extends to the last
  non-whitespace character with the index lesser than
  {@code endIndex}.
  
  @param      beginIndex   the beginning index, inclusive.
  @param      endIndex     the ending index, exclusive.
  @return     the specified substring.
  @throws  IndexOutOfBoundsException  if the
  {@code beginIndex} is negative, or
  {@code endIndex} is larger than the length of this
  buffer, or {@code beginIndex} is larger than
  {@code endIndex}.