本文整理了Java中org.apache.commons.io.input.XmlStreamReader.getEncoding()
方法的一些代码示例,展示了XmlStreamReader.getEncoding()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlStreamReader.getEncoding()
方法的具体详情如下:
包路径:org.apache.commons.io.input.XmlStreamReader
类名称:XmlStreamReader
方法名:getEncoding
[英]Returns the charset encoding of the XmlStreamReader.
[中]返回XmlStreamReader的字符集编码。
代码示例来源:origin: commons-io/commons-io
protected void _testRawBomValid(final String encoding) throws Exception {
final InputStream is = getXmlStream(encoding + "-bom", XML3, encoding,
encoding);
final XmlStreamReader xmlReader = new XmlStreamReader(is, false);
if (!encoding.equals("UTF-16") && !encoding.equals("UTF-32")) {
assertEquals(xmlReader.getEncoding(), encoding);
} else {
assertEquals(xmlReader.getEncoding()
.substring(0, encoding.length()), encoding);
}
xmlReader.close();
}
代码示例来源:origin: commons-io/commons-io
public void _testAlternateDefaultEncoding(final String cT, final String bomEnc,
final String streamEnc, final String prologEnc, final String alternateEnc)
throws Exception {
final InputStream is = getXmlStream(bomEnc, prologEnc == null ? XML1
: XML3, streamEnc, prologEnc);
final XmlStreamReader xmlReader = new XmlStreamReader(is, cT, false, alternateEnc);
if (!streamEnc.equals("UTF-16")) {
// we can not assert things here because UTF-8, US-ASCII and
// ISO-8859-1 look alike for the chars used for detection
// (niallp 2010-10-06 - I re-instated the check below - the tests(6) passed)
final String enc = alternateEnc != null ? alternateEnc : streamEnc;
assertEquals(xmlReader.getEncoding(), enc);
} else {
//String enc = (alternateEnc != null) ? alternateEnc : streamEnc;
assertEquals(xmlReader.getEncoding().substring(0,
streamEnc.length()), streamEnc);
}
xmlReader.close();
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testEncodingAttributeXML() throws Exception {
final InputStream is = new ByteArrayInputStream(ENCODING_ATTRIBUTE_XML
.getBytes("UTF-8"));
final XmlStreamReader xmlReader = new XmlStreamReader(is, "", true);
assertEquals(xmlReader.getEncoding(), "UTF-8");
xmlReader.close();
}
代码示例来源:origin: commons-io/commons-io
public void _testHttpValid(final String cT, final String bomEnc, final String streamEnc,
final String prologEnc) throws Exception {
final InputStream is = getXmlStream(bomEnc,
prologEnc == null ? XML1 : XML3, streamEnc, prologEnc);
final XmlStreamReader xmlReader = new XmlStreamReader(is, cT, false);
if (!streamEnc.equals("UTF-16")) {
// we can not assert things here because UTF-8, US-ASCII and
// ISO-8859-1 look alike for the chars used for detection
// (niallp 2010-10-06 - I re-instated the check below and removed the 2 tests that failed)
assertEquals(xmlReader.getEncoding(), streamEnc);
} else {
assertEquals(xmlReader.getEncoding().substring(0,
streamEnc.length()), streamEnc);
}
xmlReader.close();
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testRawContent() throws Exception {
final String encoding = "UTF-8";
final String xml = getXML("no-bom", XML3, encoding, encoding);
final ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes(encoding));
final XmlStreamReader xmlReader = new XmlStreamReader(is);
assertEquals("Check encoding", xmlReader.getEncoding(), encoding);
assertEquals("Check content", xml, IOUtils.toString(xmlReader));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testHttpContent() throws Exception {
final String encoding = "UTF-8";
final String xml = getXML("no-bom", XML3, encoding, encoding);
final ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes(encoding));
final XmlStreamReader xmlReader = new XmlStreamReader(is, encoding);
assertEquals("Check encoding", xmlReader.getEncoding(), encoding);
assertEquals("Check content", xml, IOUtils.toString(xmlReader));
}
代码示例来源:origin: commons-io/commons-io
protected void _testRawBomInvalid(final String bomEnc, final String streamEnc,
final String prologEnc) throws Exception {
final InputStream is = getXmlStream(bomEnc, XML3, streamEnc, prologEnc);
XmlStreamReader xmlReader = null;
try {
xmlReader = new XmlStreamReader(is, false);
final String foundEnc = xmlReader.getEncoding();
fail("Expected IOException for BOM " + bomEnc + ", streamEnc "
+ streamEnc + " and prologEnc " + prologEnc + ": found "
+ foundEnc);
} catch (final IOException ex) {
assertTrue(ex.getMessage().contains("Invalid encoding,"));
}
if (xmlReader != null) {
xmlReader.close();
}
}
代码示例来源:origin: commons-io/commons-io
protected void _testHttpLenient(final String cT, final String bomEnc, final String streamEnc,
final String prologEnc, final String shouldbe) throws Exception {
final InputStream is = getXmlStream(bomEnc,
prologEnc == null ? XML2 : XML3, streamEnc, prologEnc);
final XmlStreamReader xmlReader = new XmlStreamReader(is, cT, true);
assertEquals(xmlReader.getEncoding(), shouldbe);
xmlReader.close();
}
代码示例来源:origin: commons-io/commons-io
protected void _testRawNoBomValid(final String encoding) throws Exception {
InputStream is = getXmlStream("no-bom", XML1, encoding, encoding);
XmlStreamReader xmlReader = new XmlStreamReader(is, false);
assertEquals(xmlReader.getEncoding(), "UTF-8");
xmlReader.close();
is = getXmlStream("no-bom", XML2, encoding, encoding);
xmlReader = new XmlStreamReader(is);
assertEquals(xmlReader.getEncoding(), "UTF-8");
xmlReader.close();
is = getXmlStream("no-bom", XML3, encoding, encoding);
xmlReader = new XmlStreamReader(is);
assertEquals(xmlReader.getEncoding(), encoding);
xmlReader.close();
is = getXmlStream("no-bom", XML4, encoding, encoding);
xmlReader = new XmlStreamReader(is);
assertEquals(xmlReader.getEncoding(), encoding);
xmlReader.close();
is = getXmlStream("no-bom", XML5, encoding, encoding);
xmlReader = new XmlStreamReader(is);
assertEquals(xmlReader.getEncoding(), encoding);
xmlReader.close();
}
代码示例来源:origin: org.apache.maven.shared/maven-shared-utils
/**
* @return The current encoding.
*/
public String getEncoding()
{
return reader.getEncoding();
}
代码示例来源:origin: omegat-org/omegat
/**
* Detects charset of XML file.
*/
public static String detectCharset(File file) throws IOException {
try (XmlStreamReader rd = new XmlStreamReader(file)) {
return rd.getEncoding();
}
}
代码示例来源:origin: org.apache.maven.plugins/maven-war-plugin
/**
* Get the encoding from an XML-file.
*
* @param webXml the XML-file
* @return The encoding of the XML-file, or UTF-8 if it's not specified in the file
* @throws java.io.IOException if an error occurred while reading the file
*/
protected String getEncoding( File webXml )
throws IOException
{
XmlStreamReader xmlReader = new XmlStreamReader( webXml );
try
{
return xmlReader.getEncoding();
}
finally
{
IOUtil.close( xmlReader );
}
}
内容来源于网络,如有侵权,请联系作者删除!