/** * Returns <code>true</code> if this BOM's signature matches the given byte sequence. * * @param bytes the byte sequence to compare against this BOM's signature * @return true if this BOM's signature matches the given byte sequence */ public boolean sigEquals(byte bytes[]) { return bytes.length==sig.length && sigStartsWith(bytes); }
/** * Tests {@link BOM} comparison methods. */ @Test public void testBOMComparisons() { // Tests BOM#sigStartsWith method assert UTF8_BOM.sigStartsWith(new byte[]{(byte)0xEF, (byte)0xBB}); assert UTF8_BOM.sigStartsWith(new byte[]{(byte)0xEF, (byte)0xBB, (byte)0xBF}); assert !UTF8_BOM.sigStartsWith(new byte[]{(byte)0xAA}); assert !UTF8_BOM.sigStartsWith(new byte[]{(byte)0xEF, (byte)0xBB, (byte)0xBF, (byte)0xAA}); // Tests BOM#sigEquals method assert UTF8_BOM.sigEquals(UTF8_BOM.getSignature()); assert !UTF8_BOM.sigEquals(UTF16_LE_BOM.getSignature()); // Tests BOM#equals method assert UTF8_BOM.equals(UTF8_BOM); assert !UTF8_BOM.equals(UTF16_LE_BOM); assert !UTF8_BOM.equals(new Object()); }