bundles/org.apache.jasper.glassfish/src/org/apache/jasper/xmlparser/XMLEncodingDetector.java
private Object[] getEncodingName(byte[] b4, int count) {

        if (count < 2) {
            return new Object[]{"UTF-8", null, null};
        }

        // UTF-16, with BOM
        int b0 = b4[0] & 0xFF;
        int b1 = b4[1] & 0xFF;
        if (b0 == 0xFE && b1 == 0xFF) {
            // UTF-16, big-endian, with a BOM
            return new Object [] {"UTF-16BE", Boolean.TRUE,
                                  Boolean.TRUE};
        }
        /* SJSAS 6307968
        if (b0 == 0xFF && b1 == 0xFE) {
        */
        // BEGIN SJSAS 6307968
        if (count == 2 && b0 == 0xFF && b1 == 0xFE) {
        // END SJSAS 6307968
            // UTF-16, little-endian, with a BOM
            return new Object [] {"UTF-16LE", Boolean.FALSE,
                                  Boolean.TRUE};
        }

        // default to UTF-8 if we don't have enough bytes to make a
        // good determination of the encoding
        if (count < 3) {
            return new Object [] {"UTF-8", null, null};
        }

        // UTF-8 with a BOM
        int b2 = b4[2] & 0xFF;
        if (b0 == 0xEF && b1 == 0xBB && b2 == 0xBF) {
            return new Object [] {"UTF-8", null, Boolean.TRUE};
        }

        // default to UTF-8 if we don't have enough bytes to make a
        // good determination of the encoding
        if (count < 4) {
            return new Object [] {"UTF-8", null, null};
        }

        // other encodings
        int b3 = b4[3] & 0xFF;
        if (b0 == 0x00 && b1 == 0x00 && b2 == 0x00 && b3 == 0x3C) {
            // UCS-4, big endian (1234)
            return new Object [] {"ISO-10646-UCS-4", Boolean.TRUE, null};
        }
        if (b0 == 0x3C && b1 == 0x00 && b2 == 0x00 && b3 == 0x00) {
            // UCS-4, little endian (4321)
            return new Object [] {"ISO-10646-UCS-4", Boolean.FALSE, null};
        }
        if (b0 == 0x00 && b1 == 0x00 && b2 == 0x3C && b3 == 0x00) {
            // UCS-4, unusual octet order (2143)
            // REVISIT: What should this be?
            return new Object [] {"ISO-10646-UCS-4", null, null};
        }
        if (b0 == 0x00 && b1 == 0x3C && b2 == 0x00 && b3 == 0x00) {
            // UCS-4, unusual octect order (3412)
            // REVISIT: What should this be?
            return new Object [] {"ISO-10646-UCS-4", null, null};
        }
        if (b0 == 0x00 && b1 == 0x3C && b2 == 0x00 && b3 == 0x3F) {
            // UTF-16, big-endian, no BOM
            // (or could turn out to be UCS-2...
            // REVISIT: What should this be?
            return new Object [] {"UTF-16BE", Boolean.TRUE, null};
        }
        if (b0 == 0x3C && b1 == 0x00 && b2 == 0x3F && b3 == 0x00) {
            // UTF-16, little-endian, no BOM
            // (or could turn out to be UCS-2...
            return new Object [] {"UTF-16LE", Boolean.FALSE, null};
        }
        if (b0 == 0x4C && b1 == 0x6F && b2 == 0xA7 && b3 == 0x94) {
            // EBCDIC
            // a la xerces1, return CP037 instead of EBCDIC here
            return new Object [] {"CP037", null, null};
        }
        if (b0 == 0x00 && b1 == 0x00 && b2 == 0xFE && b3 == 0xFF) {
            // UTF-32, big-endian, with a BOM
            return new Object [] {"UTF-32BE", Boolean.TRUE,
                                  Boolean.TRUE};
        }
        if (b0 == 0xFF && b1 == 0xFE && b2 == 0x00 && b3 == 0x00) {
            // UTF-32, little-endian, with a BOM
            return new Object [] {"UTF-32LE", Boolean.FALSE,
                                  Boolean.TRUE};
        }
        // BEGIN SJSAS 6307968
        if (b0 == 0xFF && b1 == 0xFE) {
            // UTF-16, little-endian, with a BOM
            return new Object [] {"UTF-16LE", Boolean.FALSE,
                                  Boolean.TRUE};
        }
        // END SJSAS 6307968

        // default encoding
        return new Object [] {"UTF-8", null, null};

    }
private Object[] getEncodingName(byte[] b4, int count) {

        if (count < 2) {
            return new Object[]{"UTF-8", null, null};
        }

        // UTF-16, with BOM
        int b0 = b4[0] & 0xFF;
        int b1 = b4[1] & 0xFF;
        if (b0 == 0xFE && b1 == 0xFF) {
            // UTF-16, big-endian, with a BOM
            return new Object [] {"UTF-16BE", Boolean.TRUE,
                                  Boolean.TRUE};
        }
        /* SJSAS 6307968
        if (b0 == 0xFF && b1 == 0xFE) {
        */
        // BEGIN SJSAS 6307968
        if (count == 2 && b0 == 0xFF && b1 == 0xFE) {
        // END SJSAS 6307968
            // UTF-16, little-endian, with a BOM
            return new Object [] {"UTF-16LE", Boolean.FALSE,
                                  Boolean.TRUE};
        }

        // default to UTF-8 if we don't have enough bytes to make a
        // good determination of the encoding
        if (count < 3) {
            return new Object [] {"UTF-8", null, null};
        }

        // UTF-8 with a BOM
        int b2 = b4[2] & 0xFF;
        if (b0 == 0xEF && b1 == 0xBB && b2 == 0xBF) {
            return new Object [] {"UTF-8", null, Boolean.TRUE};
        }

        // default to UTF-8 if we don't have enough bytes to make a
        // good determination of the encoding
        if (count < 4) {
            return new Object [] {"UTF-8", null, null};
        }

        // other encodings
        int b3 = b4[3] & 0xFF;
        if (b0 == 0x00 && b1 == 0x00 && b2 == 0x00 && b3 == 0x3C) {
            // UCS-4, big endian (1234)
            return new Object [] {"ISO-10646-UCS-4", Boolean.TRUE, null};
        }
        if (b0 == 0x3C && b1 == 0x00 && b2 == 0x00 && b3 == 0x00) {
            // UCS-4, little endian (4321)
            return new Object [] {"ISO-10646-UCS-4", Boolean.FALSE, null};
        }
        if (b0 == 0x00 && b1 == 0x00 && b2 == 0x3C && b3 == 0x00) {
            // UCS-4, unusual octet order (2143)
            // REVISIT: What should this be?
            return new Object [] {"ISO-10646-UCS-4", null, null};
        }
        if (b0 == 0x00 && b1 == 0x3C && b2 == 0x00 && b3 == 0x00) {
            // UCS-4, unusual octect order (3412)
            // REVISIT: What should this be?
            return new Object [] {"ISO-10646-UCS-4", null, null};
        }
        if (b0 == 0x00 && b1 == 0x3C && b2 == 0x00 && b3 == 0x3F) {
            // UTF-16, big-endian, no BOM
            // (or could turn out to be UCS-2...
            // REVISIT: What should this be?
            return new Object [] {"UTF-16BE", Boolean.TRUE, null};
        }
        if (b0 == 0x3C && b1 == 0x00 && b2 == 0x3F && b3 == 0x00) {
            // UTF-16, little-endian, no BOM
            // (or could turn out to be UCS-2...
            return new Object [] {"UTF-16LE", Boolean.FALSE, null};
        }
        if (b0 == 0x4C && b1 == 0x6F && b2 == 0xA7 && b3 == 0x94) {
            // EBCDIC
            // a la xerces1, return CP037 instead of EBCDIC here
            return new Object [] {"CP037", null, null};
        }
        if (b0 == 0x00 && b1 == 0x00 && b2 == 0xFE && b3 == 0xFF) {
            // UTF-32, big-endian, with a BOM
            return new Object [] {"UTF-32BE", Boolean.TRUE,
                                  Boolean.TRUE};
        }
        if (b0 == 0xFF && b1 == 0xFE && b2 == 0x00 && b3 == 0x00) {
            // UTF-32, little-endian, with a BOM
            return new Object [] {"UTF-32LE", Boolean.FALSE,
                                  Boolean.TRUE};
        }
        // BEGIN SJSAS 6307968
        if (b0 == 0xFF && b1 == 0xFE) {
            // UTF-16, little-endian, with a BOM
            return new Object [] {"UTF-16LE", Boolean.FALSE,
                                  Boolean.TRUE};
        }
        // END SJSAS 6307968

        // default encoding
        return new Object [] {"UTF-8", null, null};

    }
private Object [ ] getEncodingName ( byte [ ] b4 , int count ) { if ( count < 2 ) { return new Object [ ] { "UTF-8" , null , null } ; } // UTF-16, with BOM int b0 = b4 [ 0 ] & 0xFF ; int b1 = b4 [ 1 ] & 0xFF ; if ( b0 == 0xFE && b1 == 0xFF ) { // UTF-16, big-endian, with a BOM return new Object [ ] { "UTF-16BE" , Boolean . TRUE , Boolean . TRUE } ; } /* SJSAS 6307968
        if (b0 == 0xFF && b1 == 0xFE) {
        */ // BEGIN SJSAS 6307968 if ( count == 2 && b0 == 0xFF && b1 == 0xFE ) { // END SJSAS 6307968 // UTF-16, little-endian, with a BOM return new Object [ ] { "UTF-16LE" , Boolean . FALSE , Boolean . TRUE } ; } // default to UTF-8 if we don't have enough bytes to make a // good determination of the encoding if ( count < 3 ) { return new Object [ ] { "UTF-8" , null , null } ; } // UTF-8 with a BOM int b2 = b4 [ 2 ] & 0xFF ; if ( b0 == 0xEF && b1 == 0xBB && b2 == 0xBF ) { return new Object [ ] { "UTF-8" , null , Boolean . TRUE } ; } // default to UTF-8 if we don't have enough bytes to make a // good determination of the encoding if ( count < 4 ) { return new Object [ ] { "UTF-8" , null , null } ; } // other encodings int b3 = b4 [ 3 ] & 0xFF ; if ( b0 == 0x00 && b1 == 0x00 && b2 == 0x00 && b3 == 0x3C ) { // UCS-4, big endian (1234) return new Object [ ] { "ISO-10646-UCS-4" , Boolean . TRUE , null } ; } if ( b0 == 0x3C && b1 == 0x00 && b2 == 0x00 && b3 == 0x00 ) { // UCS-4, little endian (4321) return new Object [ ] { "ISO-10646-UCS-4" , Boolean . FALSE , null } ; } if ( b0 == 0x00 && b1 == 0x00 && b2 == 0x3C && b3 == 0x00 ) { // UCS-4, unusual octet order (2143) // REVISIT: What should this be? return new Object [ ] { "ISO-10646-UCS-4" , null , null } ; } if ( b0 == 0x00 && b1 == 0x3C && b2 == 0x00 && b3 == 0x00 ) { // UCS-4, unusual octect order (3412) // REVISIT: What should this be? return new Object [ ] { "ISO-10646-UCS-4" , null , null } ; } if ( b0 == 0x00 && b1 == 0x3C && b2 == 0x00 && b3 == 0x3F ) { // UTF-16, big-endian, no BOM // (or could turn out to be UCS-2... // REVISIT: What should this be? return new Object [ ] { "UTF-16BE" , Boolean . TRUE , null } ; } if ( b0 == 0x3C && b1 == 0x00 && b2 == 0x3F && b3 == 0x00 ) { // UTF-16, little-endian, no BOM // (or could turn out to be UCS-2... return new Object [ ] { "UTF-16LE" , Boolean . FALSE , null } ; } if ( b0 == 0x4C && b1 == 0x6F && b2 == 0xA7 && b3 == 0x94 ) { // EBCDIC // a la xerces1, return CP037 instead of EBCDIC here return new Object [ ] { "CP037" , null , null } ; } if ( b0 == 0x00 && b1 == 0x00 && b2 == 0xFE && b3 == 0xFF ) { // UTF-32, big-endian, with a BOM return new Object [ ] { "UTF-32BE" , Boolean . TRUE , Boolean . TRUE } ; } if ( b0 == 0xFF && b1 == 0xFE && b2 == 0x00 && b3 == 0x00 ) { // UTF-32, little-endian, with a BOM return new Object [ ] { "UTF-32LE" , Boolean . FALSE , Boolean . TRUE } ; } // BEGIN SJSAS 6307968 if ( b0 == 0xFF && b1 == 0xFE ) { // UTF-16, little-endian, with a BOM return new Object [ ] { "UTF-16LE" , Boolean . FALSE , Boolean . TRUE } ; } // END SJSAS 6307968 // default encoding return new Object [ ] { "UTF-8" , null , null } ; }
Returns the IANA encoding name that is auto-detected from
the bytes specified, with the endian-ness of that encoding where
appropriate.

@param b4    The first four bytes of the input.
@param count The number of bytes actually read.
@return a 2-element array:  the first element, an IANA-encoding string,
the second element a Boolean which is true iff the document is big
endian, false if it's little-endian, and null if the distinction isn't
relevant.
Returns the IANA encoding name that is auto - detected from the bytes specified with the endian - ness of that encoding where appropriate .