(2);
+
+ /**
+ * Loads the configuration from the smack-config.xml file.
+ *
+ * So far this means that:
+ * 1) a set of classes will be loaded in order to execute their static init block
+ * 2) retrieve and set the current Smack release
+ */
static {
String smackVersion;
try {
@@ -104,6 +115,9 @@ public final class SmackConfiguration {
catch (Exception e) {
throw new IllegalStateException(e);
}
+
+ // Add the Java7 compression handler first, since it's preferred
+ compressionHandlers.add(new Java7ZlibInputOutputStream());
}
/**
@@ -112,17 +126,6 @@ public final class SmackConfiguration {
*/
private static ParsingExceptionCallback defaultCallback = new ExceptionThrowingCallback();
- private SmackConfiguration() {
- }
-
- /**
- * Loads the configuration from the smack-config.xml file.
- *
- * So far this means that:
- * 1) a set of classes will be loaded in order to execute their static init block
- * 2) retrieve and set the current Smack release
- */
-
/**
* Returns the Smack version information, eg "1.3.0".
*
@@ -250,6 +253,20 @@ public final class SmackConfiguration {
return defaultCallback;
}
+ public static void addCompressionHandler(XMPPInputOutputStream xmppInputOutputStream) {
+ compressionHandlers.add(xmppInputOutputStream);
+ }
+
+ public static List getCompresionHandlers() {
+ List res = new ArrayList(compressionHandlers.size());
+ for (XMPPInputOutputStream ios : compressionHandlers) {
+ if (ios.isSupported()) {
+ res.add(ios);
+ }
+ }
+ return res;
+ }
+
public static void processConfigFile(InputStream cfgFileStream, Collection exceptions) throws Exception {
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
diff --git a/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
index 9d7cc99ea..a289e4019 100644
--- a/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
+++ b/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
@@ -19,10 +19,8 @@ package org.jivesoftware.smack;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Constructor;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -36,7 +34,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
-import org.jivesoftware.smack.compression.Java7ZlibInputOutputStream;
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.IQReplyFilter;
@@ -97,8 +94,6 @@ public abstract class XMPPConnection {
private final static Set connectionEstablishedListeners =
new CopyOnWriteArraySet();
- protected final static List compressionHandlers = new ArrayList(2);
-
/**
* Value that indicates whether debugging is enabled. When enabled, a debug
* window will apear for each new connection that will contain the following
@@ -125,12 +120,6 @@ public abstract class XMPPConnection {
}
// Ensure the SmackConfiguration class is loaded by calling a method in it.
SmackConfiguration.getVersion();
- // Add the Java7 compression handler first, since it's preferred
- compressionHandlers.add(new Java7ZlibInputOutputStream());
- // If we don't have access to the Java7 API use the JZlib compression handler
-
- // TODO gradle migration
- //compressionHandlers.add(new JzlibInputOutputStream());
}
/**
diff --git a/tcp/src/main/java/org/jivesoftware/smack/TCPConnection.java b/tcp/src/main/java/org/jivesoftware/smack/TCPConnection.java
index 65d28a6da..a76c4feb6 100644
--- a/tcp/src/main/java/org/jivesoftware/smack/TCPConnection.java
+++ b/tcp/src/main/java/org/jivesoftware/smack/TCPConnection.java
@@ -827,10 +827,7 @@ public class TCPConnection extends XMPPConnection {
*/
private XMPPInputOutputStream maybeGetCompressionHandler() {
if (compressionMethods != null) {
- for (XMPPInputOutputStream handler : compressionHandlers) {
- if (!handler.isSupported())
- continue;
-
+ for (XMPPInputOutputStream handler : SmackConfiguration.getCompresionHandlers()) {
String method = handler.getCompressionMethod();
if (compressionMethods.contains(method))
return handler;