There a probably several ways to fix this. However, without knowing the context why you need an inputstream an answer might be might be sub optimal. So can you provide some more context on how you use the inputstream?
var response = HttpUtil.executeUrl(httpMethod, url , timeout);
for the connection to my web service.
But I need
var response = HttpUtil.executeUrl(httpMethod, url , input, contentType, timeout);
to pass the form parameters too. ‘input’ is a string variable, so I have to convert it with toInputStream(input) to a stream, because the 3rd parameter is of type stream
possible alternative
var stream = new java.io.ByteArrayInputStream(content.getBytes("UTF-8"))
var response = HttpUtil.executeUrl(httpMethod, url , stream, contentType, timeout);