Class ByteOrderMark

java.lang.Object
org.miaixz.bus.core.io.ByteOrderMark
All Implemented Interfaces:
Serializable, Comparable<ByteOrderMark>, Predicate<byte[]>

public class ByteOrderMark extends Object implements Predicate<byte[]>, Comparable<ByteOrderMark>, Serializable
Byte Order Mark (BOM) 头描述 BOM定义:http://www.unicode.org/unicode/faq/utf_bom.html
  • EF BB BF = UTF-8
  • FE FF = UTF-16BE, big-endian
  • FF FE = UTF-16LE, little-endian
  • 00 00 FE FF = UTF-32BE, big-endian
  • FF FE 00 00 = UTF-32LE, little-endian

来自:Apache-commons-io

Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Field Details

    • UTF_8

      public static final ByteOrderMark UTF_8
      UTF-8 BOM.
    • UTF_16BE

      public static final ByteOrderMark UTF_16BE
      UTF-16BE BOM (Big-Endian).
    • UTF_16LE

      public static final ByteOrderMark UTF_16LE
      UTF-16LE BOM (Little-Endian).
    • UTF_32BE

      public static final ByteOrderMark UTF_32BE
      UTF-32BE BOM (Big-Endian).
    • UTF_32LE

      public static final ByteOrderMark UTF_32LE
      UTF-32LE BOM (Little-Endian).
    • ALL

      public static final ByteOrderMark[] ALL
      预定义的所有BOM信息
  • Constructor Details

    • ByteOrderMark

      public ByteOrderMark(String charsetName, byte... bytes)
      构造
      Parameters:
      charsetName - BOM定义的编码名称
      bytes - BOM bytes
      Throws:
      IllegalArgumentException - 编码名称为空或者bytes为空
  • Method Details

    • getCharsetName

      public String getCharsetName()
      获取BOM头定义的编码名称.
      Returns:
      编码名称
    • length

      public int length()
      获取BOM头byte数
      Returns:
      BOM头byte数
    • get

      public int get(int pos)
      获取指定位置的byte值
      Parameters:
      pos - The position
      Returns:
      The specified byte
    • getBytes

      public byte[] getBytes()
      Gets a copier of the BOM's bytes.
      Returns:
      a copier of the BOM's bytes
    • test

      public boolean test(byte[] headBytes)
      是否匹配头部BOM信息 当提供的长度小于BOM需要检查的长度时,返回{code false}
      Specified by:
      test in interface Predicate<byte[]>
      Parameters:
      headBytes - 头部bytes
      Returns:
      是否匹配头部BOM信息
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(ByteOrderMark o)
      Specified by:
      compareTo in interface Comparable<ByteOrderMark>