Package com.rometools.rome.io

Examples of com.rometools.rome.io.XmlReader


        }
    }

    protected void testRawNoBomInvalid(final String encoding) throws Exception {
        InputStream is = null;
        XmlReader xmlReader = null;
        try {
            is = getXmlStream("no-bom", XML3, encoding, encoding);
            xmlReader = new XmlReader(is, false);
            fail("It should have failed");
        } catch (final IOException ex) {
            assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1);
        } finally {
            if (xmlReader != null) {
                xmlReader.close();
            }
            if (is != null) {
                is.close();
            }
        }
View Full Code Here


        testRawNoBomValid("ISO-8859-1");
    }

    protected void testRawBomValid(final String encoding) throws Exception {
        final InputStream is = getXmlStream(encoding + "-bom", XML3, encoding, encoding);
        final XmlReader xmlReader = new XmlReader(is, false);
        if (!encoding.equals("UTF-16")) {
            assertEquals(xmlReader.getEncoding(), encoding);
        } else {
            assertEquals(xmlReader.getEncoding().substring(0, encoding.length()), encoding);
        }
        xmlReader.close();
    }
View Full Code Here

    }

    protected void testRawBomInvalid(final String bomEnc, final String streamEnc, final String prologEnc) throws Exception {
        final InputStream is = getXmlStream(bomEnc, XML3, streamEnc, prologEnc);
        try {
            final XmlReader xmlReader = new XmlReader(is, false);
            fail("It should have failed for BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc);
            xmlReader.close();
        } catch (final IOException ex) {
            assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1);
        }
    }
View Full Code Here

        testHttpLenient("text/html;charset=UTF-16BE", "no-bom", "US-ASCII", "UTF-8", "UTF-8");
    }

    public void testAlternateDefaultEncoding(final String cT, final String bomEnc, final String streamEnc, final String prologEnc, final String alternateEnc)
            throws Exception {
        XmlReader xmlReader = null;
        try {
            final InputStream is;
            if (prologEnc == null) {
                is = getXmlStream(bomEnc, XML1, streamEnc, prologEnc);
            } else {
                is = getXmlStream(bomEnc, XML3, streamEnc, prologEnc);
            }
            XmlReader.setDefaultEncoding(alternateEnc);
            xmlReader = new XmlReader(is, cT, false);
            if (!streamEnc.equals("UTF-16")) {
                // we can not assert things here becuase UTF-8, US-ASCII and
                // ISO-8859-1 look alike for the chars used for detection
            } else {
                assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc);
            }
        } finally {
            XmlReader.setDefaultEncoding(null);
            if (xmlReader != null) {
                xmlReader.close();
            }
        }
    }
View Full Code Here

        if (prologEnc == null) {
            is = getXmlStream(bomEnc, XML1, streamEnc, prologEnc);
        } else {
            is = getXmlStream(bomEnc, XML3, streamEnc, prologEnc);
        }
        final XmlReader xmlReader = new XmlReader(is, cT, false);
        if (!streamEnc.equals("UTF-16")) {
            // we can not assert things here becuase UTF-8, US-ASCII and
            // ISO-8859-1 look alike for the chars used for detection
        } else {
            assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc);
        }
        xmlReader.close();
    }
View Full Code Here

            is = getXmlStream(bomEnc, XML2, streamEnc, prologEnc);
        } else {
            is = getXmlStream(bomEnc, XML3, streamEnc, prologEnc);
        }
        try {
            new XmlReader(is, cT, false);
            fail("It should have failed for HTTP Content-type " + cT + ", BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc);
        } catch (final IOException ex) {
            assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1);
        }
    }
View Full Code Here

        if (prologEnc == null) {
            is = getXmlStream(bomEnc, XML2, streamEnc, prologEnc);
        } else {
            is = getXmlStream(bomEnc, XML3, streamEnc, prologEnc);
        }
        final XmlReader xmlReader = new XmlReader(is, cT, true);
        assertEquals(xmlReader.getEncoding(), shouldbe);
        xmlReader.close();
    }
View Full Code Here

    private static final String ENCODING_ATTRIBUTE_XML = "<?xml version=\"1.0\" ?> \n" + "<atom:feed xmlns:atom=\"http://www.w3.org/2005/Atom\">\n" + "\n"
            + "  <atom:entry>\n" + "    <atom:title encoding=\"base64\"><![CDATA\n" + "aW5nTGluZSIgLz4";

    public void testEncodingAttributeXML() throws Exception {
        final InputStream is = new ByteArrayInputStream(ENCODING_ATTRIBUTE_XML.getBytes());
        final XmlReader xmlReader = new XmlReader(is, "", true);
        assertEquals(xmlReader.getEncoding(), "UTF-8");
        xmlReader.close();
    }
View Full Code Here

TOP

Related Classes of com.rometools.rome.io.XmlReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.