/** * Checks if a BOM is waiting for being written, and if there is, writes it to the underlying output stream. * * @throws IOException if an error occurred while writing the BOM */ protected void checkWriteBOM() throws IOException { if(!bomWriteChecked) { if(bom!=null) out.write(bom.getSignature()); bomWriteChecked = true; } }
tempBomSig = tempBom.getSignature(); if(tempBomSig.length>bestMatchLength && startsWith(bytes, tempBomSig)) { bestMatchIndex = i;
/** * 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()); }
bomIn = getBOMInputStream(bom.getSignature()); assert bom.equals(bomIn.getBOM()); assertEOF(bomIn); b = UTF16_BE_BOM.getSignature(); bomIn = getBOMInputStream(b); assert !UTF8_BOM.equals(bomIn.getBOM());