What is the actual type of your OutputStream ? Since this is an abstract class, it does not say where the data actually goes (or if it even goes anywhere).
But suppose you're talking about ByteArrayOutputStream , as it at least stores data in memory (unlike many others).
If you create a ByteArrayInputStream from your buffer, there is no duplicated memory. This is the whole idea of ββstreaming.
source share