Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Java have methods to get the various byte order marks?

I am looking for a utility method or constant in Java that will return me the bytes that correspond to the appropriate byte order mark for an encoding, but I can't seem to find one. Is there one? I really would like to do something like:

byte[] bom = Charset.forName( CharEncoding.UTF8 ).getByteOrderMark();

Where CharEncoding comes from Apache Commons.

like image 311
Brandon DuRette Avatar asked Dec 22 '22 12:12

Brandon DuRette


1 Answers

Java does not recognize byte order marks for UTF-8. See bugs 4508058 and 6378911.

The gist is that support was added, broke backwards compatibility, and was rolled back. You'll have to do BOM recognition in UTF-8 yourself.

like image 172
Adam Jaskiewicz Avatar answered Apr 07 '23 13:04

Adam Jaskiewicz