I have a byte stream that may be UTF-8 data or it may be a binary image. I should be able to make an educated guess about which one it is by inspecting the first 100 bytes or so.
However, I haven't figured out exactly how to do this in Java. I've tried doing things like the following:
new String( bytes, "UTF-8").substring(0,100).matches(".*[^\p{Print}]") to see if the first 100 chars contain non-printable characters, but that doesn't seem to work.
Is there a better way to do this?