Convert a stream of bytes to a String (UTF-8 encoded)
10,706
So would be new String(bytes, "UTF-8");
You would need to filter the Stream beforehand though.
Author by
Guillaume Brunerie
Updated on June 04, 2022Comments
-
Guillaume Brunerie almost 2 years
I have a stream of bytes (given by a BufferedInputStream) which represents a sequence of UTF-8 strings. The protocol is a little crappy becauses it uses 0xFF between commands, which implies that the whole stream is not a valid UTF-8 string, only the parts between the 0xFF are.
How can I extract those UTF-8 strings.
I don’t think BufferedReader would work, because the 0xFF will mess up everything and I have found no byte array to UTF-8 string conversion function.