code: private static byte[] extractBytes(
        String str, 
        int startIndex, 
        int endIndex,
        char[] charArray, 
        boolean canFastConvert) throws UnsupportedEncodingException {
      if (canFastConvert) {
        // fast conversion, just copy the raw bytes
        final int len = endIndex - startIndex;
        byte[] strBytes = new byte[len];
        for (int i = 0; i < len; i++) {
          strBytes[i] = (byte) charArray[startIndex + i];
        }
        return strBytes;
      } 
      // otherwise, do expensive conversion
      return str.substring(startIndex, endIndex).getBytes(utf8charsetName);
    }
docs: Helper for extracting bytes either from "str"
  or from the array of chars "charArray",
  depending if fast conversion is possible,
  specified by "canFastConvert"