With your attempt you are always reading the first 8000 bytes in a buffer, even if the already the first byte is null. And then, after you have buffered the first 8000 bytes you again process them (up to the first null).

I suggest a solution which buffers everything up to the first null byte or the 8000th byte - whatever comes first (so potentially we buffer much smaller amount of data). And whenever you detect the first binary artefact (a decision which should be taken by RawText) you can stop doing the buffering & conversion for the rest of the stream.

But I see one problem with what I suggest: We would have to have a method RawText.isBinary(byte) (so we can ask RawText for every single byte we get). Do you expect that (e.g. with UTF-16 support) we come into a situation where RawText can't decide on binary/not-binary by looking at a single byte? If yes, then I agree that it's better to stay with your approach.