code: public static InputStream string2InputStream(final String string, final String charsetName) {
          if (string == null || isSpace(charsetName)) return null;
          try {
              return new ByteArrayInputStream(string.getBytes(charsetName));
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
              return null;
          }
      }
docs: string转inputStream按编码
  
  @param string      字符串
  @param charsetName 编码格式
  @return 输入流