public static InputStream getStringInputStream(String string)
    {
        InputStream is = null;
        try   {
            ByteArrayOutputStream ba = new ByteArrayOutputStream();
            DataOutputStream os = new DataOutputStream(ba);
            os.writeUTF(string);
            os.flush();
            is = new ByteArrayInputStream(ba.toByteArray());
        } catch (IOException ex)    {
            ex.printStackTrace();
        }
        return is;
    }
public static InputStream getStringInputStream ( String string ) { InputStream is = null ; try { ByteArrayOutputStream ba = new ByteArrayOutputStream ( ) ; DataOutputStream os = new DataOutputStream ( ba ) ; os . writeUTF ( string ) ; os . flush ( ) ; is = new ByteArrayInputStream ( ba . toByteArray ( ) ) ; } catch ( IOException ex ) { ex . printStackTrace ( ) ; } return is ; }
A utility method to get an UTF-8 Input stream from a string.
@param string The string to be converted to an InputStream.
@return The input stream.