Your code isn't thread-safe, basically.
You're accepting a synchronous call accepting a byte array - and then you're using that byte array later, and assuming it will still have the same content. What if the caller to write()
overwrites the data in the byte array immediately after the method returns? By the time you get to use it, you won't have the right data.
I would extract the String
from the byte array in your write
call, and then use that String
in the call to write0
.
(I'd also personally use a Writer
rather than an OutputStream
- fundamentally you want to deal with text data, not binary data.)