[core] Align behavior of getParserFor(InputStream) and getParserFor(Reader)

Reported-by: Ingo Bauersachs <ingo@jitsi.org>
This commit is contained in:
Florian Schmaus 2021-11-30 10:49:55 +01:00
parent cad63bc107
commit 11cc2d8d77
3 changed files with 3 additions and 6 deletions

View File

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2003-2007 Jive Software, 2019 Florian Schmaus. * Copyright 2003-2007 Jive Software, 2019-2021 Florian Schmaus.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -76,9 +76,9 @@ public class PacketParserUtils {
return getParserFor(new StringReader(stanza)); return getParserFor(new StringReader(stanza));
} }
public static XmlPullParser getParserFor(InputStream inputStream) throws XmlPullParserException { public static XmlPullParser getParserFor(InputStream inputStream) throws XmlPullParserException, IOException {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
return SmackXmlParser.newXmlParser(inputStreamReader); return getParserFor(inputStreamReader);
} }
public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException { public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {

View File

@ -67,7 +67,6 @@ public class AMPExtensionTest {
AMPExtensionProvider ampProvider = new AMPExtensionProvider(); AMPExtensionProvider ampProvider = new AMPExtensionProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(INCORRECT_RECEIVING_STANZA_STREAM); XmlPullParser parser = PacketParserUtils.getParserFor(INCORRECT_RECEIVING_STANZA_STREAM);
assertEquals(XmlPullParser.Event.START_ELEMENT, parser.next());
assertEquals(AMPExtension.ELEMENT, parser.getName()); assertEquals(AMPExtension.ELEMENT, parser.getName());
ExtensionElement extension = ampProvider.parse(parser); ExtensionElement extension = ampProvider.parse(parser);
@ -85,7 +84,6 @@ public class AMPExtensionTest {
AMPExtensionProvider ampProvider = new AMPExtensionProvider(); AMPExtensionProvider ampProvider = new AMPExtensionProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(CORRECT_SENDING_STANZA_STREAM); XmlPullParser parser = PacketParserUtils.getParserFor(CORRECT_SENDING_STANZA_STREAM);
assertEquals(XmlPullParser.Event.START_ELEMENT, parser.next());
assertEquals(AMPExtension.ELEMENT, parser.getName()); assertEquals(AMPExtension.ELEMENT, parser.getName());
ExtensionElement extension = ampProvider.parse(parser); ExtensionElement extension = ampProvider.parse(parser);
assertTrue(extension instanceof AMPExtension); assertTrue(extension instanceof AMPExtension);

View File

@ -39,7 +39,6 @@ public class XHTMLExtensionProviderTest {
public void parsesWell() throws IOException, XmlPullParserException { public void parsesWell() throws IOException, XmlPullParserException {
InputStream inputStream = getClass().getResourceAsStream(XHTML_EXTENSION_SAMPLE_RESOURCE_NAME); InputStream inputStream = getClass().getResourceAsStream(XHTML_EXTENSION_SAMPLE_RESOURCE_NAME);
XmlPullParser parser = PacketParserUtils.getParserFor(inputStream); XmlPullParser parser = PacketParserUtils.getParserFor(inputStream);
parser.next();
XHTMLExtensionProvider provider = new XHTMLExtensionProvider(); XHTMLExtensionProvider provider = new XHTMLExtensionProvider();
ExtensionElement extension = provider.parse(parser, parser.getDepth(), null); ExtensionElement extension = provider.parse(parser, parser.getDepth(), null);