Here you can find the source of toInputStream(String input, Charset charset)
Parameter | Description |
---|---|
input | the string to be converted |
charset | the charset used in the conversion |
public static InputStream toInputStream(String input, Charset charset)
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.Charset; public class Main { /**//from ww w .jav a2 s . c o m * Convert the given string as an input stream that contains the string. * * @param input the string to be converted * @return the input stream that contains the string */ public static InputStream toInputStream(String input) { return toInputStream(input, Charset.forName("UTF-8")); } /** * Convert the given string as an input stream that contains the string using * the specified charset. * * @param input the string to be converted * @param charset the charset used in the conversion * @return the input stream that contains the string */ public static InputStream toInputStream(String input, Charset charset) { return (input != null && charset != null) ? new ByteArrayInputStream(input.getBytes(charset)) : null; } }