code: public static boolean isText(ByteBuf buf, int index, int length, Charset charset) {
          checkNotNull(buf, "buf");
          checkNotNull(charset, "charset");
          final int maxIndex = buf.readerIndex() + buf.readableBytes();
          if (index < 0 || length < 0 || index > maxIndex - length) {
              throw new IndexOutOfBoundsException("index: " + index + " length: " + length);
          }
          if (charset.equals(CharsetUtil.UTF_8)) {
              return isUtf8(buf, index, length);
          } else if (charset.equals(CharsetUtil.US_ASCII)) {
              return isAscii(buf, index, length);
          } else {
              CharsetDecoder decoder = CharsetUtil.decoder(charset, CodingErrorAction.REPORT, CodingErrorAction.REPORT);
              try {
                  if (buf.nioBufferCount() == 1) {
                      decoder.decode(buf.nioBuffer(index, length));
                  } else {
                      ByteBuf heapBuffer = buf.alloc().heapBuffer(length);
                      try {
                          heapBuffer.writeBytes(buf, index, length);
                          decoder.decode(heapBuffer.internalNioBuffer(heapBuffer.readerIndex(), length));
                      } finally {
                          heapBuffer.release();
                      }
                  }
                  return true;
              } catch (CharacterCodingException ignore) {
                  return false;
              }
          }
      }
docs: Returns {@code true} if the specified {@link ByteBuf} starting at {@code index} with {@code length} is valid
  text using the given {@link Charset}, otherwise return {@code false}.
  
  @param buf The given {@link ByteBuf}.
  @param index The start index of the specified buffer.
  @param length The length of the specified buffer.
  @param charset The specified {@link Charset}.
  
  @throws IndexOutOfBoundsException if {@code index} + {@code length} is greater than {@code buf.readableBytes}