} else if (tryEncoding (signature, (byte) 0x00, (byte) 0x00, (byte) 0x3c, (byte) 0x00)) {  encoding = ENCODING_UCS_4_2143;
else if (tryEncoding(signature, (byte) 0xfe, (byte) 0xff)) {   encoding = ENCODING_UCS_2_12; is.read(); is.read(); } else if (tryEncoding(signature, (byte) 0xff, (byte) 0xfe)) {   encoding = ENCODING_UCS_2_21; is.read(); is.read(); } else if (tryEncoding(signature, (byte) 0x00, (byte) 0x3c, (byte) 0x00, (byte) 0x3f)) {   encoding = ENCODING_UCS_2_12; error("no byte-order mark for UCS-2 entity"); } else if (tryEncoding(signature, (byte) 0x3c, (byte) 0x00, (byte) 0x3f, (byte) 0x00)) {   encoding = ENCODING_UCS_2_21; error("no byte-order mark for UCS-2 entity"); }
    private void detectEncoding ()    throws SAXException, IOException    {	byte signature[] = new byte [4];	// Read the first four bytes for	// autodetection.	is.mark (4);	is.read (signature);	is.reset ();	//	// FIRST:  four byte encodings (who uses these?)	//	if (tryEncoding (signature, (byte) 0x00, (byte) 0x00,			  (byte) 0x00, (byte) 0x3c)) {	    // UCS-4 must begin with "<?xml"	    // 0x00 0x00 0x00 0x3c: UCS-4, big-endian (1234)	    // "UTF-32BE"	    encoding = ENCODING_UCS_4_1234;	} else if (tryEncoding (signature, (byte) 0x3c, (byte) 0x00,				 (byte) 0x00, (byte) 0x00)) {	    // 0x3c 0x00 0x00 0x00: UCS-4, little-endian (4321)	    // "UTF-32LE"	    encoding = ENCODING_UCS_4_4321;	} else if (tryEncoding (signature, (byte) 0x00, (byte) 0x00,				 (byte) 0x3c, (byte) 0x00)) {	    // 0x00 0x00 0x3c 0x00: UCS-4, unusual (2143)	    encoding = ENCODING_UCS_4_2143;	} else if (tryEncoding (signature, (byte) 0x00, (byte) 0x3c,				 (byte) 0x00, (byte) 0x00)) {	    // 0x00 0x3c 0x00 0x00: UCS-4, unusual (3421)	    encoding = ENCODING_UCS_4_3412;	    // 00 00 fe ff UCS_4_1234 (with BOM)	    // ff fe 00 00 UCS_4_4321 (with BOM)	}	//	// SECOND:  two byte encodings	// note ... with 1/14/2000 errata the XML spec identifies some	// more "broken UTF-16" autodetection cases, with no XML decl,	// which we don't handle here (that's legal too).	//	else if (tryEncoding (signature, (byte) 0xfe, (byte) 0xff)) {	    // UCS-2 with a byte-order marker. (UTF-16)	    // 0xfe 0xff: UCS-2, big-endian (12)	    encoding = ENCODING_UCS_2_12;	    is.read (); is.read ();	} else if (tryEncoding (signature, (byte) 0xff, (byte) 0xfe)) {	    // UCS-2 with a byte-order marker. (UTF-16)	    // 0xff 0xfe: UCS-2, little-endian (21)	    encoding = ENCODING_UCS_2_21;	    is.read (); is.read ();	} else if (tryEncoding (signature, (byte) 0x00, (byte) 0x3c,				 (byte) 0x00, (byte) 0x3f)) {	    // UTF-16BE (otherwise, malformed UTF-16)	    // 0x00 0x3c 0x00 0x3f: UCS-2, big-endian, no byte-order mark	    encoding = ENCODING_UCS_2_12;	    error ("no byte-order mark for UCS-2 entity");	} else if (tryEncoding (signature, (byte) 0x3c, (byte) 0x00,				 (byte) 0x3f, (byte) 0x00)) {	    // UTF-16LE (otherwise, malformed UTF-16)	    // 0x3c 0x00 0x3f 0x00: UCS-2, little-endian, no byte-order mark	    encoding = ENCODING_UCS_2_21;	    error ("no byte-order mark for UCS-2 entity");	}	//	// THIRD:  ASCII-derived encodings, fixed and variable lengths	//	else if (tryEncoding (signature, (byte) 0x3c, (byte) 0x3f,			       (byte) 0x78, (byte) 0x6d)) {	    // ASCII derived	    // 0x3c 0x3f 0x78 0x6d: UTF-8 or other 8-bit markup (read ENCODING)	    encoding = ENCODING_UTF_8;	    prefetchASCIIEncodingDecl ();	} else if (signature [0] == (byte) 0xef		&& signature [1] == (byte) 0xbb		&& signature [2] == (byte) 0xbf) {	    // 0xef 0xbb 0xbf: UTF-8 BOM (not part of document text)	    // this un-needed notion slipped into XML 2nd ed through a	    // "non-normative" erratum; now required by MSFT and UDDI,	    // and E22 made it normative.	    encoding = ENCODING_UTF_8;	    is.read (); is.read (); is.read ();	} else {	    // 4c 6f a7 94 ... we don't understand EBCDIC flavors	    // ... but we COULD at least kick in some fixed code page	    // (default) UTF-8 without encoding/XML declaration	    encoding = ENCODING_UTF_8;	}    }