1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Reworked compression-jzlib and compressionHandlers

- There is now no longer the need to use reflection for
compression-jzlib.
- compressionHandlers are a global configuration property and therefore
belong in SmackConfiguration.
This commit is contained in:
Florian Schmaus 2014-03-10 10:20:52 +01:00
parent 489816c61f
commit a3ab886896
5 changed files with 50 additions and 55 deletions

View file

@ -24,6 +24,7 @@ task compressionJar(type: Jar) {
dependsOn classes
from sourceSets.main.output
include('org/jivesoftware/smack/compression/**')
include('org/jivesoftware/smack/SmackConfiguration.class')
}
task dnsJar(type: Jar) {
appendix += '-dns'

View file

@ -28,6 +28,8 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.compression.Java7ZlibInputOutputStream;
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.initializer.SmackInitializer;
import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
@ -64,6 +66,15 @@ public final class SmackConfiguration {
private static Set<String> disabledSmackClasses = new HashSet<String>();
private final static List<XMPPInputOutputStream> compressionHandlers = new ArrayList<XMPPInputOutputStream>(2);
/**
* Loads the configuration from the smack-config.xml file.<p>
*
* 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.<p>
*
* 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<XMPPInputOutputStream> getCompresionHandlers() {
List<XMPPInputOutputStream> res = new ArrayList<XMPPInputOutputStream>(compressionHandlers.size());
for (XMPPInputOutputStream ios : compressionHandlers) {
if (ios.isSupported()) {
res.add(ios);
}
}
return res;
}
public static void processConfigFile(InputStream cfgFileStream, Collection<Exception> exceptions) throws Exception {
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

View file

@ -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<ConnectionCreationListener> connectionEstablishedListeners =
new CopyOnWriteArraySet<ConnectionCreationListener>();
protected final static List<XMPPInputOutputStream> compressionHandlers = new ArrayList<XMPPInputOutputStream>(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());
}
/**