Ultimately, you are going to send a stream anyway.
If you received data from another source outside your control as a massive byte[] , you can also save it in this form for your processing, if it is not convenient for you, and let it be transferred to the network stream down the line.
If you get it as a stream, it makes no sense to turn it into a massive byte[] so that it is transferred to another stream. Use a buffer size of 4 or 8 kiB (4 or 8, not 4-8, as there are some minor advantages in all matches with all memory numbers that you can use).
If you create it yourself, the stream in most cases is facilitated (wrapping in binary or text script, as well as its execution), as well as more efficient.
In general, if I see a buffer larger than 8kiB that is written to or read from the stream, I should note that you should try to change first if something seems too slow.
source share