<p>If you have a <code>java.io.InputStream</code> object, how should you process that object and produce a <code>String</code>?</p>
<hr />
<p>Suppose I have an <code>InputStream</code> that contains text data, and I want to convert it to a <code>String</code>, so for example I can write that to a log file.</p>
<p>What is the easiest way to take the <code>InputStream</code> and convert it to a <code>String</code>?</p>
<pre><code>public String convertStreamToString(InputStream is) {
// ???
}
</code></pre>

A nice way to do this is using
Apache commons
```
IOUtils
```
to copy the
```
InputStream
```
into a
```
StringWriter
```
... something like
```
```
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, encoding);
String theString = writer.toString();
```
```
or even
```
```
// NB: does not close inputStream, you'll have to use try-with-resources for that
String theString = IOUtils.toString(inputStream, encoding);
```
```
Alternatively, you could use
```
ByteArrayOutputStream
```
if you don't want to mix your Streams and Writers