xpp.setInput(isw, null );  checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1); assertEquals("read() not called before next()", false, isw.calledRead());  xpp.nextToken(); assertEquals("read() must be called after next()", true, isw.calledRead());
    public void testSetInput() throws Exception {        XmlPullParser xpp = factory.newPullParser();        assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));        // another test        byte[] binput = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo/>").getBytes("UTF-8");        InputStreamWrapper isw = new InputStreamWrapper(            new ByteArrayInputStream( binput ));        assertEquals("no read() called in just contructed reader", false, isw.calledRead());        xpp.setInput(isw, "UTF-8");        assertEquals("UTF-8", xpp.getInputEncoding());        checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);        assertEquals("read() not called before next()", false, isw.calledRead());        xpp.nextToken();        assertEquals("read() must be called after next()", true, isw.calledRead());        // add BOM        //byte[] binput1 = new byte[]{((byte)'\u00FE'), ((byte)'\u00FF')};        //byte[] binput1 = new byte[]{((byte)'\u00FF'), ((byte)'\u00FE')};	byte[] binput1 = new byte[0];        byte[] binput2 =            ("<?xml version=\"1.0\" encoding=\"UTF-16\"?><foo/>").getBytes("UTF16");        binput = new byte[ binput1.length + binput2.length ] ;        System.arraycopy(binput1, 0, binput, 0, binput1.length);        System.arraycopy(binput2, 0, binput, binput1.length, binput2.length);        isw = new InputStreamWrapper(            new ByteArrayInputStream( binput ));        assertEquals("no read() called in just contructed reader", false, isw.calledRead());        //xpp.setInput(isw, "UTF-16" ); //TODO why Xerces2 causes java Unicode decoder to fail ????	xpp.setInput(isw, null );        //assertEquals("UTF-16", xpp.getInputEncoding());        checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);        assertEquals("read() not called before next()", false, isw.calledRead());        xpp.nextToken();        assertEquals("read() must be called after next()", true, isw.calledRead());        // check input detecting  -- for mutlibyte sequences ...        final String FEATURE_DETECT_ENCODING =            "http://xmlpull.org/v1/doc/features.html#detect-encoding";        if(xpp.getFeature(FEATURE_DETECT_ENCODING)) {            PackageTests.addNote("* optional feature "+FEATURE_DETECT_ENCODING+" is supported\n");            isw = new InputStreamWrapper(                new ByteArrayInputStream( binput ));            assertEquals("no read() called in just contructed reader", false, isw.calledRead());            xpp.setInput(isw, null );            assertEquals(null, xpp.getInputEncoding());            checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);            assertEquals("read() not called before next()", false, isw.calledRead());            xpp.nextToken();            assertEquals("read() must be called after next()", true, isw.calledRead());            assertEquals("UTF16", xpp.getInputEncoding());        }        // check input detecting  -- default        binput =            ("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><foo/>").getBytes("ISO-8859-1");        isw = new InputStreamWrapper(            new ByteArrayInputStream( binput ));        assertEquals("no read() called in just contructed reader", false, isw.calledRead());        xpp.setInput(isw, null );        assertEquals(null, xpp.getInputEncoding());        checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);        assertEquals("read() not called before next()", false, isw.calledRead());        xpp.next();        assertEquals("read() must be called after next()", true, isw.calledRead());        checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "foo", null, true/*empty*/, 0);        if(xpp.getFeature(FEATURE_DETECT_ENCODING)) {            assertEquals("ISO-8859-1", xpp.getInputEncoding());        }    }