Well, will ByteArrayOutputStream cause memory overflow if it doesn't properly flush and close? I mean are they necessary to be put in the code or Java will garbage-collect it?
Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.
Yes it is thread safe, or rather all its methods are synchronized, and ProcessBuilder.
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).
The ByteArrayOutputStream class of the java.io package can be used to write an array of output data (in bytes). It extends the OutputStream abstract class. Note: In ByteArrayOutputStream maintains an internal array of bytes to store the data.
No, it will get garbage collected once the last reference to it is lost.
Per the javadoc:
Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.
Also, if you look at the code, both flush
and close
are no-ops in the ByteArrayOutputStream
class (although flush
is inherited from OutputStream
, it is a no-op in OutputStream
unless overridden in the specific implementation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With