Commit 954ebad9 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Optimization - create a XmlPullParserFactory when loading the class. This...

Optimization - create a XmlPullParserFactory when loading the class. This avoids possible hangs up while reading the resource file.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1385 b35dd754-fafc-0310-a699-88a17e54d16e
parent 670430cc
...@@ -58,6 +58,17 @@ class ServerDialback { ...@@ -58,6 +58,17 @@ class ServerDialback {
*/ */
private static final String secretKey = StringUtils.randomString(10); private static final String secretKey = StringUtils.randomString(10);
private static XmlPullParserFactory FACTORY = null;
static {
try {
FACTORY = XmlPullParserFactory.newInstance();
}
catch (XmlPullParserException e) {
Log.error("Error creating a parser factory", e);
}
}
private Connection connection; private Connection connection;
private String serverName; private String serverName;
private SessionManager sessionManager = SessionManager.getInstance(); private SessionManager sessionManager = SessionManager.getInstance();
...@@ -440,7 +451,6 @@ class ServerDialback { ...@@ -440,7 +451,6 @@ class ServerDialback {
private boolean verifyKey(String key, String streamID, String hostname, String host, int port) private boolean verifyKey(String key, String streamID, String hostname, String host, int port)
throws IOException, XmlPullParserException, RemoteConnectionFailedException { throws IOException, XmlPullParserException, RemoteConnectionFailedException {
// TODO Check if the hostname is in the blacklist // TODO Check if the hostname is in the blacklist
XmlPullParserFactory factory = null;
XPPPacketReader reader = null; XPPPacketReader reader = null;
Writer writer = null; Writer writer = null;
StreamError error; StreamError error;
...@@ -449,9 +459,8 @@ class ServerDialback { ...@@ -449,9 +459,8 @@ class ServerDialback {
Socket socket = SocketFactory.getDefault().createSocket(host, port); Socket socket = SocketFactory.getDefault().createSocket(host, port);
Log.debug("RS - Connection to AS: " + hostname + ":" + port + " successfull"); Log.debug("RS - Connection to AS: " + hostname + ":" + port + " successfull");
try { try {
factory = XmlPullParserFactory.newInstance();
reader = new XPPPacketReader(); reader = new XPPPacketReader();
reader.setXPPFactory(factory); reader.setXPPFactory(FACTORY);
reader.getXPPParser().setInput(new InputStreamReader(socket.getInputStream(), reader.getXPPParser().setInput(new InputStreamReader(socket.getInputStream(),
CHARSET)); CHARSET));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment