private static String getXMLGuessEncoding(final BufferedInputStream is) throws IOException {
        String encoding = null;
        final int[] bytes = new int[4];
        is.mark(4);
        bytes[0] = is.read();
        bytes[1] = is.read();
        bytes[2] = is.read();
        bytes[3] = is.read();
        is.reset();

        if (bytes[0] == 0x00 && bytes[1] == 0x3C && bytes[2] == 0x00 && bytes[3] == 0x3F) {
            encoding = UTF_16BE;
        } else if (bytes[0] == 0x3C && bytes[1] == 0x00 && bytes[2] == 0x3F && bytes[3] == 0x00) {
            encoding = UTF_16LE;
        } else if (bytes[0] == 0x3C && bytes[1] == 0x3F && bytes[2] == 0x78 && bytes[3] == 0x6D) {
            encoding = UTF_8;
        } else if (bytes[0] == 0x4C && bytes[1] == 0x6F && bytes[2] == 0xA7 && bytes[3] == 0x94) {
            encoding = CP1047;
        }
        return encoding;
    }
private static String getXMLGuessEncoding ( final BufferedInputStream is ) throws IOException { String encoding = null ; final int [ ] bytes = new int [ 4 ] ; is . mark ( 4 ) ; bytes [ 0 ] = is . read ( ) ; bytes [ 1 ] = is . read ( ) ; bytes [ 2 ] = is . read ( ) ; bytes [ 3 ] = is . read ( ) ; is . reset ( ) ; if ( bytes [ 0 ] == 0x00 && bytes [ 1 ] == 0x3C && bytes [ 2 ] == 0x00 && bytes [ 3 ] == 0x3F ) { encoding = UTF_16BE ; } else if ( bytes [ 0 ] == 0x3C && bytes [ 1 ] == 0x00 && bytes [ 2 ] == 0x3F && bytes [ 3 ] == 0x00 ) { encoding = UTF_16LE ; } else if ( bytes [ 0 ] == 0x3C && bytes [ 1 ] == 0x3F && bytes [ 2 ] == 0x78 && bytes [ 3 ] == 0x6D ) { encoding = UTF_8 ; } else if ( bytes [ 0 ] == 0x4C && bytes [ 1 ] == 0x6F && bytes [ 2 ] == 0xA7 && bytes [ 3 ] == 0x94 ) { encoding = CP1047 ; } return encoding ; }
stream, '<?xm'