code: public static InputStream toInputStream(String str, Charset charset) {
          return new ByteArrayInputStream(str.getBytes(charset));
      }
docs: Turns a {@code String} into an {@code InputStream} containing the string's encoded characters.
  
  @param str     the string
  @param charset the {@link Charset} to use when encoding the string.
  @return an {@link InputStream} containing the string's encoded characters.