You don’t have to close ByteArrayInputStream
, the moment it is not referenced by any variable, garbage collector will release the stream and somebytes
(of course assuming they aren’t referenced somewhere else).
However it is always a good practice to close every stream, in fact, maybe the implementation creating the stream will change in the future and instead of raw bytes you’ll be reading file? Also static code analyzing tools like PMD or FindBugs (see comments) will most likely complain.
If you are bored with closing the stream and being forced to handle impossible IOException
, you might use IOUtils:
IOUtils.closeQuietly(stream);