I'm going to use apache commons method: IOUtils.toString(InputStream, "UTF-8");
Should I close passed InputStream
manually or library is smart enough to care about it?
I'm going to use apache commons method: IOUtils.toString(InputStream, "UTF-8");
Should I close passed InputStream
manually or library is smart enough to care about it?
As @Puce and @Ratshiḓaho Wayne have pointed out, There is nothing in the javadoc that says that the input stream you pass to the toString() method would be closed by the API.
It doesn't make sense for an API to close the stream that has been passed for converting the stream of bytes to string, since the stream could be re-read by the application elsewhere, if it supports reset
.
Here's the doc for your reference.
public static String toString(InputStream input,
Charset encoding)
throws IOException
Gets the contents of an InputStream as a String using the specified character encoding.
This method buffers the input internally, so there is no need to use a BufferedInputStream.