I am in the situation that my algorithm has the 2 inputs of:
In the end, the returned result will be put into an OutputStream, an action which may happen multiple times, but at least once. There is no multithreading happening in this scenario.
I have found two solutions:
Delving into the code behind these methods shows a complex design for each underlying algorithm. I can't say I understand how to make a choice between these two options.
Which solution would generally be a better choice?
In both cases, a byte[] is built dynamically to encode the string. A more efficient approach is to have it written directly to the OutputStream. e.g.
OutputStreamWriter osw = new OutputStreamWriter(out, StandardCharsets.UTF_8);
// look Mum, no byte[] needed
osw.write(text);
An alternetive would to use DataOutputStream.writeUTF if you need a binary format.
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