Java ByteOrderMark-class And Method Code Example

Here's an example of how to use the ByteOrderMark class from the package in Java:


public class Main {
    public static void main(String[] args) {
        // Get the UTF-8 BOM
        ByteOrderMark bom = ByteOrderMark.UTF_8;
        System.out.println("The byte order mark for UTF-8 is: " + bom.getValue());
        // Check if a byte array contains a specific BOM
        byte[] bytes = {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF}; // UTF-8 BOM
        if (bom.hasLeadingSequence(bytes)) {
            System.out.println("The byte array contains the UTF-8 BOM.");
        } else {
            System.out.println("The byte array does not contain the UTF-8 BOM.");

This example shows how to get the value of the UTF-8 byte order mark (BOM) using the ByteOrderMark.UTF_8 constant and how to check if a byte array contains a specific BOM using the hasLeadingSequence() method.