Bump "Error Prone" to 2.0.15

and fix a few things :)
This commit is contained in:
Florian Schmaus 2017-02-11 16:16:41 +01:00
parent ef0af66b21
commit 4c646436a5
246 changed files with 1122 additions and 124 deletions

View File

@ -170,7 +170,7 @@ allprojects {
// version 52.0" error messages caused by the errorprone javac. // version 52.0" error messages caused by the errorprone javac.
// See https://github.com/tbroyer/gradle-errorprone-plugin/issues/18 for more information. // See https://github.com/tbroyer/gradle-errorprone-plugin/issues/18 for more information.
configurations.errorprone { configurations.errorprone {
resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.5' resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.15'
} }
} }

View File

@ -55,6 +55,7 @@ public final class BOSHConfiguration extends ConnectionConfiguration {
return proxy != null; return proxy != null;
} }
@Override
public ProxyInfo getProxyInfo() { public ProxyInfo getProxyInfo() {
return proxy; return proxy;
} }

View File

@ -203,11 +203,13 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
saslFeatureReceived.reportSuccess(); saslFeatureReceived.reportSuccess();
} }
@Override
public boolean isSecureConnection() { public boolean isSecureConnection() {
// TODO: Implement SSL usage // TODO: Implement SSL usage
return false; return false;
} }
@Override
public boolean isUsingCompression() { public boolean isUsingCompression() {
// TODO: Implement compression // TODO: Implement compression
return false; return false;
@ -313,16 +315,25 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
/** /**
* Initialize the SmackDebugger which allows to log and debug XML traffic. * Initialize the SmackDebugger which allows to log and debug XML traffic.
*/ */
@Override
protected void initDebugger() { protected void initDebugger() {
// TODO: Maybe we want to extend the SmackDebugger for simplification // TODO: Maybe we want to extend the SmackDebugger for simplification
// and a performance boost. // and a performance boost.
// Initialize a empty writer which discards all data. // Initialize a empty writer which discards all data.
writer = new Writer() { writer = new Writer() {
public void write(char[] cbuf, int off, int len) { /* ignore */} @Override
public void close() { /* ignore */ } public void write(char[] cbuf, int off, int len) {
public void flush() { /* ignore */ } /* ignore */}
};
@Override
public void close() {
/* ignore */ }
@Override
public void flush() {
/* ignore */ }
};
// Initialize a pipe for received raw data. // Initialize a pipe for received raw data.
try { try {
@ -338,6 +349,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
// Add listeners for the received and sent raw data. // Add listeners for the received and sent raw data.
client.addBOSHClientResponseListener(new BOSHClientResponseListener() { client.addBOSHClientResponseListener(new BOSHClientResponseListener() {
@Override
public void responseReceived(BOSHMessageEvent event) { public void responseReceived(BOSHMessageEvent event) {
if (event.getBody() != null) { if (event.getBody() != null) {
try { try {
@ -350,6 +362,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
} }
}); });
client.addBOSHClientRequestListener(new BOSHClientRequestListener() { client.addBOSHClientRequestListener(new BOSHClientRequestListener() {
@Override
public void requestSent(BOSHMessageEvent event) { public void requestSent(BOSHMessageEvent event) {
if (event.getBody() != null) { if (event.getBody() != null) {
try { try {
@ -366,6 +379,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
private Thread thread = this; private Thread thread = this;
private int bufferLength = 1024; private int bufferLength = 1024;
@Override
public void run() { public void run() {
try { try {
char[] cbuf = new char[bufferLength]; char[] cbuf = new char[bufferLength];
@ -406,6 +420,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
* Process the connection listeners and try to login if the * Process the connection listeners and try to login if the
* connection was formerly authenticated and is now reconnected. * connection was formerly authenticated and is now reconnected.
*/ */
@Override
public void connectionEvent(BOSHClientConnEvent connEvent) { public void connectionEvent(BOSHClientConnEvent connEvent) {
try { try {
if (connEvent.isConnected()) { if (connEvent.isConnected()) {
@ -463,6 +478,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
* *
* @param event the BOSH client response which includes the received packet. * @param event the BOSH client response which includes the received packet.
*/ */
@Override
public void responseReceived(BOSHMessageEvent event) { public void responseReceived(BOSHMessageEvent event) {
AbstractBody body = event.getBody(); AbstractBody body = event.getBody();
if (body != null) { if (body != null) {

View File

@ -1616,6 +1616,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
private long lastStanzaReceived; private long lastStanzaReceived;
@Override
public long getLastStanzaReceived() { public long getLastStanzaReceived() {
return lastStanzaReceived; return lastStanzaReceived;
} }

View File

@ -70,6 +70,7 @@ public final class ReconnectionManager {
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
if (connection instanceof AbstractXMPPConnection) { if (connection instanceof AbstractXMPPConnection) {
ReconnectionManager.getInstanceFor((AbstractXMPPConnection) connection); ReconnectionManager.getInstanceFor((AbstractXMPPConnection) connection);
@ -204,6 +205,7 @@ public final class ReconnectionManager {
/** /**
* The process will try the reconnection until the connection succeed or the user cancel it * The process will try the reconnection until the connection succeed or the user cancel it
*/ */
@Override
public void run() { public void run() {
final AbstractXMPPConnection connection = weakRefConnection.get(); final AbstractXMPPConnection connection = weakRefConnection.get();
if (connection == null) { if (connection == null) {

View File

@ -37,6 +37,7 @@ import org.jivesoftware.smack.sasl.core.SASLXOauth2Mechanism;
import org.jivesoftware.smack.sasl.core.SCRAMSHA1Mechanism; import org.jivesoftware.smack.sasl.core.SCRAMSHA1Mechanism;
import org.jivesoftware.smack.sasl.core.ScramSha1PlusMechanism; import org.jivesoftware.smack.sasl.core.ScramSha1PlusMechanism;
import org.jivesoftware.smack.util.FileUtils; import org.jivesoftware.smack.util.FileUtils;
import org.jivesoftware.smack.util.StringUtils;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlPullParserFactory;
@ -60,7 +61,7 @@ public final class SmackInitialization {
static { static {
String smackVersion; String smackVersion;
try { try {
BufferedReader reader = new BufferedReader(new InputStreamReader(FileUtils.getStreamForUrl("classpath:org.jivesoftware.smack/version", null))); BufferedReader reader = new BufferedReader(new InputStreamReader(FileUtils.getStreamForUrl("classpath:org.jivesoftware.smack/version", null), StringUtils.UTF8));
smackVersion = reader.readLine(); smackVersion = reader.readLine();
try { try {
reader.close(); reader.close();
@ -232,7 +233,7 @@ public final class SmackInitialization {
} }
} }
if (SmackInitializer.class.isAssignableFrom(initClass)) { if (SmackInitializer.class.isAssignableFrom(initClass)) {
SmackInitializer initializer = (SmackInitializer) initClass.newInstance(); SmackInitializer initializer = (SmackInitializer) initClass.getConstructor().newInstance();
List<Exception> exceptions = initializer.initialize(); List<Exception> exceptions = initializer.initialize();
if (exceptions == null || exceptions.size() == 0) { if (exceptions == null || exceptions.size() == 0) {
LOGGER.log(Level.FINE, "Loaded SmackInitializer " + className); LOGGER.log(Level.FINE, "Loaded SmackInitializer " + className);

View File

@ -49,6 +49,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
// Create a special Reader that wraps the main Reader and logs data to the GUI. // Create a special Reader that wraps the main Reader and logs data to the GUI.
this.reader = new ObservableReader(reader); this.reader = new ObservableReader(reader);
readerListener = new ReaderListener() { readerListener = new ReaderListener() {
@Override
public void read(String str) { public void read(String str) {
log("RECV (" + connection.getConnectionCounter() + "): " + str); log("RECV (" + connection.getConnectionCounter() + "): " + str);
} }
@ -58,6 +59,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
// Create a special Writer that wraps the main Writer and logs data to the GUI. // Create a special Writer that wraps the main Writer and logs data to the GUI.
this.writer = new ObservableWriter(writer); this.writer = new ObservableWriter(writer);
writerListener = new WriterListener() { writerListener = new WriterListener() {
@Override
public void write(String str) { public void write(String str) {
log("SENT (" + connection.getConnectionCounter() + "): " + str); log("SENT (" + connection.getConnectionCounter() + "): " + str);
} }
@ -68,6 +70,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
// the GUI. This is what we call "interpreted" packet data, since it's the packet // the GUI. This is what we call "interpreted" packet data, since it's the packet
// data as Smack sees it and not as it's coming in as raw XML. // data as Smack sees it and not as it's coming in as raw XML.
listener = new StanzaListener() { listener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
if (printInterpreted) { if (printInterpreted) {
log("RCV PKT (" + connection.getConnectionCounter() + "): " + packet.toXML()); log("RCV PKT (" + connection.getConnectionCounter() + "): " + packet.toXML());
@ -76,10 +79,12 @@ public abstract class AbstractDebugger implements SmackDebugger {
}; };
connListener = new ConnectionListener() { connListener = new ConnectionListener() {
@Override
public void connected(XMPPConnection connection) { public void connected(XMPPConnection connection) {
log("XMPPConnection connected (" log("XMPPConnection connected ("
+ connection + ")"); + connection + ")");
} }
@Override
public void authenticated(XMPPConnection connection, boolean resumed) { public void authenticated(XMPPConnection connection, boolean resumed) {
String logString = "XMPPConnection authenticated (" + connection + ")"; String logString = "XMPPConnection authenticated (" + connection + ")";
if (resumed) { if (resumed) {
@ -87,6 +92,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
} }
log(logString); log(logString);
} }
@Override
public void connectionClosed() { public void connectionClosed() {
log( log(
"XMPPConnection closed (" + "XMPPConnection closed (" +
@ -94,24 +100,28 @@ public abstract class AbstractDebugger implements SmackDebugger {
")"); ")");
} }
@Override
public void connectionClosedOnError(Exception e) { public void connectionClosedOnError(Exception e) {
log( log(
"XMPPConnection closed due to an exception (" + "XMPPConnection closed due to an exception (" +
connection + connection +
")", e); ")", e);
} }
@Override
public void reconnectionFailed(Exception e) { public void reconnectionFailed(Exception e) {
log( log(
"Reconnection failed due to an exception (" + "Reconnection failed due to an exception (" +
connection + connection +
")", e); ")", e);
} }
@Override
public void reconnectionSuccessful() { public void reconnectionSuccessful() {
log( log(
"XMPPConnection reconnected (" + "XMPPConnection reconnected (" +
connection + connection +
")"); ")");
} }
@Override
public void reconnectingIn(int seconds) { public void reconnectingIn(int seconds) {
log( log(
"XMPPConnection (" + "XMPPConnection (" +
@ -125,6 +135,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
protected abstract void log(String logMessage, Throwable throwable); protected abstract void log(String logMessage, Throwable throwable);
@Override
public Reader newConnectionReader(Reader newReader) { public Reader newConnectionReader(Reader newReader) {
reader.removeReaderListener(readerListener); reader.removeReaderListener(readerListener);
ObservableReader debugReader = new ObservableReader(newReader); ObservableReader debugReader = new ObservableReader(newReader);
@ -133,6 +144,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
return reader; return reader;
} }
@Override
public Writer newConnectionWriter(Writer newWriter) { public Writer newConnectionWriter(Writer newWriter) {
writer.removeWriterListener(writerListener); writer.removeWriterListener(writerListener);
ObservableWriter debugWriter = new ObservableWriter(newWriter); ObservableWriter debugWriter = new ObservableWriter(newWriter);
@ -159,18 +171,22 @@ public abstract class AbstractDebugger implements SmackDebugger {
connection.addConnectionListener(connListener); connection.addConnectionListener(connListener);
} }
@Override
public Reader getReader() { public Reader getReader() {
return reader; return reader;
} }
@Override
public Writer getWriter() { public Writer getWriter() {
return writer; return writer;
} }
@Override
public StanzaListener getReaderListener() { public StanzaListener getReaderListener() {
return listener; return listener;
} }
@Override
public StanzaListener getWriterListener() { public StanzaListener getWriterListener() {
return null; return null;
} }

View File

@ -47,6 +47,7 @@ public abstract class AbstractFromToMatchesFilter implements StanzaFilter {
this.ignoreResourcepart = ignoreResourcepart; this.ignoreResourcepart = ignoreResourcepart;
} }
@Override
public final boolean accept(final Stanza stanza) { public final boolean accept(final Stanza stanza) {
Jid stanzaAddress = getAddressToCompare(stanza); Jid stanzaAddress = getAddressToCompare(stanza);
@ -63,6 +64,7 @@ public abstract class AbstractFromToMatchesFilter implements StanzaFilter {
protected abstract Jid getAddressToCompare(Stanza stanza); protected abstract Jid getAddressToCompare(Stanza stanza);
@Override
public final String toString() { public final String toString() {
String matchMode = ignoreResourcepart ? "ignoreResourcepart" : "full"; String matchMode = ignoreResourcepart ? "ignoreResourcepart" : "full";
return getClass().getSimpleName() + " (" + matchMode + "): " + address; return getClass().getSimpleName() + " (" + matchMode + "): " + address;

View File

@ -44,6 +44,7 @@ public class AndFilter extends AbstractListFilter implements StanzaFilter {
super(filters); super(filters);
} }
@Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
for (StanzaFilter filter : filters) { for (StanzaFilter filter : filters) {
if (!filter.accept(packet)) { if (!filter.accept(packet)) {

View File

@ -39,6 +39,7 @@ public class NotFilter implements StanzaFilter {
this.filter = Objects.requireNonNull(filter, "Parameter must not be null."); this.filter = Objects.requireNonNull(filter, "Parameter must not be null.");
} }
@Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
return !filter.accept(packet); return !filter.accept(packet);
} }

View File

@ -67,6 +67,7 @@ public class PacketExtensionFilter implements StanzaFilter {
this(packetExtension.getElementName(), packetExtension.getNamespace()); this(packetExtension.getElementName(), packetExtension.getNamespace());
} }
@Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
return packet.hasExtension(elementName, namespace); return packet.hasExtension(elementName, namespace);
} }

View File

@ -54,10 +54,12 @@ public class PacketIDFilter implements StanzaFilter {
this.packetID = packetID; this.packetID = packetID;
} }
@Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
return packetID.equals(packet.getStanzaId()); return packetID.equals(packet.getStanzaId());
} }
@Override
public String toString() { public String toString() {
return getClass().getSimpleName() + ": id=" + packetID; return getClass().getSimpleName() + ": id=" + packetID;
} }

View File

@ -51,6 +51,7 @@ public class PacketTypeFilter implements StanzaFilter {
this.packetType = packetType; this.packetType = packetType;
} }
@Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
return packetType.isInstance(packet); return packetType.isInstance(packet);
} }

View File

@ -65,6 +65,7 @@ public class StanzaExtensionFilter implements StanzaFilter {
this(packetExtension.getElementName(), packetExtension.getNamespace()); this(packetExtension.getElementName(), packetExtension.getNamespace());
} }
@Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
return packet.hasExtension(elementName, namespace); return packet.hasExtension(elementName, namespace);
} }

View File

@ -47,10 +47,12 @@ public class StanzaIdFilter implements StanzaFilter {
this.stanzaId = StringUtils.requireNotNullOrEmpty(stanzaID, "Stanza ID must not be null or empty."); this.stanzaId = StringUtils.requireNotNullOrEmpty(stanzaID, "Stanza ID must not be null or empty.");
} }
@Override
public boolean accept(Stanza stanza) { public boolean accept(Stanza stanza) {
return stanzaId.equals(stanza.getStanzaId()); return stanzaId.equals(stanza.getStanzaId());
} }
@Override
public String toString() { public String toString() {
return getClass().getSimpleName() + ": id=" + stanzaId; return getClass().getSimpleName() + ": id=" + stanzaId;
} }

View File

@ -51,6 +51,7 @@ public final class StanzaTypeFilter implements StanzaFilter {
this.packetType = packetType; this.packetType = packetType;
} }
@Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
return packetType.isInstance(packet); return packetType.isInstance(packet);
} }

View File

@ -70,6 +70,7 @@ public class DefaultExtensionElement implements ExtensionElement {
* *
* @return the XML element name of the stanza(/packet) extension. * @return the XML element name of the stanza(/packet) extension.
*/ */
@Override
public String getElementName() { public String getElementName() {
return elementName; return elementName;
} }
@ -79,6 +80,7 @@ public class DefaultExtensionElement implements ExtensionElement {
* *
* @return the XML namespace of the stanza(/packet) extension. * @return the XML namespace of the stanza(/packet) extension.
*/ */
@Override
public String getNamespace() { public String getNamespace() {
return namespace; return namespace;
} }

View File

@ -570,6 +570,7 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
} }
@Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
@ -578,6 +579,7 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
return result; return result;
} }
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
@ -632,6 +634,7 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
return message; return message;
} }
@Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
@ -640,6 +643,7 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
return result; return result;
} }
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;

View File

@ -78,7 +78,7 @@ public class IntrospectionProvider{
IOException, IllegalArgumentException, InvocationTargetException, IOException, IllegalArgumentException, InvocationTargetException,
ClassNotFoundException { ClassNotFoundException {
ParserUtils.assertAtStartTag(parser); ParserUtils.assertAtStartTag(parser);
Object object = objectClass.newInstance(); Object object = objectClass.getConstructor().newInstance();
outerloop: while (true) { outerloop: while (true) {
int eventType = parser.next(); int eventType = parser.next();
switch (eventType) { switch (eventType) {

View File

@ -83,7 +83,8 @@ public class ProviderFileLoader implements ProviderLoader {
// reflection later to create instances of the class. // reflection later to create instances of the class.
// Add the provider to the map. // Add the provider to the map.
if (IQProvider.class.isAssignableFrom(provider)) { if (IQProvider.class.isAssignableFrom(provider)) {
iqProviders.add(new IQProviderInfo(elementName, namespace, (IQProvider<IQ>) provider.newInstance())); IQProvider<IQ> iqProvider = (IQProvider<IQ>) provider.getConstructor().newInstance();
iqProviders.add(new IQProviderInfo(elementName, namespace, iqProvider));
} }
else { else {
exceptions.add(new IllegalArgumentException(className + " is not a IQProvider")); exceptions.add(new IllegalArgumentException(className + " is not a IQProvider"));
@ -96,7 +97,9 @@ public class ProviderFileLoader implements ProviderLoader {
// then we'll use reflection later to create instances // then we'll use reflection later to create instances
// of the class. // of the class.
if (ExtensionElementProvider.class.isAssignableFrom(provider)) { if (ExtensionElementProvider.class.isAssignableFrom(provider)) {
extProviders.add(new ExtensionProviderInfo(elementName, namespace, (ExtensionElementProvider<ExtensionElement>) provider.newInstance())); ExtensionElementProvider<ExtensionElement> extensionElementProvider = (ExtensionElementProvider<ExtensionElement>) provider.getConstructor().newInstance();
extProviders.add(new ExtensionProviderInfo(elementName, namespace,
extensionElementProvider));
} }
else { else {
exceptions.add(new IllegalArgumentException(className exceptions.add(new IllegalArgumentException(className
@ -104,9 +107,10 @@ public class ProviderFileLoader implements ProviderLoader {
} }
break; break;
case "streamFeatureProvider": case "streamFeatureProvider":
ExtensionElementProvider<ExtensionElement> streamFeatureProvider = (ExtensionElementProvider<ExtensionElement>) provider.getConstructor().newInstance();
sfProviders.add(new StreamFeatureProviderInfo(elementName, sfProviders.add(new StreamFeatureProviderInfo(elementName,
namespace, namespace,
(ExtensionElementProvider<ExtensionElement>) provider.newInstance())); streamFeatureProvider));
break; break;
default: default:
LOGGER.warning("Unknown provider type: " + typeName); LOGGER.warning("Unknown provider type: " + typeName);

View File

@ -23,6 +23,8 @@ import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import org.jivesoftware.smack.util.StringUtils;
/** /**
* Socket factory for socks4 proxy. * Socket factory for socks4 proxy.
* *
@ -89,7 +91,8 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
if(user!=null) if(user!=null)
{ {
System.arraycopy(user.getBytes(), 0, buf, index, user.length()); byte[] userBytes = user.getBytes(StringUtils.UTF8);
System.arraycopy(userBytes, 0, buf, index, user.length());
index+=user.length(); index+=user.length();
} }
buf[index++]=0; buf[index++]=0;

View File

@ -22,6 +22,8 @@ import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import org.jivesoftware.smack.util.StringUtils;
/** /**
* Socket factory for Socks5 proxy. * Socket factory for Socks5 proxy.
* *
@ -132,11 +134,13 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
index=0; index=0;
buf[index++]=1; buf[index++]=1;
buf[index++]=(byte)(user.length()); buf[index++]=(byte)(user.length());
System.arraycopy(user.getBytes(), 0, buf, index, byte[] userBytes = user.getBytes(StringUtils.UTF8);
System.arraycopy(userBytes, 0, buf, index,
user.length()); user.length());
index+=user.length(); index+=user.length();
buf[index++]=(byte)(passwd.length()); byte[] passwordBytes = user.getBytes(StringUtils.UTF8);
System.arraycopy(passwd.getBytes(), 0, buf, index, buf[index++]=(byte)(passwordBytes.length);
System.arraycopy(passwordBytes, 0, buf, index,
passwd.length()); passwd.length());
index+=passwd.length(); index+=passwd.length();
@ -210,7 +214,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
buf[index++]=1; // CONNECT buf[index++]=1; // CONNECT
buf[index++]=0; buf[index++]=0;
byte[] hostb= host.getBytes(); byte[] hostb= host.getBytes(StringUtils.UTF8);
int len=hostb.length; int len=hostb.length;
buf[index++]=3; // DOMAINNAME buf[index++]=3; // DOMAINNAME
buf[index++]=(byte)(len); buf[index++]=(byte)(len);

View File

@ -265,9 +265,10 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
return null; return null;
} }
@Override
public final int compareTo(SASLMechanism other) { public final int compareTo(SASLMechanism other) {
// Switch to Integer.compare(int, int) once Smack is on Android 19 or higher. // Switch to Integer.compare(int, int) once Smack is on Android 19 or higher.
Integer ourPriority = new Integer(getPriority()); Integer ourPriority = getPriority();
return ourPriority.compareTo(other.getPriority()); return ourPriority.compareTo(other.getPriority());
} }
@ -300,7 +301,7 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
} }
/** /**
* SASLprep the given String. * SASLprep the given String. The resulting String is in UTF-8.
* *
* @param string the String to sasl prep. * @param string the String to sasl prep.
* @return the given String SASL preped * @return the given String SASL preped

View File

@ -30,6 +30,7 @@ public class SASLAnonymous extends SASLMechanism {
public static final String NAME = "ANONYMOUS"; public static final String NAME = "ANONYMOUS";
@Override
public String getName() { public String getName() {
return NAME; return NAME;
} }

View File

@ -16,6 +16,7 @@
*/ */
package org.jivesoftware.smack.sasl.core; package org.jivesoftware.smack.sasl.core;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Collections; import java.util.Collections;
@ -105,7 +106,15 @@ public abstract class ScramMechanism extends SASLMechanism {
@Override @Override
protected byte[] evaluateChallenge(byte[] challenge) throws SmackException { protected byte[] evaluateChallenge(byte[] challenge) throws SmackException {
final String challengeString = new String(challenge); String challengeString;
try {
// TODO: Where is it specified that this is an UTF-8 encoded string?
challengeString = new String(challenge, StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
switch (state) { switch (state) {
case AUTH_TEXT_SENT: case AUTH_TEXT_SENT:
final String serverFirstMessage = challengeString; final String serverFirstMessage = challengeString;
@ -358,14 +367,21 @@ public abstract class ScramMechanism extends SASLMechanism {
* (PRF) and with dkLen == output length of HMAC() == output length of H(). * (PRF) and with dkLen == output length of HMAC() == output length of H().
* </p> * </p>
* *
* @param str * @param normalizedPassword the normalized password.
* @param salt * @param salt
* @param iterations * @param iterations
* @return the result of the Hi function. * @return the result of the Hi function.
* @throws SmackException * @throws SmackException
*/ */
private byte[] hi(String str, byte[] salt, int iterations) throws SmackException { private byte[] hi(String normalizedPassword, byte[] salt, int iterations) throws SmackException {
byte[] key = str.getBytes(); byte[] key;
try {
// According to RFC 5802 § 2.2, the resulting string of the normalization is also in UTF-8.
key = normalizedPassword.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError();
}
// U1 := HMAC(str, salt + INT(1)) // U1 := HMAC(str, salt + INT(1))
byte[] u = hmac(key, ByteUtils.concact(salt, ONE)); byte[] u = hmac(key, ByteUtils.concact(salt, ONE));
byte[] res = u.clone(); byte[] res = u.clone();

View File

@ -240,6 +240,7 @@ public class ArrayBlockingQueueWithShutdown<E> extends AbstractQueue<E> implemen
* @param e the element to add. * @param e the element to add.
* @throws InterruptedException if interrupted while waiting or if the queue was shut down. * @throws InterruptedException if interrupted while waiting or if the queue was shut down.
*/ */
@Override
public void put(E e) throws InterruptedException { public void put(E e) throws InterruptedException {
checkNotNull(e); checkNotNull(e);
lock.lockInterruptibly(); lock.lockInterruptibly();
@ -452,6 +453,7 @@ public class ArrayBlockingQueueWithShutdown<E> extends AbstractQueue<E> implemen
} }
} }
@Override
public boolean hasNext() { public boolean hasNext() {
return nextIndex >= 0; return nextIndex >= 0;
} }
@ -469,6 +471,7 @@ public class ArrayBlockingQueueWithShutdown<E> extends AbstractQueue<E> implemen
} }
} }
@Override
public E next() { public E next() {
lock.lock(); lock.lock();
try { try {
@ -486,6 +489,7 @@ public class ArrayBlockingQueueWithShutdown<E> extends AbstractQueue<E> implemen
} }
} }
@Override
public void remove() { public void remove() {
lock.lock(); lock.lock();
try { try {

View File

@ -87,7 +87,8 @@ public final class FileUtils {
public static boolean addLines(String url, Set<String> set) throws MalformedURLException, IOException { public static boolean addLines(String url, Set<String> set) throws MalformedURLException, IOException {
InputStream is = getStreamForUrl(url, null); InputStream is = getStreamForUrl(url, null);
if (is == null) return false; if (is == null) return false;
BufferedReader br = new BufferedReader(new InputStreamReader(is)); InputStreamReader sr = new InputStreamReader(is, StringUtils.UTF8);
BufferedReader br = new BufferedReader(sr);
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
set.add(line); set.add(line);
@ -102,6 +103,7 @@ public final class FileUtils {
* @return the content of file or null in case of an error * @return the content of file or null in case of an error
* @throws IOException * @throws IOException
*/ */
@SuppressWarnings("DefaultCharset")
public static String readFileOrThrow(File file) throws FileNotFoundException, IOException { public static String readFileOrThrow(File file) throws FileNotFoundException, IOException {
Reader reader = null; Reader reader = null;
try { try {
@ -132,6 +134,7 @@ public final class FileUtils {
return null; return null;
} }
@SuppressWarnings("DefaultCharset")
public static void writeFileOrThrow(File file, CharSequence content) throws IOException { public static void writeFileOrThrow(File file, CharSequence content) throws IOException {
FileWriter writer = new FileWriter(file, false); FileWriter writer = new FileWriter(file, false);
try { try {

View File

@ -37,6 +37,7 @@ public class ObservableReader extends Reader {
this.wrappedReader = wrappedReader; this.wrappedReader = wrappedReader;
} }
@Override
public int read(char[] cbuf, int off, int len) throws IOException { public int read(char[] cbuf, int off, int len) throws IOException {
int count = wrappedReader.read(cbuf, off, len); int count = wrappedReader.read(cbuf, off, len);
if (count > 0) { if (count > 0) {
@ -54,34 +55,42 @@ public class ObservableReader extends Reader {
return count; return count;
} }
@Override
public void close() throws IOException { public void close() throws IOException {
wrappedReader.close(); wrappedReader.close();
} }
@Override
public int read() throws IOException { public int read() throws IOException {
return wrappedReader.read(); return wrappedReader.read();
} }
@Override
public int read(char[] cbuf) throws IOException { public int read(char[] cbuf) throws IOException {
return wrappedReader.read(cbuf); return wrappedReader.read(cbuf);
} }
@Override
public long skip(long n) throws IOException { public long skip(long n) throws IOException {
return wrappedReader.skip(n); return wrappedReader.skip(n);
} }
@Override
public boolean ready() throws IOException { public boolean ready() throws IOException {
return wrappedReader.ready(); return wrappedReader.ready();
} }
@Override
public boolean markSupported() { public boolean markSupported() {
return wrappedReader.markSupported(); return wrappedReader.markSupported();
} }
@Override
public void mark(int readAheadLimit) throws IOException { public void mark(int readAheadLimit) throws IOException {
wrappedReader.mark(readAheadLimit); wrappedReader.mark(readAheadLimit);
} }
@Override
public void reset() throws IOException { public void reset() throws IOException {
wrappedReader.reset(); wrappedReader.reset();
} }

View File

@ -38,36 +38,43 @@ public class ObservableWriter extends Writer {
this.wrappedWriter = wrappedWriter; this.wrappedWriter = wrappedWriter;
} }
@Override
public void write(char[] cbuf, int off, int len) throws IOException { public void write(char[] cbuf, int off, int len) throws IOException {
wrappedWriter.write(cbuf, off, len); wrappedWriter.write(cbuf, off, len);
String str = new String(cbuf, off, len); String str = new String(cbuf, off, len);
maybeNotifyListeners(str); maybeNotifyListeners(str);
} }
@Override
public void flush() throws IOException { public void flush() throws IOException {
notifyListeners(); notifyListeners();
wrappedWriter.flush(); wrappedWriter.flush();
} }
@Override
public void close() throws IOException { public void close() throws IOException {
wrappedWriter.close(); wrappedWriter.close();
} }
@Override
public void write(int c) throws IOException { public void write(int c) throws IOException {
wrappedWriter.write(c); wrappedWriter.write(c);
} }
@Override
public void write(char[] cbuf) throws IOException { public void write(char[] cbuf) throws IOException {
wrappedWriter.write(cbuf); wrappedWriter.write(cbuf);
String str = new String(cbuf); String str = new String(cbuf);
maybeNotifyListeners(str); maybeNotifyListeners(str);
} }
@Override
public void write(String str) throws IOException { public void write(String str) throws IOException {
wrappedWriter.write(str); wrappedWriter.write(str);
maybeNotifyListeners(str); maybeNotifyListeners(str);
} }
@Override
public void write(String str, int off, int len) throws IOException { public void write(String str, int off, int len) throws IOException {
wrappedWriter.write(str, off, len); wrappedWriter.write(str, off, len);
str = str.substring(off, off + len); str = str.substring(off, off + len);

View File

@ -20,6 +20,9 @@ package org.jivesoftware.smack.util.stringencoder;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.jivesoftware.smack.util.StringUtils;
/** /**
* Base32 string encoding is useful for when filenames case-insensitive filesystems are encoded. * Base32 string encoding is useful for when filenames case-insensitive filesystems are encoded.
@ -53,7 +56,13 @@ public class Base32 {
public static String decode(String str) { public static String decode(String str) {
ByteArrayOutputStream bs = new ByteArrayOutputStream(); ByteArrayOutputStream bs = new ByteArrayOutputStream();
byte[] raw = str.getBytes(); byte[] raw;
try {
raw = str.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
for (int i = 0; i < raw.length; i++) { for (int i = 0; i < raw.length; i++) {
char c = (char) raw[i]; char c = (char) raw[i];
if (!Character.isWhitespace(c)) { if (!Character.isWhitespace(c)) {
@ -106,11 +115,24 @@ public class Base32 {
} }
} }
return new String(bs.toByteArray()); String res;
try {
res = new String(bs.toByteArray(), StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
return res;
} }
public static String encode(String str) { public static String encode(String str) {
byte[] b = str.getBytes(); byte[] b;
try {
b = str.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
for (int i = 0; i < (b.length + 4) / 5; i++) { for (int i = 0; i < (b.length + 4) / 5; i++) {
@ -153,7 +175,14 @@ public class Base32 {
os.write(c); os.write(c);
} }
} }
return new String(os.toByteArray()); String res;
try {
res = new String(os.toByteArray(), StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
return res;
} }
private static int lenToPadding(int blocklen) { private static int lenToPadding(int blocklen) {

View File

@ -180,6 +180,7 @@ public class DummyConnection extends AbstractXMPPConnection {
* *
* @param packet the stanza(/packet) to process. * @param packet the stanza(/packet) to process.
*/ */
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
invokeStanzaCollectorsAndNotifyRecvListeners(packet); invokeStanzaCollectorsAndNotifyRecvListeners(packet);
} }

View File

@ -176,7 +176,7 @@ public class StanzaCollectorTest
assertNull(collector.pollResult()); assertNull(collector.pollResult());
} }
class OKEverything implements StanzaFilter static class OKEverything implements StanzaFilter
{ {
@Override @Override
public boolean accept(Stanza packet) public boolean accept(Stanza packet)
@ -186,7 +186,7 @@ public class StanzaCollectorTest
} }
class TestStanzaCollector extends StanzaCollector static class TestStanzaCollector extends StanzaCollector
{ {
protected TestStanzaCollector(XMPPConnection conection, StanzaFilter packetFilter, int size) protected TestStanzaCollector(XMPPConnection conection, StanzaFilter packetFilter, int size)
{ {
@ -194,7 +194,7 @@ public class StanzaCollectorTest
} }
} }
class TestPacket extends Stanza static class TestPacket extends Stanza
{ {
public TestPacket(int i) public TestPacket(int i)
{ {

View File

@ -19,6 +19,7 @@ package org.jivesoftware.smack.sasl;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -38,14 +39,14 @@ public class DigestMd5SaslTest extends AbstractSaslTest {
super(saslMechanism); super(saslMechanism);
} }
protected void runTest(boolean useAuthzid) throws NotConnectedException, SmackException, InterruptedException, XmppStringprepException { protected void runTest(boolean useAuthzid) throws NotConnectedException, SmackException, InterruptedException, XmppStringprepException, UnsupportedEncodingException {
EntityBareJid authzid = null; EntityBareJid authzid = null;
if (useAuthzid) { if (useAuthzid) {
authzid = JidCreate.entityBareFrom("shazbat@xmpp.org"); authzid = JidCreate.entityBareFrom("shazbat@xmpp.org");
} }
saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null); saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null);
byte[] response = saslMechanism.evaluateChallenge(challengeBytes); byte[] response = saslMechanism.evaluateChallenge(challengeBytes);
String responseString = new String(response); String responseString = new String(response, StringUtils.UTF8);
String[] responseParts = responseString.split(","); String[] responseParts = responseString.split(",");
Map<String, String> responsePairs = new HashMap<String, String>(); Map<String, String> responsePairs = new HashMap<String, String>();
for (String part : responseParts) { for (String part : responseParts) {

View File

@ -851,6 +851,7 @@ public class PacketParserUtilsTest {
XmlUnitUtils.assertSimilar(saslFailureString, saslFailure.toXML()); XmlUnitUtils.assertSimilar(saslFailureString, saslFailure.toXML());
} }
@SuppressWarnings("ReferenceEquality")
private static String determineNonDefaultLanguage() { private static String determineNonDefaultLanguage() {
String otherLanguage = "jp"; String otherLanguage = "jp";
Locale[] availableLocales = Locale.getAvailableLocales(); Locale[] availableLocales = Locale.getAvailableLocales();

View File

@ -21,6 +21,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
import org.junit.Test; import org.junit.Test;
/** /**
@ -72,16 +74,16 @@ public class StringUtilsTest {
} }
@Test @Test
public void testEncodeHex() { public void testEncodeHex() throws UnsupportedEncodingException {
String input = ""; String input = "";
String output = ""; String output = "";
assertEquals(new String(StringUtils.encodeHex(input.getBytes())), assertEquals(new String(StringUtils.encodeHex(input.getBytes(StringUtils.UTF8))),
new String(output.getBytes())); output);
input = "foo bar 123"; input = "foo bar 123";
output = "666f6f2062617220313233"; output = "666f6f2062617220313233";
assertEquals(new String(StringUtils.encodeHex(input.getBytes())), assertEquals(new String(StringUtils.encodeHex(input.getBytes(StringUtils.UTF8))),
new String(output.getBytes())); output);
} }
@Test @Test

View File

@ -40,22 +40,27 @@ class SLF4JLoggingConnectionListener implements ConnectionListener {
logger.debug("({}) Connection authenticated as {}", connection.hashCode(), connection.getUser()); logger.debug("({}) Connection authenticated as {}", connection.hashCode(), connection.getUser());
} }
@Override
public void connectionClosed() { public void connectionClosed() {
logger.debug("({}) Connection closed", connection.hashCode()); logger.debug("({}) Connection closed", connection.hashCode());
} }
@Override
public void connectionClosedOnError(Exception e) { public void connectionClosedOnError(Exception e) {
logger.debug("({}) Connection closed due to an exception: {}", connection.hashCode(), e); logger.debug("({}) Connection closed due to an exception: {}", connection.hashCode(), e);
} }
@Override
public void reconnectionFailed(Exception e) { public void reconnectionFailed(Exception e) {
logger.debug("({}) Reconnection failed due to an exception: {}", connection.hashCode(), e); logger.debug("({}) Reconnection failed due to an exception: {}", connection.hashCode(), e);
} }
@Override
public void reconnectionSuccessful() { public void reconnectionSuccessful() {
logger.debug("({}) Connection reconnected", connection.hashCode()); logger.debug("({}) Connection reconnected", connection.hashCode());
} }
@Override
public void reconnectingIn(int seconds) { public void reconnectingIn(int seconds) {
logger.debug("({}) Connection will reconnect in {}", connection.hashCode(), seconds); logger.debug("({}) Connection will reconnect in {}", connection.hashCode(), seconds);
} }

View File

@ -31,6 +31,7 @@ class SLF4JLoggingPacketListener implements StanzaListener {
this.prefix = Validate.notNull(prefix); this.prefix = Validate.notNull(prefix);
} }
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
if (SLF4JSmackDebugger.printInterpreted.get() && logger.isDebugEnabled()) { if (SLF4JSmackDebugger.printInterpreted.get() && logger.isDebugEnabled()) {
logger.debug("{}: PKT [{}] '{}'", prefix, packet.getClass().getName(), packet.toXML()); logger.debug("{}: PKT [{}] '{}'", prefix, packet.getClass().getName(), packet.toXML());

View File

@ -28,10 +28,12 @@ class SLF4JRawXmlListener implements ReaderListener, WriterListener {
this.logger = Validate.notNull(logger); this.logger = Validate.notNull(logger);
} }
@Override
public void read(String str) { public void read(String str) {
logger.debug("{}: {}", SLF4JSmackDebugger.RECEIVED_TAG, str); logger.debug("{}: {}", SLF4JSmackDebugger.RECEIVED_TAG, str);
} }
@Override
public void write(String str) { public void write(String str) {
logger.debug("{}: {}", SLF4JSmackDebugger.SENT_TAG, str); logger.debug("{}: {}", SLF4JSmackDebugger.SENT_TAG, str);
} }

View File

@ -208,8 +208,10 @@ public class EnhancedDebugger implements SmackDebugger {
packetReaderListener = new StanzaListener() { packetReaderListener = new StanzaListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss:SS"); SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss:SS");
@Override
public void processStanza(final Stanza packet) { public void processStanza(final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
addReadPacketToTable(dateFormatter, packet); addReadPacketToTable(dateFormatter, packet);
} }
@ -223,8 +225,10 @@ public class EnhancedDebugger implements SmackDebugger {
packetWriterListener = new StanzaListener() { packetWriterListener = new StanzaListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss:SS"); SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss:SS");
@Override
public void processStanza(final Stanza packet) { public void processStanza(final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
addSentPacketToTable(dateFormatter, packet); addSentPacketToTable(dateFormatter, packet);
} }
@ -235,8 +239,10 @@ public class EnhancedDebugger implements SmackDebugger {
// Create a thread that will listen for any connection closed event // Create a thread that will listen for any connection closed event
connListener = new AbstractConnectionListener() { connListener = new AbstractConnectionListener() {
@Override
public void connectionClosed() { public void connectionClosed() {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
statusField.setValue("Closed"); statusField.setValue("Closed");
EnhancedDebuggerWindow.connectionClosed(EnhancedDebugger.this); EnhancedDebuggerWindow.connectionClosed(EnhancedDebugger.this);
@ -245,8 +251,10 @@ public class EnhancedDebugger implements SmackDebugger {
} }
@Override
public void connectionClosedOnError(final Exception e) { public void connectionClosedOnError(final Exception e) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
statusField.setValue("Closed due to an exception"); statusField.setValue("Closed due to an exception");
EnhancedDebuggerWindow.connectionClosedOnError(EnhancedDebugger.this, e); EnhancedDebuggerWindow.connectionClosedOnError(EnhancedDebugger.this, e);
@ -254,16 +262,20 @@ public class EnhancedDebugger implements SmackDebugger {
}); });
} }
@Override
public void reconnectingIn(final int seconds){ public void reconnectingIn(final int seconds){
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
statusField.setValue("Attempt to reconnect in " + seconds + " seconds"); statusField.setValue("Attempt to reconnect in " + seconds + " seconds");
} }
}); });
} }
@Override
public void reconnectionSuccessful() { public void reconnectionSuccessful() {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
statusField.setValue("Reconnection stablished"); statusField.setValue("Reconnection stablished");
EnhancedDebuggerWindow.connectionEstablished(EnhancedDebugger.this); EnhancedDebuggerWindow.connectionEstablished(EnhancedDebugger.this);
@ -271,8 +283,10 @@ public class EnhancedDebugger implements SmackDebugger {
}); });
} }
@Override
public void reconnectionFailed(Exception e) { public void reconnectionFailed(Exception e) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
statusField.setValue("Reconnection failed"); statusField.setValue("Reconnection failed");
} }
@ -291,11 +305,13 @@ public class EnhancedDebugger implements SmackDebugger {
0) { 0) {
// CHECKSTYLE:OFF // CHECKSTYLE:OFF
private static final long serialVersionUID = 8136121224474217264L; private static final long serialVersionUID = 8136121224474217264L;
public boolean isCellEditable(int rowIndex, int mColIndex) { @Override
public boolean isCellEditable(int rowIndex, int mColIndex) {
// CHECKSTYLE:ON // CHECKSTYLE:ON
return false; return false;
} }
@Override
public Class<?> getColumnClass(int columnIndex) { public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 2 || columnIndex == 3) { if (columnIndex == 2 || columnIndex == 3) {
return Icon.class; return Icon.class;
@ -344,6 +360,7 @@ public class EnhancedDebugger implements SmackDebugger {
JPopupMenu menu = new JPopupMenu(); JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem1 = new JMenuItem("Copy"); JMenuItem menuItem1 = new JMenuItem("Copy");
menuItem1.addActionListener(new ActionListener() { menuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Get the clipboard // Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
@ -391,6 +408,7 @@ public class EnhancedDebugger implements SmackDebugger {
menu = new JPopupMenu(); menu = new JPopupMenu();
menuItem1 = new JMenuItem("Copy"); menuItem1 = new JMenuItem("Copy");
menuItem1.addActionListener(new ActionListener() { menuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Get the clipboard // Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
@ -401,6 +419,7 @@ public class EnhancedDebugger implements SmackDebugger {
JMenuItem menuItem2 = new JMenuItem("Clear"); JMenuItem menuItem2 = new JMenuItem("Clear");
menuItem2.addActionListener(new ActionListener() { menuItem2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
sentText.setText(""); sentText.setText("");
} }
@ -426,6 +445,7 @@ public class EnhancedDebugger implements SmackDebugger {
menu = new JPopupMenu(); menu = new JPopupMenu();
menuItem1 = new JMenuItem("Copy"); menuItem1 = new JMenuItem("Copy");
menuItem1.addActionListener(new ActionListener() { menuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Get the clipboard // Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
@ -436,6 +456,7 @@ public class EnhancedDebugger implements SmackDebugger {
menuItem2 = new JMenuItem("Clear"); menuItem2 = new JMenuItem("Clear");
menuItem2.addActionListener(new ActionListener() { menuItem2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
receivedText.setText(""); receivedText.setText("");
} }
@ -449,8 +470,10 @@ public class EnhancedDebugger implements SmackDebugger {
// Create a special Reader that wraps the main Reader and logs data to the GUI. // Create a special Reader that wraps the main Reader and logs data to the GUI.
ObservableReader debugReader = new ObservableReader(reader); ObservableReader debugReader = new ObservableReader(reader);
readerListener = new ReaderListener() { readerListener = new ReaderListener() {
@Override
public void read(final String str) { public void read(final String str) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER && if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER &&
!EnhancedDebuggerWindow.getInstance().isVisible()) { !EnhancedDebuggerWindow.getInstance().isVisible()) {
@ -487,8 +510,10 @@ public class EnhancedDebugger implements SmackDebugger {
// Create a special Writer that wraps the main Writer and logs data to the GUI. // Create a special Writer that wraps the main Writer and logs data to the GUI.
ObservableWriter debugWriter = new ObservableWriter(writer); ObservableWriter debugWriter = new ObservableWriter(writer);
writerListener = new WriterListener() { writerListener = new WriterListener() {
@Override
public void write(final String str) { public void write(final String str) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER && if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER &&
!EnhancedDebuggerWindow.getInstance().isVisible()) { !EnhancedDebuggerWindow.getInstance().isVisible()) {
@ -536,6 +561,7 @@ public class EnhancedDebugger implements SmackDebugger {
JPopupMenu menu = new JPopupMenu(); JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Message"); JMenuItem menuItem = new JMenuItem("Message");
menuItem.addActionListener(new ActionListener() { menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
adhocMessages.setText( adhocMessages.setText(
"<message to=\"\" id=\"" "<message to=\"\" id=\""
@ -547,6 +573,7 @@ public class EnhancedDebugger implements SmackDebugger {
menuItem = new JMenuItem("IQ Get"); menuItem = new JMenuItem("IQ Get");
menuItem.addActionListener(new ActionListener() { menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
adhocMessages.setText( adhocMessages.setText(
"<iq type=\"get\" to=\"\" id=\"" "<iq type=\"get\" to=\"\" id=\""
@ -558,6 +585,7 @@ public class EnhancedDebugger implements SmackDebugger {
menuItem = new JMenuItem("IQ Set"); menuItem = new JMenuItem("IQ Set");
menuItem.addActionListener(new ActionListener() { menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
adhocMessages.setText( adhocMessages.setText(
"<iq type=\"set\" to=\"\" id=\"" "<iq type=\"set\" to=\"\" id=\""
@ -569,6 +597,7 @@ public class EnhancedDebugger implements SmackDebugger {
menuItem = new JMenuItem("Presence"); menuItem = new JMenuItem("Presence");
menuItem.addActionListener(new ActionListener() { menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
adhocMessages.setText( adhocMessages.setText(
"<presence to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"/>"); "<presence to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"/>");
@ -579,6 +608,7 @@ public class EnhancedDebugger implements SmackDebugger {
menuItem = new JMenuItem("Send"); menuItem = new JMenuItem("Send");
menuItem.addActionListener(new ActionListener() { menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (!"".equals(adhocMessages.getText())) { if (!"".equals(adhocMessages.getText())) {
AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText()); AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText());
@ -595,6 +625,7 @@ public class EnhancedDebugger implements SmackDebugger {
menuItem = new JMenuItem("Clear"); menuItem = new JMenuItem("Clear");
menuItem.addActionListener(new ActionListener() { menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
adhocMessages.setText(null); adhocMessages.setText(null);
} }
@ -709,7 +740,8 @@ public class EnhancedDebugger implements SmackDebugger {
new Object[]{"Type", "Received", "Sent"}) { new Object[]{"Type", "Received", "Sent"}) {
// CHECKSTYLE:OFF // CHECKSTYLE:OFF
private static final long serialVersionUID = -6793886085109589269L; private static final long serialVersionUID = -6793886085109589269L;
public boolean isCellEditable(int rowIndex, int mColIndex) { @Override
public boolean isCellEditable(int rowIndex, int mColIndex) {
// CHECKSTYLE:ON // CHECKSTYLE:ON
return false; return false;
} }
@ -726,6 +758,7 @@ public class EnhancedDebugger implements SmackDebugger {
tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection"); tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection");
} }
@Override
public Reader newConnectionReader(Reader newReader) { public Reader newConnectionReader(Reader newReader) {
((ObservableReader) reader).removeReaderListener(readerListener); ((ObservableReader) reader).removeReaderListener(readerListener);
ObservableReader debugReader = new ObservableReader(newReader); ObservableReader debugReader = new ObservableReader(newReader);
@ -734,6 +767,7 @@ public class EnhancedDebugger implements SmackDebugger {
return reader; return reader;
} }
@Override
public Writer newConnectionWriter(Writer newWriter) { public Writer newConnectionWriter(Writer newWriter) {
((ObservableWriter) writer).removeWriterListener(writerListener); ((ObservableWriter) writer).removeWriterListener(writerListener);
ObservableWriter debugWriter = new ObservableWriter(newWriter); ObservableWriter debugWriter = new ObservableWriter(newWriter);
@ -746,6 +780,7 @@ public class EnhancedDebugger implements SmackDebugger {
public void userHasLogged(final EntityFullJid user) { public void userHasLogged(final EntityFullJid user) {
final EnhancedDebugger debugger = this; final EnhancedDebugger debugger = this;
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
userField.setText(user.toString()); userField.setText(user.toString());
EnhancedDebuggerWindow.userHasLogged(debugger, user.toString()); EnhancedDebuggerWindow.userHasLogged(debugger, user.toString());
@ -757,18 +792,22 @@ public class EnhancedDebugger implements SmackDebugger {
} }
@Override
public Reader getReader() { public Reader getReader() {
return reader; return reader;
} }
@Override
public Writer getWriter() { public Writer getWriter() {
return writer; return writer;
} }
@Override
public StanzaListener getReaderListener() { public StanzaListener getReaderListener() {
return packetReaderListener; return packetReaderListener;
} }
@Override
public StanzaListener getWriterListener() { public StanzaListener getWriterListener() {
return packetWriterListener; return packetWriterListener;
} }
@ -801,6 +840,7 @@ public class EnhancedDebugger implements SmackDebugger {
*/ */
private void addReadPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) { private void addReadPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
String messageType; String messageType;
Jid from = packet.getFrom(); Jid from = packet.getFrom();
@ -862,6 +902,7 @@ public class EnhancedDebugger implements SmackDebugger {
*/ */
private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) { private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
String messageType; String messageType;
Jid to = packet.getTo(); Jid to = packet.getTo();
@ -978,9 +1019,9 @@ public class EnhancedDebugger implements SmackDebugger {
* The whole text to send must be passed to the constructor. This implies that the client of * The whole text to send must be passed to the constructor. This implies that the client of
* this class is responsible for sending a valid text to the constructor. * this class is responsible for sending a valid text to the constructor.
*/ */
private class AdHocPacket extends Stanza { private static class AdHocPacket extends Stanza {
private String text; private final String text;
/** /**
* Create a new AdHocPacket with the text to send. The passed text must be a valid text to * Create a new AdHocPacket with the text to send. The passed text must be a valid text to
@ -992,6 +1033,7 @@ public class EnhancedDebugger implements SmackDebugger {
this.text = text; this.text = text;
} }
@Override
public String toXML() { public String toXML() {
return text; return text;
} }
@ -1006,7 +1048,7 @@ public class EnhancedDebugger implements SmackDebugger {
/** /**
* Listens for debug window popup dialog events. * Listens for debug window popup dialog events.
*/ */
private class PopupListener extends MouseAdapter { private static class PopupListener extends MouseAdapter {
JPopupMenu popup; JPopupMenu popup;
@ -1014,10 +1056,12 @@ public class EnhancedDebugger implements SmackDebugger {
popup = popupMenu; popup = popupMenu;
} }
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
maybeShowPopup(e); maybeShowPopup(e);
} }
@Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
maybeShowPopup(e); maybeShowPopup(e);
} }
@ -1039,6 +1083,7 @@ public class EnhancedDebugger implements SmackDebugger {
this.table = table; this.table = table;
} }
@Override
public void valueChanged(ListSelectionEvent e) { public void valueChanged(ListSelectionEvent e) {
if (table.getSelectedRow() == -1) { if (table.getSelectedRow() == -1) {
// Clear the messageTextArea since there is none packet selected // Clear the messageTextArea since there is none packet selected

View File

@ -210,6 +210,7 @@ public final class EnhancedDebuggerWindow {
if (!PERSISTED_DEBUGGER) { if (!PERSISTED_DEBUGGER) {
// Add listener for window closing event // Add listener for window closing event
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) { public void windowClosing(WindowEvent evt) {
rootWindowClosing(evt); rootWindowClosing(evt);
} }
@ -280,6 +281,7 @@ public final class EnhancedDebuggerWindow {
// Add a menu item that allows to close the current selected tab // Add a menu item that allows to close the current selected tab
JMenuItem menuItem = new JMenuItem("Close"); JMenuItem menuItem = new JMenuItem("Close");
menuItem.addActionListener(new ActionListener() { menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Remove the selected tab pane if it's not the Smack info pane // Remove the selected tab pane if it's not the Smack info pane
if (tabbedPane.getSelectedIndex() < tabbedPane.getComponentCount() - 1) { if (tabbedPane.getSelectedIndex() < tabbedPane.getComponentCount() - 1) {
@ -301,6 +303,7 @@ public final class EnhancedDebuggerWindow {
// Add a menu item that allows to close all the tabs that have their connections closed // Add a menu item that allows to close all the tabs that have their connections closed
menuItem = new JMenuItem("Close All Not Active"); menuItem = new JMenuItem("Close All Not Active");
menuItem.addActionListener(new ActionListener() { menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ArrayList<EnhancedDebugger> debuggersToRemove = new ArrayList<EnhancedDebugger>(); ArrayList<EnhancedDebugger> debuggersToRemove = new ArrayList<EnhancedDebugger>();
// Remove all the debuggers of which their connections are no longer valid // Remove all the debuggers of which their connections are no longer valid
@ -348,7 +351,7 @@ public final class EnhancedDebuggerWindow {
debugger.cancel(); debugger.cancel();
} }
// Release any reference to the debuggers // Release any reference to the debuggers
debuggers.removeAll(debuggers); debuggers.clear();
// Release the default instance // Release the default instance
instance = null; instance = null;
} }
@ -356,7 +359,7 @@ public final class EnhancedDebuggerWindow {
/** /**
* Listens for debug window popup dialog events. * Listens for debug window popup dialog events.
*/ */
private class PopupListener extends MouseAdapter { private static class PopupListener extends MouseAdapter {
JPopupMenu popup; JPopupMenu popup;
@ -364,10 +367,12 @@ public final class EnhancedDebuggerWindow {
popup = popupMenu; popup = popupMenu;
} }
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
maybeShowPopup(e); maybeShowPopup(e);
} }
@Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
maybeShowPopup(e); maybeShowPopup(e);
} }

View File

@ -86,6 +86,7 @@ public class LiteDebugger implements SmackDebugger {
// Add listener for window closing event // Add listener for window closing event
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) { public void windowClosing(WindowEvent evt) {
rootWindowClosing(evt); rootWindowClosing(evt);
} }
@ -114,6 +115,7 @@ public class LiteDebugger implements SmackDebugger {
JPopupMenu menu = new JPopupMenu(); JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem1 = new JMenuItem("Copy"); JMenuItem menuItem1 = new JMenuItem("Copy");
menuItem1.addActionListener(new ActionListener() { menuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Get the clipboard // Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
@ -124,6 +126,7 @@ public class LiteDebugger implements SmackDebugger {
JMenuItem menuItem2 = new JMenuItem("Clear"); JMenuItem menuItem2 = new JMenuItem("Clear");
menuItem2.addActionListener(new ActionListener() { menuItem2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
sentText1.setText(""); sentText1.setText("");
sentText2.setText(""); sentText2.setText("");
@ -151,6 +154,7 @@ public class LiteDebugger implements SmackDebugger {
menu = new JPopupMenu(); menu = new JPopupMenu();
menuItem1 = new JMenuItem("Copy"); menuItem1 = new JMenuItem("Copy");
menuItem1.addActionListener(new ActionListener() { menuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Get the clipboard // Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
@ -161,6 +165,7 @@ public class LiteDebugger implements SmackDebugger {
menuItem2 = new JMenuItem("Clear"); menuItem2 = new JMenuItem("Clear");
menuItem2.addActionListener(new ActionListener() { menuItem2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
receivedText1.setText(""); receivedText1.setText("");
receivedText2.setText(""); receivedText2.setText("");
@ -188,6 +193,7 @@ public class LiteDebugger implements SmackDebugger {
menu = new JPopupMenu(); menu = new JPopupMenu();
menuItem1 = new JMenuItem("Copy"); menuItem1 = new JMenuItem("Copy");
menuItem1.addActionListener(new ActionListener() { menuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Get the clipboard // Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
@ -198,6 +204,7 @@ public class LiteDebugger implements SmackDebugger {
menuItem2 = new JMenuItem("Clear"); menuItem2 = new JMenuItem("Clear");
menuItem2.addActionListener(new ActionListener() { menuItem2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
interpretedText1.setText(""); interpretedText1.setText("");
interpretedText2.setText(""); interpretedText2.setText("");
@ -219,6 +226,7 @@ public class LiteDebugger implements SmackDebugger {
// Create a special Reader that wraps the main Reader and logs data to the GUI. // Create a special Reader that wraps the main Reader and logs data to the GUI.
ObservableReader debugReader = new ObservableReader(reader); ObservableReader debugReader = new ObservableReader(reader);
readerListener = new ReaderListener() { readerListener = new ReaderListener() {
@Override
public void read(String str) { public void read(String str) {
int index = str.lastIndexOf(">"); int index = str.lastIndexOf(">");
if (index != -1) { if (index != -1) {
@ -242,6 +250,7 @@ public class LiteDebugger implements SmackDebugger {
// Create a special Writer that wraps the main Writer and logs data to the GUI. // Create a special Writer that wraps the main Writer and logs data to the GUI.
ObservableWriter debugWriter = new ObservableWriter(writer); ObservableWriter debugWriter = new ObservableWriter(writer);
writerListener = new WriterListener() { writerListener = new WriterListener() {
@Override
public void write(String str) { public void write(String str) {
sentText1.append(str); sentText1.append(str);
sentText2.append(str); sentText2.append(str);
@ -262,6 +271,7 @@ public class LiteDebugger implements SmackDebugger {
// the GUI. This is what we call "interpreted" packet data, since it's the packet // the GUI. This is what we call "interpreted" packet data, since it's the packet
// data as Smack sees it and not as it's coming in as raw XML. // data as Smack sees it and not as it's coming in as raw XML.
listener = new StanzaListener() { listener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
interpretedText1.append(packet.toXML().toString()); interpretedText1.append(packet.toXML().toString());
interpretedText2.append(packet.toXML().toString()); interpretedText2.append(packet.toXML().toString());
@ -286,17 +296,19 @@ public class LiteDebugger implements SmackDebugger {
/** /**
* Listens for debug window popup dialog events. * Listens for debug window popup dialog events.
*/ */
private class PopupListener extends MouseAdapter { private static class PopupListener extends MouseAdapter {
JPopupMenu popup; JPopupMenu popup;
PopupListener(JPopupMenu popupMenu) { PopupListener(JPopupMenu popupMenu) {
popup = popupMenu; popup = popupMenu;
} }
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
maybeShowPopup(e); maybeShowPopup(e);
} }
@Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
maybeShowPopup(e); maybeShowPopup(e);
} }
@ -308,6 +320,7 @@ public class LiteDebugger implements SmackDebugger {
} }
} }
@Override
public Reader newConnectionReader(Reader newReader) { public Reader newConnectionReader(Reader newReader) {
((ObservableReader)reader).removeReaderListener(readerListener); ((ObservableReader)reader).removeReaderListener(readerListener);
ObservableReader debugReader = new ObservableReader(newReader); ObservableReader debugReader = new ObservableReader(newReader);
@ -316,6 +329,7 @@ public class LiteDebugger implements SmackDebugger {
return reader; return reader;
} }
@Override
public Writer newConnectionWriter(Writer newWriter) { public Writer newConnectionWriter(Writer newWriter) {
((ObservableWriter)writer).removeWriterListener(writerListener); ((ObservableWriter)writer).removeWriterListener(writerListener);
ObservableWriter debugWriter = new ObservableWriter(newWriter); ObservableWriter debugWriter = new ObservableWriter(newWriter);
@ -332,18 +346,22 @@ public class LiteDebugger implements SmackDebugger {
frame.setTitle(title); frame.setTitle(title);
} }
@Override
public Reader getReader() { public Reader getReader() {
return reader; return reader;
} }
@Override
public Writer getWriter() { public Writer getWriter() {
return writer; return writer;
} }
@Override
public StanzaListener getReaderListener() { public StanzaListener getReaderListener() {
return listener; return listener;
} }
@Override
public StanzaListener getWriterListener() { public StanzaListener getWriterListener() {
return null; return null;
} }

View File

@ -72,6 +72,7 @@ public final class CarbonManager extends Manager {
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
getInstanceFor(connection); getInstanceFor(connection);
} }
@ -271,6 +272,7 @@ public final class CarbonManager extends Manager {
try { try {
connection().sendIqWithResponseCallback(setIQ, new StanzaListener() { connection().sendIqWithResponseCallback(setIQ, new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
enabled_state = use; enabled_state = use;
} }

View File

@ -44,6 +44,7 @@ public abstract class AbstractHttpOverXmpp extends IQ {
this.version = Objects.requireNonNull(builder.version, "version must not be null"); this.version = Objects.requireNonNull(builder.version, "version must not be null");
} }
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
IQChildElementXmlStringBuilder builder = getIQHoxtChildElementBuilder(xml); IQChildElementXmlStringBuilder builder = getIQHoxtChildElementBuilder(xml);
builder.optAppend(headers); builder.optAppend(headers);

View File

@ -1,6 +1,6 @@
/** /**
* *
* Copyright © 2016 Florian Schmaus * Copyright © 2016-2017 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.
@ -16,6 +16,7 @@
*/ */
package org.jivesoftware.smackx.iot.control.element; package org.jivesoftware.smackx.iot.control.element;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -31,7 +32,21 @@ public class IoTSetRequest extends IQ {
public IoTSetRequest(Collection<? extends SetData> setData) { public IoTSetRequest(Collection<? extends SetData> setData) {
super(ELEMENT, NAMESPACE); super(ELEMENT, NAMESPACE);
setType(Type.set); setType(Type.set);
this.setData = Collections.unmodifiableCollection(setData);
/*
* Ugly workaround for the following error prone false positive:
*
* IoTSetRequest.java:34: error: incompatible types: Collection<CAP#1> cannot be converted to Collection<SetData>
* this.setData = Collections.unmodifiableCollection(setDataA);
* ^
* where CAP#1 is a fresh type-variable:
* CAP#1 extends SetData from capture of ? extends SetData
*/
Collection<SetData> tmp = new ArrayList<>(setData.size());
for (SetData data : setData) {
tmp.add(data);
}
this.setData = Collections.unmodifiableCollection(tmp);
} }
public Collection<SetData> getSetData() { public Collection<SetData> getSetData() {

View File

@ -30,7 +30,7 @@ public abstract class SetData implements NamedElement {
DOUBLE, DOUBLE,
; ;
private String toStringCache; private final String toStringCache;
private Type() { private Type() {
toStringCache = this.name().toLowerCase(Locale.US); toStringCache = this.name().toLowerCase(Locale.US);

View File

@ -61,6 +61,7 @@ public final class IoTDataManager extends IoTManager {
// Ensure a IoTDataManager exists for every connection. // Ensure a IoTDataManager exists for every connection.
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
if (!isAutoEnableActive()) return; if (!isAutoEnableActive()) return;
getInstanceFor(connection); getInstanceFor(connection);

View File

@ -74,6 +74,7 @@ public final class IoTDiscoveryManager extends Manager {
// Ensure a IoTProvisioningManager exists for every connection. // Ensure a IoTProvisioningManager exists for every connection.
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
if (!IoTManager.isAutoEnableActive()) return; if (!IoTManager.isAutoEnableActive()) return;
getInstanceFor(connection); getInstanceFor(connection);

View File

@ -62,6 +62,7 @@ public final class NodeInfo {
} }
@Override @Override
@SuppressWarnings("ReferenceEquality")
public int hashCode() { public int hashCode() {
if (this == EMPTY) { if (this == EMPTY) {
return 0; return 0;

View File

@ -82,6 +82,7 @@ public final class IoTProvisioningManager extends Manager {
// Ensure a IoTProvisioningManager exists for every connection. // Ensure a IoTProvisioningManager exists for every connection.
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
if (!IoTManager.isAutoEnableActive()) return; if (!IoTManager.isAutoEnableActive()) return;
getInstanceFor(connection); getInstanceFor(connection);

View File

@ -53,6 +53,7 @@ import org.jxmpp.jid.Jid;
* *
* @see <a href="https://xmpp.org/extensions/xep-0296.html">XEP-0296: Best Practices for Resource Locking</a> * @see <a href="https://xmpp.org/extensions/xep-0296.html">XEP-0296: Best Practices for Resource Locking</a>
*/ */
@SuppressWarnings("FunctionalInterfaceClash")
public final class ChatManager extends Manager { public final class ChatManager extends Manager {
private static final Map<XMPPConnection, ChatManager> INSTANCES = new WeakHashMap<>(); private static final Map<XMPPConnection, ChatManager> INSTANCES = new WeakHashMap<>();
@ -188,22 +189,84 @@ public final class ChatManager extends Manager {
return true; return true;
} }
public boolean addListener(IncomingChatMessageListener listener) { /**
* Add a new listener for incoming chat messages.
*
* @param listener the listener to add.
* @return <code>true</code> if the listener was not already added.
*/
public boolean addIncomingListener(IncomingChatMessageListener listener) {
return incomingListeners.add(listener); return incomingListeners.add(listener);
} }
/**
* Add a new listener for incoming chat messages.
*
* @param listener the listener to add.
* @return <code>true</code> if the listener was not already added.
*/
@Deprecated
@SuppressWarnings("FunctionalInterfaceClash")
public boolean addListener(IncomingChatMessageListener listener) {
return addIncomingListener(listener);
}
/**
* Remove an incoming chat message listener.
*
* @param listener the listener to remove.
* @return <code>true</code> if the listener was active and got removed.
*/
@SuppressWarnings("FunctionalInterfaceClash")
public boolean removeListener(IncomingChatMessageListener listener) { public boolean removeListener(IncomingChatMessageListener listener) {
return incomingListeners.remove(listener); return incomingListeners.remove(listener);
} }
public boolean addListener(OutgoingChatMessageListener listener) { /**
* Add a new listener for outgoing chat messages.
*
* @param listener the listener to add.
* @return <code>true</code> if the listener was not already added.
*/
public boolean addOutgoingListener(OutgoingChatMessageListener listener) {
return outgoingListeners.add(listener); return outgoingListeners.add(listener);
} }
public boolean removeOutoingLIstener(OutgoingChatMessageListener listener) { /**
* Add a new listener for incoming chat messages.
*
* @param listener the listener to add.
* @return <code>true</code> if the listener was not already added.
* @deprecated use {@link #addOutgoingListener(OutgoingChatMessageListener)} instead.
*/
@Deprecated
@SuppressWarnings("FunctionalInterfaceClash")
public boolean addListener(OutgoingChatMessageListener listener) {
return addOutgoingListener(listener);
}
/**
* Remove an outgoing chat message listener.
*
* @param listener the listener to remove.
* @return <code>true</code> if the listener was active and got removed.
*/
public boolean removeListener(OutgoingChatMessageListener listener) {
return outgoingListeners.remove(listener); return outgoingListeners.remove(listener);
} }
/**
* Remove an outgoing chat message listener.
*
* @param listener the listener to remove.
* @return <code>true</code> if the listener was active and got removed.
* @deprecated use {@link #removeListener(OutgoingChatMessageListener)} instead.
*/
@Deprecated
public boolean removeOutoingLIstener(OutgoingChatMessageListener listener) {
return removeListener(listener);
}
/** /**
* Start a new or retrieve the existing chat with <code>jid</code>. * Start a new or retrieve the existing chat with <code>jid</code>.
* *

View File

@ -40,6 +40,7 @@ public class AMPManager {
// The ServiceDiscoveryManager class should have been already initialized // The ServiceDiscoveryManager class should have been already initialized
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
AMPManager.setServiceEnabled(connection, true); AMPManager.setServiceEnabled(connection, true);
} }

View File

@ -47,6 +47,7 @@ public class AttentionExtension implements ExtensionElement {
* *
* @see org.jivesoftware.smack.packet.PacketExtension#getElementName() * @see org.jivesoftware.smack.packet.PacketExtension#getElementName()
*/ */
@Override
public String getElementName() { public String getElementName() {
return ELEMENT_NAME; return ELEMENT_NAME;
} }
@ -56,6 +57,7 @@ public class AttentionExtension implements ExtensionElement {
* *
* @see org.jivesoftware.smack.packet.PacketExtension#getNamespace() * @see org.jivesoftware.smack.packet.PacketExtension#getNamespace()
*/ */
@Override
public String getNamespace() { public String getNamespace() {
return NAMESPACE; return NAMESPACE;
} }
@ -65,6 +67,7 @@ public class AttentionExtension implements ExtensionElement {
* *
* @see org.jivesoftware.smack.packet.PacketExtension#toXML() * @see org.jivesoftware.smack.packet.PacketExtension#toXML()
*/ */
@Override
public String toXML() { public String toXML() {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append('<').append(getElementName()).append(" xmlns=\"").append( sb.append('<').append(getElementName()).append(" xmlns=\"").append(

View File

@ -131,6 +131,7 @@ public class BookmarkedConference implements SharedBookmark {
this.isShared = isShared; this.isShared = isShared;
} }
@Override
public boolean isShared() { public boolean isShared() {
return isShared; return isShared;
} }

View File

@ -102,6 +102,7 @@ public class BookmarkedURL implements SharedBookmark {
this.isShared = shared; this.isShared = shared;
} }
@Override
public boolean isShared() { public boolean isShared() {
return isShared; return isShared;
} }

View File

@ -151,6 +151,7 @@ public class Bookmarks implements PrivateData {
* *
* @return the element name. * @return the element name.
*/ */
@Override
public String getElementName() { public String getElementName() {
return ELEMENT; return ELEMENT;
} }
@ -160,6 +161,7 @@ public class Bookmarks implements PrivateData {
* *
* @return the namespace. * @return the namespace.
*/ */
@Override
public String getNamespace() { public String getNamespace() {
return NAMESPACE; return NAMESPACE;
} }
@ -218,6 +220,7 @@ public class Bookmarks implements PrivateData {
super(); super();
} }
@Override
public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException { public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException {
Bookmarks storage = new Bookmarks(); Bookmarks storage = new Bookmarks();

View File

@ -34,6 +34,7 @@ public abstract class InBandBytestreamListener implements BytestreamListener {
@Override
public void incomingBytestreamRequest(BytestreamRequest request) { public void incomingBytestreamRequest(BytestreamRequest request) {
incomingBytestreamRequest((InBandBytestreamRequest) request); incomingBytestreamRequest((InBandBytestreamRequest) request);
} }

View File

@ -103,6 +103,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
*/ */
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(final XMPPConnection connection) { public void connectionCreated(final XMPPConnection connection) {
// create the manager for this connection // create the manager for this connection
InBandBytestreamManager.getByteStreamManager(connection); InBandBytestreamManager.getByteStreamManager(connection);
@ -236,6 +237,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
* *
* @param listener the listener to register * @param listener the listener to register
*/ */
@Override
public void addIncomingBytestreamListener(BytestreamListener listener) { public void addIncomingBytestreamListener(BytestreamListener listener) {
this.allRequestListeners.add(listener); this.allRequestListeners.add(listener);
} }
@ -246,6 +248,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
* *
* @param listener the listener to remove * @param listener the listener to remove
*/ */
@Override
public void removeIncomingBytestreamListener(BytestreamListener listener) { public void removeIncomingBytestreamListener(BytestreamListener listener) {
this.allRequestListeners.remove(listener); this.allRequestListeners.remove(listener);
} }
@ -268,6 +271,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
* @param listener the listener to register * @param listener the listener to register
* @param initiatorJID the JID of the user that wants to establish an In-Band Bytestream * @param initiatorJID the JID of the user that wants to establish an In-Band Bytestream
*/ */
@Override
public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID) { public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID) {
this.userListeners.put(initiatorJID, listener); this.userListeners.put(initiatorJID, listener);
} }
@ -277,6 +281,9 @@ public final class InBandBytestreamManager implements BytestreamManager {
* *
* @param initiatorJID the JID of the user the listener should be removed * @param initiatorJID the JID of the user the listener should be removed
*/ */
@Override
// TODO: Change argument to Jid in Smack 4.3.
@SuppressWarnings("CollectionIncompatibleType")
public void removeIncomingBytestreamListener(String initiatorJID) { public void removeIncomingBytestreamListener(String initiatorJID) {
this.userListeners.remove(initiatorJID); this.userListeners.remove(initiatorJID);
} }
@ -402,6 +409,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
* @throws SmackException if there was no response from the server. * @throws SmackException if there was no response from the server.
* @throws InterruptedException * @throws InterruptedException
*/ */
@Override
public InBandBytestreamSession establishSession(Jid targetJID) throws XMPPException, SmackException, InterruptedException { public InBandBytestreamSession establishSession(Jid targetJID) throws XMPPException, SmackException, InterruptedException {
String sessionID = getNextSessionID(); String sessionID = getNextSessionID();
return establishSession(targetJID, sessionID); return establishSession(targetJID, sessionID);
@ -420,6 +428,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
@Override
public InBandBytestreamSession establishSession(Jid targetJID, String sessionID) public InBandBytestreamSession establishSession(Jid targetJID, String sessionID)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Open byteStreamRequest = new Open(sessionID, this.defaultBlockSize, this.stanza); Open byteStreamRequest = new Open(sessionID, this.defaultBlockSize, this.stanza);

View File

@ -50,6 +50,7 @@ public class InBandBytestreamRequest implements BytestreamRequest {
* *
* @return the sender of the In-Band Bytestream open request * @return the sender of the In-Band Bytestream open request
*/ */
@Override
public Jid getFrom() { public Jid getFrom() {
return this.byteStreamRequest.getFrom(); return this.byteStreamRequest.getFrom();
} }
@ -59,6 +60,7 @@ public class InBandBytestreamRequest implements BytestreamRequest {
* *
* @return the session ID of the In-Band Bytestream open request * @return the session ID of the In-Band Bytestream open request
*/ */
@Override
public String getSessionID() { public String getSessionID() {
return this.byteStreamRequest.getSessionID(); return this.byteStreamRequest.getSessionID();
} }
@ -71,6 +73,7 @@ public class InBandBytestreamRequest implements BytestreamRequest {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
@Override
public InBandBytestreamSession accept() throws NotConnectedException, InterruptedException { public InBandBytestreamSession accept() throws NotConnectedException, InterruptedException {
XMPPConnection connection = this.manager.getConnection(); XMPPConnection connection = this.manager.getConnection();
@ -92,6 +95,7 @@ public class InBandBytestreamRequest implements BytestreamRequest {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
@Override
public void reject() throws NotConnectedException, InterruptedException { public void reject() throws NotConnectedException, InterruptedException {
this.manager.replyRejectPacket(this.byteStreamRequest); this.manager.replyRejectPacket(this.byteStreamRequest);
} }

View File

@ -109,18 +109,22 @@ public class InBandBytestreamSession implements BytestreamSession {
} }
@Override
public InputStream getInputStream() { public InputStream getInputStream() {
return this.inputStream; return this.inputStream;
} }
@Override
public OutputStream getOutputStream() { public OutputStream getOutputStream() {
return this.outputStream; return this.outputStream;
} }
@Override
public int getReadTimeout() { public int getReadTimeout() {
return this.inputStream.readTimeout; return this.inputStream.readTimeout;
} }
@Override
public void setReadTimeout(int timeout) { public void setReadTimeout(int timeout) {
if (timeout < 0) { if (timeout < 0) {
throw new IllegalArgumentException("Timeout must be >= 0"); throw new IllegalArgumentException("Timeout must be >= 0");
@ -151,6 +155,7 @@ public class InBandBytestreamSession implements BytestreamSession {
this.closeBothStreamsEnabled = closeBothStreamsEnabled; this.closeBothStreamsEnabled = closeBothStreamsEnabled;
} }
@Override
public void close() throws IOException { public void close() throws IOException {
closeByLocal(true); // close input stream closeByLocal(true); // close input stream
closeByLocal(false); // close output stream closeByLocal(false); // close output stream
@ -224,7 +229,9 @@ public class InBandBytestreamSession implements BytestreamSession {
this.inputStream.cleanup(); this.inputStream.cleanup();
// remove session from manager // remove session from manager
InBandBytestreamManager.getByteStreamManager(this.connection).getSessions().remove(this); // Thanks Google Error Prone for finding the bug where remove() was called with 'this' as argument. Changed
// now to remove(byteStreamRequest.getSessionID).
InBandBytestreamManager.getByteStreamManager(this.connection).getSessions().remove(byteStreamRequest.getSessionID());
} }
} }
@ -283,6 +290,7 @@ public class InBandBytestreamSession implements BytestreamSession {
*/ */
protected abstract StanzaFilter getDataPacketFilter(); protected abstract StanzaFilter getDataPacketFilter();
@Override
public synchronized int read() throws IOException { public synchronized int read() throws IOException {
checkClosed(); checkClosed();
@ -298,6 +306,7 @@ public class InBandBytestreamSession implements BytestreamSession {
return buffer[bufferPointer++] & 0xff; return buffer[bufferPointer++] & 0xff;
} }
@Override
public synchronized int read(byte[] b, int off, int len) throws IOException { public synchronized int read(byte[] b, int off, int len) throws IOException {
if (b == null) { if (b == null) {
throw new NullPointerException(); throw new NullPointerException();
@ -331,6 +340,7 @@ public class InBandBytestreamSession implements BytestreamSession {
return len; return len;
} }
@Override
public synchronized int read(byte[] b) throws IOException { public synchronized int read(byte[] b) throws IOException {
return read(b, 0, b.length); return read(b, 0, b.length);
} }
@ -405,10 +415,12 @@ public class InBandBytestreamSession implements BytestreamSession {
} }
} }
@Override
public boolean markSupported() { public boolean markSupported() {
return false; return false;
} }
@Override
public void close() throws IOException { public void close() throws IOException {
if (closeInvoked) { if (closeInvoked) {
return; return;
@ -444,11 +456,13 @@ public class InBandBytestreamSession implements BytestreamSession {
*/ */
private class IQIBBInputStream extends IBBInputStream { private class IQIBBInputStream extends IBBInputStream {
@Override
protected StanzaListener getDataPacketListener() { protected StanzaListener getDataPacketListener() {
return new StanzaListener() { return new StanzaListener() {
private long lastSequence = -1; private long lastSequence = -1;
@Override
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException { public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
// get data packet extension // get data packet extension
DataPacketExtension data = ((Data) packet).getDataPacketExtension(); DataPacketExtension data = ((Data) packet).getDataPacketExtension();
@ -491,6 +505,7 @@ public class InBandBytestreamSession implements BytestreamSession {
}; };
} }
@Override
protected StanzaFilter getDataPacketFilter() { protected StanzaFilter getDataPacketFilter() {
/* /*
* filter all IQ stanzas having type 'SET' (represented by Data class), containing a * filter all IQ stanzas having type 'SET' (represented by Data class), containing a
@ -507,9 +522,11 @@ public class InBandBytestreamSession implements BytestreamSession {
*/ */
private class MessageIBBInputStream extends IBBInputStream { private class MessageIBBInputStream extends IBBInputStream {
@Override
protected StanzaListener getDataPacketListener() { protected StanzaListener getDataPacketListener() {
return new StanzaListener() { return new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
// get data packet extension // get data packet extension
DataPacketExtension data = (DataPacketExtension) packet.getExtension( DataPacketExtension data = (DataPacketExtension) packet.getExtension(
@ -555,6 +572,7 @@ public class InBandBytestreamSession implements BytestreamSession {
*/ */
private class IBBDataPacketFilter implements StanzaFilter { private class IBBDataPacketFilter implements StanzaFilter {
@Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
// sender equals remote peer // sender equals remote peer
if (!packet.getFrom().equals(remoteJID)) { if (!packet.getFrom().equals(remoteJID)) {
@ -619,6 +637,7 @@ public class InBandBytestreamSession implements BytestreamSession {
*/ */
protected abstract void writeToXML(DataPacketExtension data) throws IOException, NotConnectedException, InterruptedException; protected abstract void writeToXML(DataPacketExtension data) throws IOException, NotConnectedException, InterruptedException;
@Override
public synchronized void write(int b) throws IOException { public synchronized void write(int b) throws IOException {
if (this.isClosed) { if (this.isClosed) {
throw new IOException("Stream is closed"); throw new IOException("Stream is closed");
@ -632,6 +651,7 @@ public class InBandBytestreamSession implements BytestreamSession {
buffer[bufferPointer++] = (byte) b; buffer[bufferPointer++] = (byte) b;
} }
@Override
public synchronized void write(byte[] b, int off, int len) throws IOException { public synchronized void write(byte[] b, int off, int len) throws IOException {
if (b == null) { if (b == null) {
throw new NullPointerException(); throw new NullPointerException();
@ -662,6 +682,7 @@ public class InBandBytestreamSession implements BytestreamSession {
} }
} }
@Override
public synchronized void write(byte[] b) throws IOException { public synchronized void write(byte[] b) throws IOException {
write(b, 0, b.length); write(b, 0, b.length);
} }
@ -698,6 +719,7 @@ public class InBandBytestreamSession implements BytestreamSession {
bufferPointer += len - available; bufferPointer += len - available;
} }
@Override
public synchronized void flush() throws IOException { public synchronized void flush() throws IOException {
if (this.isClosed) { if (this.isClosed) {
throw new IOException("Stream is closed"); throw new IOException("Stream is closed");
@ -735,6 +757,7 @@ public class InBandBytestreamSession implements BytestreamSession {
} }
@Override
public void close() throws IOException { public void close() throws IOException {
if (isClosed) { if (isClosed) {
return; return;

View File

@ -66,6 +66,7 @@ class InitiationListener extends AbstractIqRequestHandler {
public IQ handleIQRequest(final IQ packet) { public IQ handleIQRequest(final IQ packet) {
initiationListenerExecutor.execute(new Runnable() { initiationListenerExecutor.execute(new Runnable() {
@Override
public void run() { public void run() {
try { try {
processRequest(packet); processRequest(packet);

View File

@ -126,10 +126,12 @@ public class DataPacketExtension implements ExtensionElement {
return this.decodedData; return this.decodedData;
} }
@Override
public String getElementName() { public String getElementName() {
return ELEMENT; return ELEMENT;
} }
@Override
public String getNamespace() { public String getNamespace() {
return NAMESPACE; return NAMESPACE;
} }

View File

@ -62,6 +62,7 @@ final class InitiationListener extends AbstractIqRequestHandler {
public IQ handleIQRequest(final IQ packet) { public IQ handleIQRequest(final IQ packet) {
initiationListenerExecutor.execute(new Runnable() { initiationListenerExecutor.execute(new Runnable() {
@Override
public void run() { public void run() {
try { try {
processRequest(packet); processRequest(packet);

View File

@ -32,6 +32,7 @@ import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
*/ */
public abstract class Socks5BytestreamListener implements BytestreamListener { public abstract class Socks5BytestreamListener implements BytestreamListener {
@Override
public void incomingBytestreamRequest(BytestreamRequest request) { public void incomingBytestreamRequest(BytestreamRequest request) {
incomingBytestreamRequest((Socks5BytestreamRequest) request); incomingBytestreamRequest((Socks5BytestreamRequest) request);
} }

View File

@ -98,6 +98,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(final XMPPConnection connection) { public void connectionCreated(final XMPPConnection connection) {
// create the manager for this connection // create the manager for this connection
Socks5BytestreamManager.getBytestreamManager(connection); Socks5BytestreamManager.getBytestreamManager(connection);
@ -198,6 +199,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
* *
* @param listener the listener to register * @param listener the listener to register
*/ */
@Override
public void addIncomingBytestreamListener(BytestreamListener listener) { public void addIncomingBytestreamListener(BytestreamListener listener) {
this.allRequestListeners.add(listener); this.allRequestListeners.add(listener);
} }
@ -208,6 +210,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
* *
* @param listener the listener to remove * @param listener the listener to remove
*/ */
@Override
public void removeIncomingBytestreamListener(BytestreamListener listener) { public void removeIncomingBytestreamListener(BytestreamListener listener) {
this.allRequestListeners.remove(listener); this.allRequestListeners.remove(listener);
} }
@ -230,6 +233,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
* @param listener the listener to register * @param listener the listener to register
* @param initiatorJID the JID of the user that wants to establish a SOCKS5 Bytestream * @param initiatorJID the JID of the user that wants to establish a SOCKS5 Bytestream
*/ */
@Override
public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID) { public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID) {
this.userListeners.put(initiatorJID, listener); this.userListeners.put(initiatorJID, listener);
} }
@ -239,6 +243,9 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
* *
* @param initiatorJID the JID of the user the listener should be removed * @param initiatorJID the JID of the user the listener should be removed
*/ */
// TODO: Change parameter to Jid in Smack 4.3.
@Override
@SuppressWarnings("CollectionIncompatibleType")
public void removeIncomingBytestreamListener(String initiatorJID) { public void removeIncomingBytestreamListener(String initiatorJID) {
this.userListeners.remove(initiatorJID); this.userListeners.remove(initiatorJID);
} }
@ -386,6 +393,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
* @throws InterruptedException if the current thread was interrupted while waiting * @throws InterruptedException if the current thread was interrupted while waiting
* @throws SmackException if there was no response from the server. * @throws SmackException if there was no response from the server.
*/ */
@Override
public Socks5BytestreamSession establishSession(Jid targetJID) throws XMPPException, public Socks5BytestreamSession establishSession(Jid targetJID) throws XMPPException,
IOException, InterruptedException, SmackException { IOException, InterruptedException, SmackException {
String sessionID = getNextSessionID(); String sessionID = getNextSessionID();
@ -405,6 +413,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
* @throws SmackException if the target does not support SOCKS5. * @throws SmackException if the target does not support SOCKS5.
* @throws XMPPException * @throws XMPPException
*/ */
@Override
public Socks5BytestreamSession establishSession(Jid targetJID, String sessionID) public Socks5BytestreamSession establishSession(Jid targetJID, String sessionID)
throws IOException, InterruptedException, NoResponseException, SmackException, XMPPException{ throws IOException, InterruptedException, NoResponseException, SmackException, XMPPException{
XMPPConnection connection = connection(); XMPPConnection connection = connection();

View File

@ -170,6 +170,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
* *
* @return the sender of the SOCKS5 Bytestream initialization request. * @return the sender of the SOCKS5 Bytestream initialization request.
*/ */
@Override
public Jid getFrom() { public Jid getFrom() {
return this.bytestreamRequest.getFrom(); return this.bytestreamRequest.getFrom();
} }
@ -179,6 +180,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
* *
* @return the session ID of the SOCKS5 Bytestream initialization request. * @return the session ID of the SOCKS5 Bytestream initialization request.
*/ */
@Override
public String getSessionID() { public String getSessionID() {
return this.bytestreamRequest.getSessionID(); return this.bytestreamRequest.getSessionID();
} }
@ -195,6 +197,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
* @throws XMPPErrorException * @throws XMPPErrorException
* @throws SmackException * @throws SmackException
*/ */
@Override
public Socks5BytestreamSession accept() throws InterruptedException, XMPPErrorException, SmackException { public Socks5BytestreamSession accept() throws InterruptedException, XMPPErrorException, SmackException {
Collection<StreamHost> streamHosts = this.bytestreamRequest.getStreamHosts(); Collection<StreamHost> streamHosts = this.bytestreamRequest.getStreamHosts();
@ -264,6 +267,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
@Override
public void reject() throws NotConnectedException, InterruptedException { public void reject() throws NotConnectedException, InterruptedException {
this.manager.replyRejectPacket(this.bytestreamRequest); this.manager.replyRejectPacket(this.bytestreamRequest);
} }

View File

@ -64,14 +64,17 @@ public class Socks5BytestreamSession implements BytestreamSession {
return !this.isDirect; return !this.isDirect;
} }
@Override
public InputStream getInputStream() throws IOException { public InputStream getInputStream() throws IOException {
return this.socket.getInputStream(); return this.socket.getInputStream();
} }
@Override
public OutputStream getOutputStream() throws IOException { public OutputStream getOutputStream() throws IOException {
return this.socket.getOutputStream(); return this.socket.getOutputStream();
} }
@Override
public int getReadTimeout() throws IOException { public int getReadTimeout() throws IOException {
try { try {
return this.socket.getSoTimeout(); return this.socket.getSoTimeout();
@ -81,6 +84,7 @@ public class Socks5BytestreamSession implements BytestreamSession {
} }
} }
@Override
public void setReadTimeout(int timeout) throws IOException { public void setReadTimeout(int timeout) throws IOException {
try { try {
this.socket.setSoTimeout(timeout); this.socket.setSoTimeout(timeout);
@ -90,6 +94,7 @@ public class Socks5BytestreamSession implements BytestreamSession {
} }
} }
@Override
public void close() throws IOException { public void close() throws IOException {
this.socket.close(); this.socket.close();
} }

View File

@ -19,6 +19,7 @@ package org.jivesoftware.smackx.bytestreams.socks5;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress; import java.net.SocketAddress;
@ -34,6 +35,7 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
/** /**
@ -82,6 +84,7 @@ class Socks5Client {
// wrap connecting in future for timeout // wrap connecting in future for timeout
FutureTask<Socket> futureTask = new FutureTask<Socket>(new Callable<Socket>() { FutureTask<Socket> futureTask = new FutureTask<Socket>(new Callable<Socket>() {
@Override
public Socket call() throws IOException, SmackException { public Socket call() throws IOException, SmackException {
// initialize socket // initialize socket
@ -199,7 +202,13 @@ class Socks5Client {
* @return SOCKS5 connection request message * @return SOCKS5 connection request message
*/ */
private byte[] createSocks5ConnectRequest() { private byte[] createSocks5ConnectRequest() {
byte[] addr = this.digest.getBytes(); byte[] addr;
try {
addr = digest.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
byte[] data = new byte[7 + addr.length]; byte[] data = new byte[7 + addr.length];
data[0] = (byte) 0x05; // version (SOCKS5) data[0] = (byte) 0x05; // version (SOCKS5)

View File

@ -69,6 +69,7 @@ class Socks5ClientForInitiator extends Socks5Client {
this.target = target; this.target = target;
} }
@Override
public Socket getSocket(int timeout) throws IOException, InterruptedException, public Socket getSocket(int timeout) throws IOException, InterruptedException,
TimeoutException, XMPPException, SmackException { TimeoutException, XMPPException, SmackException {
Socket socket = null; Socket socket = null;

View File

@ -38,6 +38,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.util.StringUtils;
/** /**
* The Socks5Proxy class represents a local SOCKS5 proxy server. It can be enabled/disabled by * The Socks5Proxy class represents a local SOCKS5 proxy server. It can be enabled/disabled by
@ -381,6 +382,7 @@ public final class Socks5Proxy {
*/ */
private class Socks5ServerProcess implements Runnable { private class Socks5ServerProcess implements Runnable {
@Override
public void run() { public void run() {
while (true) { while (true) {
Socket socket = null; Socket socket = null;
@ -470,7 +472,7 @@ public final class Socks5Proxy {
byte[] connectionRequest = Socks5Utils.receiveSocks5Message(in); byte[] connectionRequest = Socks5Utils.receiveSocks5Message(in);
// extract digest // extract digest
String responseDigest = new String(connectionRequest, 5, connectionRequest[4]); String responseDigest = new String(connectionRequest, 5, connectionRequest[4], StringUtils.UTF8);
// return error if digest is not allowed // return error if digest is not allowed
if (!Socks5Proxy.this.allowedConnections.contains(responseDigest)) { if (!Socks5Proxy.this.allowedConnections.contains(responseDigest)) {

View File

@ -317,6 +317,7 @@ public class Bytestream extends IQ {
return port; return port;
} }
@Override
public String getElementName() { public String getElementName() {
return ELEMENTNAME; return ELEMENTNAME;
} }
@ -366,6 +367,7 @@ public class Bytestream extends IQ {
return JID; return JID;
} }
@Override
public String getElementName() { public String getElementName() {
return ELEMENTNAME; return ELEMENTNAME;
} }
@ -408,6 +410,7 @@ public class Bytestream extends IQ {
return target; return target;
} }
@Override
public String getElementName() { public String getElementName() {
return ELEMENTNAME; return ELEMENTNAME;
} }

View File

@ -65,6 +65,7 @@ import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -113,6 +114,7 @@ public final class EntityCapsManager extends Manager {
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
getInstanceFor(connection); getInstanceFor(connection);
} }
@ -346,6 +348,7 @@ public final class EntityCapsManager extends Manager {
// XEP-0115 specifies that a client SHOULD include entity capabilities // XEP-0115 specifies that a client SHOULD include entity capabilities
// with every presence notification it sends. // with every presence notification it sends.
StanzaListener packetInterceptor = new StanzaListener() { StanzaListener packetInterceptor = new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
if (!entityCapsEnabled) { if (!entityCapsEnabled) {
// Be sure to not send stanzas with the caps extension if it's not enabled // Be sure to not send stanzas with the caps extension if it's not enabled
@ -403,7 +406,11 @@ public final class EntityCapsManager extends Manager {
* @param user * @param user
* the user (Full JID) * the user (Full JID)
*/ */
// TODO: Change parameter type to Jid in Smack 4.3.
@SuppressWarnings("CollectionIncompatibleType")
public static void removeUserCapsNode(String user) { public static void removeUserCapsNode(String user) {
// While JID_TO_NODEVER_CHACHE has the generic types <Jid, NodeVerHash>, it is ok to call remove with String
// arguments, since the same Jid and String representations would be equal and have the same hash code.
JID_TO_NODEVER_CACHE.remove(user); JID_TO_NODEVER_CACHE.remove(user);
} }
@ -658,6 +665,7 @@ public final class EntityCapsManager extends Manager {
// XEP-0128 data forms, sort the forms by the FORM_TYPE (i.e., // XEP-0128 data forms, sort the forms by the FORM_TYPE (i.e.,
// by the XML character data of the <value/> element). // by the XML character data of the <value/> element).
SortedSet<FormField> fs = new TreeSet<FormField>(new Comparator<FormField>() { SortedSet<FormField> fs = new TreeSet<FormField>(new Comparator<FormField>() {
@Override
public int compare(FormField f1, FormField f2) { public int compare(FormField f1, FormField f2) {
return f1.getVariable().compareTo(f2.getVariable()); return f1.getVariable().compareTo(f2.getVariable());
} }
@ -701,9 +709,16 @@ public final class EntityCapsManager extends Manager {
// encoded using Base64 as specified in Section 4 of RFC 4648 // encoded using Base64 as specified in Section 4 of RFC 4648
// (note: the Base64 output MUST NOT include whitespace and MUST set // (note: the Base64 output MUST NOT include whitespace and MUST set
// padding bits to zero). // padding bits to zero).
byte[] bytes;
try {
bytes = sb.toString().getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
byte[] digest; byte[] digest;
synchronized(md) { synchronized(md) {
digest = md.digest(sb.toString().getBytes()); digest = md.digest(bytes);
} }
String version = Base64.encodeToString(digest); String version = Base64.encodeToString(digest);
return new CapsVersionAndHash(version, hash); return new CapsVersionAndHash(version, hash);

View File

@ -35,10 +35,12 @@ public class CapsExtension implements ExtensionElement {
this.hash = hash; this.hash = hash;
} }
@Override
public String getElementName() { public String getElementName() {
return ELEMENT; return ELEMENT;
} }
@Override
public String getNamespace() { public String getNamespace() {
return NAMESPACE; return NAMESPACE;
} }

View File

@ -27,6 +27,7 @@ import org.xmlpull.v1.XmlPullParserException;
public class CapsExtensionProvider extends ExtensionElementProvider<CapsExtension> { public class CapsExtensionProvider extends ExtensionElementProvider<CapsExtension> {
@Override
public CapsExtension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, public CapsExtension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
SmackException { SmackException {
String hash = null; String hash = null;

View File

@ -119,6 +119,7 @@ public final class ChatStateManager extends Manager {
} }
@Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
@ -129,6 +130,7 @@ public final class ChatStateManager extends Manager {
} }
@Override
public int hashCode() { public int hashCode() {
return connection().hashCode(); return connection().hashCode();
} }
@ -164,12 +166,14 @@ public final class ChatStateManager extends Manager {
} }
} }
private class IncomingMessageInterceptor implements ChatManagerListener, ChatMessageListener { private static class IncomingMessageInterceptor implements ChatManagerListener, ChatMessageListener {
@Override
public void chatCreated(final org.jivesoftware.smack.chat.Chat chat, boolean createdLocally) { public void chatCreated(final org.jivesoftware.smack.chat.Chat chat, boolean createdLocally) {
chat.addMessageListener(this); chat.addMessageListener(this);
} }
@Override
public void processMessage(org.jivesoftware.smack.chat.Chat chat, Message message) { public void processMessage(org.jivesoftware.smack.chat.Chat chat, Message message) {
ExtensionElement extension = message.getExtension(NAMESPACE); ExtensionElement extension = message.getExtension(NAMESPACE);
if (extension == null) { if (extension == null) {

View File

@ -457,12 +457,13 @@ public abstract class AdHocCommand {
*/ */
sessionExpired("session-expired"); sessionExpired("session-expired");
private String value; private final String value;
SpecificErrorCondition(String value) { SpecificErrorCondition(String value) {
this.value = value; this.value = value;
} }
@Override
public String toString() { public String toString() {
return value; return value;
} }

View File

@ -17,6 +17,7 @@
package org.jivesoftware.smackx.commands; package org.jivesoftware.smackx.commands;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -83,6 +84,7 @@ public final class AdHocCommandManager extends Manager {
*/ */
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
getAddHocCommandsManager(connection); getAddHocCommandsManager(connection);
} }
@ -200,8 +202,16 @@ public final class AdHocCommandManager extends Manager {
*/ */
public void registerCommand(String node, String name, final Class<? extends LocalCommand> clazz) { public void registerCommand(String node, String name, final Class<? extends LocalCommand> clazz) {
registerCommand(node, name, new LocalCommandFactory() { registerCommand(node, name, new LocalCommandFactory() {
@Override
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException { public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
return clazz.newInstance(); try {
return clazz.getConstructor().newInstance();
}
catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e) {
// TODO: Throw those method in Smack 4.3.
throw new IllegalStateException(e);
}
} }
}); });
} }
@ -393,6 +403,7 @@ public final class AdHocCommandManager extends Manager {
// See if the session reaping thread is started. If not, start it. // See if the session reaping thread is started. If not, start it.
if (sessionsSweeper == null) { if (sessionsSweeper == null) {
sessionsSweeper = new Thread(new Runnable() { sessionsSweeper = new Thread(new Runnable() {
@Override
public void run() { public void run() {
while (true) { while (true) {
for (String sessionId : executingCommands.keySet()) { for (String sessionId : executingCommands.keySet()) {

View File

@ -248,9 +248,11 @@ public class AdHocCommandData extends IQ {
this.condition = condition; this.condition = condition;
} }
@Override
public String getElementName() { public String getElementName() {
return condition.toString(); return condition.toString();
} }
@Override
public String getNamespace() { public String getNamespace() {
return namespace; return namespace;
} }
@ -259,6 +261,7 @@ public class AdHocCommandData extends IQ {
return condition; return condition;
} }
@Override
public String toXML() { public String toXML() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append('<').append(getElementName()); buf.append('<').append(getElementName());

View File

@ -88,10 +88,12 @@ public class DelayInformation implements ExtensionElement {
return reason; return reason;
} }
@Override
public String getElementName() { public String getElementName() {
return ELEMENT; return ELEMENT;
} }
@Override
public String getNamespace() { public String getNamespace() {
return NAMESPACE; return NAMESPACE;
} }

View File

@ -25,18 +25,22 @@ import java.util.List;
public abstract class AbstractNodeInformationProvider implements NodeInformationProvider { public abstract class AbstractNodeInformationProvider implements NodeInformationProvider {
@Override
public List<DiscoverItems.Item> getNodeItems() { public List<DiscoverItems.Item> getNodeItems() {
return null; return null;
} }
@Override
public List<String> getNodeFeatures() { public List<String> getNodeFeatures() {
return null; return null;
} }
@Override
public List<DiscoverInfo.Identity> getNodeIdentities() { public List<DiscoverInfo.Identity> getNodeIdentities() {
return null; return null;
} }
@Override
public List<ExtensionElement> getNodePacketExtensions() { public List<ExtensionElement> getNodePacketExtensions() {
return null; return null;
} }

View File

@ -91,6 +91,7 @@ public final class ServiceDiscoveryManager extends Manager {
// Create a new ServiceDiscoveryManager on every established connection // Create a new ServiceDiscoveryManager on every established connection
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
getInstanceFor(connection); getInstanceFor(connection);
} }

View File

@ -394,6 +394,7 @@ public class DiscoverInfo extends IQ implements TypedCloneable<DiscoverInfo> {
* <a href="http://xmpp.org/extensions/xep-0115.html#ver-proc">XEP-0015 5.4 Processing Method (Step 3.3)</a>. * <a href="http://xmpp.org/extensions/xep-0115.html#ver-proc">XEP-0015 5.4 Processing Method (Step 3.3)</a>.
* *
*/ */
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) if (obj == null)
return false; return false;
@ -437,6 +438,7 @@ public class DiscoverInfo extends IQ implements TypedCloneable<DiscoverInfo> {
* @return a negative integer, zero, or a positive integer as this object is less than, * @return a negative integer, zero, or a positive integer as this object is less than,
* equal to, or greater than the specified object. * equal to, or greater than the specified object.
*/ */
@Override
public int compareTo(DiscoverInfo.Identity other) { public int compareTo(DiscoverInfo.Identity other) {
String otherLang = other.lang == null ? "" : other.lang; String otherLang = other.lang == null ? "" : other.lang;
String thisLang = lang == null ? "" : lang; String thisLang = lang == null ? "" : lang;
@ -512,6 +514,7 @@ public class DiscoverInfo extends IQ implements TypedCloneable<DiscoverInfo> {
return xml; return xml;
} }
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) if (obj == null)
return false; return false;

View File

@ -55,11 +55,13 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
secondaryNegotiator.newStreamInitiation(from, streamID); secondaryNegotiator.newStreamInitiation(from, streamID);
} }
@Override
InputStream negotiateIncomingStream(Stanza streamInitiation) { InputStream negotiateIncomingStream(Stanza streamInitiation) {
throw new UnsupportedOperationException("Negotiation only handled by create incoming " + throw new UnsupportedOperationException("Negotiation only handled by create incoming " +
"stream method."); "stream method.");
} }
@Override
public InputStream createIncomingStream(final StreamInitiation initiation) throws SmackException, XMPPErrorException, InterruptedException { public InputStream createIncomingStream(final StreamInitiation initiation) throws SmackException, XMPPErrorException, InterruptedException {
// This could be either an xep47 ibb 'open' iq or an xep65 streamhost iq // This could be either an xep47 ibb 'open' iq or an xep65 streamhost iq
IQ initationSet = initiateIncomingStream(connection, initiation); IQ initationSet = initiateIncomingStream(connection, initiation);
@ -79,6 +81,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
} }
} }
@Override
public OutputStream createOutgoingStream(String streamID, Jid initiator, Jid target) public OutputStream createOutgoingStream(String streamID, Jid initiator, Jid target)
throws SmackException, XMPPException, InterruptedException { throws SmackException, XMPPException, InterruptedException {
OutputStream stream; OutputStream stream;
@ -92,6 +95,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
return stream; return stream;
} }
@Override
public String[] getNamespaces() { public String[] getNamespaces() {
String[] primary = primaryNegotiator.getNamespaces(); String[] primary = primaryNegotiator.getNamespaces();
String[] secondary = secondaryNegotiator.getNamespaces(); String[] secondary = secondaryNegotiator.getNamespaces();

View File

@ -292,12 +292,13 @@ public abstract class FileTransfer {
*/ */
cancelled("Cancelled"); cancelled("Cancelled");
private String status; private final String status;
private Status(String status) { private Status(String status) {
this.status = status; this.status = status;
} }
@Override
public String toString() { public String toString() {
return status; return status;
} }
@ -358,6 +359,7 @@ public abstract class FileTransfer {
return msg; return msg;
} }
@Override
public String toString() { public String toString() {
return msg; return msg;
} }

View File

@ -58,6 +58,7 @@ public class IBBTransferNegotiator extends StreamNegotiator {
this.manager = InBandBytestreamManager.getByteStreamManager(connection); this.manager = InBandBytestreamManager.getByteStreamManager(connection);
} }
@Override
public OutputStream createOutgoingStream(String streamID, Jid initiator, public OutputStream createOutgoingStream(String streamID, Jid initiator,
Jid target) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Jid target) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
InBandBytestreamSession session = this.manager.establishSession(target, streamID); InBandBytestreamSession session = this.manager.establishSession(target, streamID);
@ -65,6 +66,7 @@ public class IBBTransferNegotiator extends StreamNegotiator {
return session.getOutputStream(); return session.getOutputStream();
} }
@Override
public InputStream createIncomingStream(StreamInitiation initiation) public InputStream createIncomingStream(StreamInitiation initiation)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
/* /*
@ -87,10 +89,12 @@ public class IBBTransferNegotiator extends StreamNegotiator {
this.manager.ignoreBytestreamRequestOnce(streamID); this.manager.ignoreBytestreamRequestOnce(streamID);
} }
@Override
public String[] getNamespaces() { public String[] getNamespaces() {
return new String[] { DataPacketExtension.NAMESPACE }; return new String[] { DataPacketExtension.NAMESPACE };
} }
@Override
InputStream negotiateIncomingStream(Stanza streamInitiation) throws NotConnectedException, InterruptedException { InputStream negotiateIncomingStream(Stanza streamInitiation) throws NotConnectedException, InterruptedException {
// build In-Band Bytestream request // build In-Band Bytestream request
InBandBytestreamRequest request = new ByteStreamRequest(this.manager, InBandBytestreamRequest request = new ByteStreamRequest(this.manager,

View File

@ -126,6 +126,7 @@ public class IncomingFileTransfer extends FileTransfer {
} }
Thread transferThread = new Thread(new Runnable() { Thread transferThread = new Thread(new Runnable() {
@Override
public void run() { public void run() {
try { try {
inputStream = negotiateStream(); inputStream = negotiateStream();
@ -184,6 +185,7 @@ public class IncomingFileTransfer extends FileTransfer {
FutureTask<InputStream> streamNegotiatorTask = new FutureTask<InputStream>( FutureTask<InputStream> streamNegotiatorTask = new FutureTask<InputStream>(
new Callable<InputStream>() { new Callable<InputStream>() {
@Override
public InputStream call() throws Exception { public InputStream call() throws Exception {
return streamNegotiator return streamNegotiator
.createIncomingStream(recieveRequest.getStreamInitiation()); .createIncomingStream(recieveRequest.getStreamInitiation());
@ -220,6 +222,7 @@ public class IncomingFileTransfer extends FileTransfer {
return inputStream; return inputStream;
} }
@Override
public void cancel() { public void cancel() {
setStatus(Status.cancelled); setStatus(Status.cancelled);
} }

View File

@ -174,6 +174,7 @@ public class OutgoingFileTransfer extends FileTransfer {
setFileInfo(fileName, fileSize); setFileInfo(fileName, fileSize);
this.callback = progress; this.callback = progress;
transferThread = new Thread(new Runnable() { transferThread = new Thread(new Runnable() {
@Override
public void run() { public void run() {
try { try {
OutgoingFileTransfer.this.outputStream = negotiateStream( OutgoingFileTransfer.this.outputStream = negotiateStream(
@ -192,7 +193,7 @@ public class OutgoingFileTransfer extends FileTransfer {
} }
private void checkTransferThread() { private void checkTransferThread() {
if (transferThread != null && transferThread.isAlive() || isDone()) { if ((transferThread != null && transferThread.isAlive()) || isDone()) {
throw new IllegalStateException( throw new IllegalStateException(
"File transfer in progress or has already completed."); "File transfer in progress or has already completed.");
} }
@ -225,6 +226,7 @@ public class OutgoingFileTransfer extends FileTransfer {
} }
transferThread = new Thread(new Runnable() { transferThread = new Thread(new Runnable() {
@Override
public void run() { public void run() {
try { try {
outputStream = negotiateStream(file.getName(), file outputStream = negotiateStream(file.getName(), file
@ -298,6 +300,7 @@ public class OutgoingFileTransfer extends FileTransfer {
setFileInfo(fileName, fileSize); setFileInfo(fileName, fileSize);
transferThread = new Thread(new Runnable() { transferThread = new Thread(new Runnable() {
@Override
public void run() { public void run() {
//Create packet filter //Create packet filter
try { try {
@ -398,6 +401,7 @@ public class OutgoingFileTransfer extends FileTransfer {
return outputStream; return outputStream;
} }
@Override
public void cancel() { public void cancel() {
setStatus(Status.cancelled); setStatus(Status.cancelled);
} }

View File

@ -34,6 +34,7 @@ public final class GeoLocationManager extends Manager {
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
getInstanceFor(connection); getInstanceFor(connection);
} }

View File

@ -108,6 +108,7 @@ public final class LastActivityManager extends Manager {
// Enable the LastActivity support on every established connection // Enable the LastActivity support on every established connection
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
LastActivityManager.getInstanceFor(connection); LastActivityManager.getInstanceFor(connection);
} }
@ -135,6 +136,7 @@ public final class LastActivityManager extends Manager {
// Listen to all the sent messages to reset the idle time on each one // Listen to all the sent messages to reset the idle time on each one
connection.addPacketSendingListener(new StanzaListener() { connection.addPacketSendingListener(new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
Presence presence = (Presence) packet; Presence presence = (Presence) packet;
Presence.Mode mode = presence.getMode(); Presence.Mode mode = presence.getMode();

View File

@ -66,6 +66,7 @@ public class DefaultPrivateData implements PrivateData {
* *
* @return the XML element name of the stanza(/packet) extension. * @return the XML element name of the stanza(/packet) extension.
*/ */
@Override
public String getElementName() { public String getElementName() {
return elementName; return elementName;
} }
@ -75,10 +76,12 @@ public class DefaultPrivateData implements PrivateData {
* *
* @return the XML namespace of the stanza(/packet) extension. * @return the XML namespace of the stanza(/packet) extension.
*/ */
@Override
public String getNamespace() { public String getNamespace() {
return namespace; return namespace;
} }
@Override
public String toXML() { public String toXML() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append('<').append(elementName).append(" xmlns=\"").append(namespace).append("\">"); buf.append('<').append(elementName).append(" xmlns=\"").append(namespace).append("\">");

View File

@ -71,6 +71,7 @@ public final class VersionManager extends Manager {
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) { public void connectionCreated(XMPPConnection connection) {
VersionManager.getInstanceFor(connection); VersionManager.getInstanceFor(connection);
} }

View File

@ -32,48 +32,63 @@ import org.jxmpp.jid.parts.Resourcepart;
*/ */
public class DefaultParticipantStatusListener implements ParticipantStatusListener { public class DefaultParticipantStatusListener implements ParticipantStatusListener {
@Override
public void joined(EntityFullJid participant) { public void joined(EntityFullJid participant) {
} }
@Override
public void left(EntityFullJid participant) { public void left(EntityFullJid participant) {
} }
@Override
public void kicked(EntityFullJid participant, Jid actor, String reason) { public void kicked(EntityFullJid participant, Jid actor, String reason) {
} }
@Override
public void voiceGranted(EntityFullJid participant) { public void voiceGranted(EntityFullJid participant) {
} }
@Override
public void voiceRevoked(EntityFullJid participant) { public void voiceRevoked(EntityFullJid participant) {
} }
@Override
public void banned(EntityFullJid participant, Jid actor, String reason) { public void banned(EntityFullJid participant, Jid actor, String reason) {
} }
@Override
public void membershipGranted(EntityFullJid participant) { public void membershipGranted(EntityFullJid participant) {
} }
@Override
public void membershipRevoked(EntityFullJid participant) { public void membershipRevoked(EntityFullJid participant) {
} }
@Override
public void moderatorGranted(EntityFullJid participant) { public void moderatorGranted(EntityFullJid participant) {
} }
@Override
public void moderatorRevoked(EntityFullJid participant) { public void moderatorRevoked(EntityFullJid participant) {
} }
@Override
public void ownershipGranted(EntityFullJid participant) { public void ownershipGranted(EntityFullJid participant) {
} }
@Override
public void ownershipRevoked(EntityFullJid participant) { public void ownershipRevoked(EntityFullJid participant) {
} }
@Override
public void adminGranted(EntityFullJid participant) { public void adminGranted(EntityFullJid participant) {
} }
@Override
public void adminRevoked(EntityFullJid participant) { public void adminRevoked(EntityFullJid participant) {
} }
@Override
public void nicknameChanged(EntityFullJid participant, Resourcepart newNickname) { public void nicknameChanged(EntityFullJid participant, Resourcepart newNickname) {
} }

View File

@ -30,42 +30,55 @@ import org.jxmpp.jid.Jid;
*/ */
public class DefaultUserStatusListener implements UserStatusListener { public class DefaultUserStatusListener implements UserStatusListener {
@Override
public void kicked(Jid actor, String reason) { public void kicked(Jid actor, String reason) {
} }
@Override
public void voiceGranted() { public void voiceGranted() {
} }
@Override
public void voiceRevoked() { public void voiceRevoked() {
} }
@Override
public void banned(Jid actor, String reason) { public void banned(Jid actor, String reason) {
} }
@Override
public void membershipGranted() { public void membershipGranted() {
} }
@Override
public void membershipRevoked() { public void membershipRevoked() {
} }
@Override
public void moderatorGranted() { public void moderatorGranted() {
} }
@Override
public void moderatorRevoked() { public void moderatorRevoked() {
} }
@Override
public void ownershipGranted() { public void ownershipGranted() {
} }
@Override
public void ownershipRevoked() { public void ownershipRevoked() {
} }
@Override
public void adminGranted() { public void adminGranted() {
} }
@Override
public void adminRevoked() { public void adminRevoked() {
} }
@Override
public void roomDestroyed(MultiUserChat alternateMUC, String reason) { public void roomDestroyed(MultiUserChat alternateMUC, String reason) {
} }

View File

@ -163,6 +163,7 @@ public class MultiUserChat {
// Create a listener for subject updates. // Create a listener for subject updates.
subjectListener = new StanzaListener() { subjectListener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
Message msg = (Message) packet; Message msg = (Message) packet;
EntityFullJid from = msg.getFrom().asEntityFullJidIfPossible(); EntityFullJid from = msg.getFrom().asEntityFullJidIfPossible();
@ -181,6 +182,7 @@ public class MultiUserChat {
// Create a listener for all presence updates. // Create a listener for all presence updates.
presenceListener = new StanzaListener() { presenceListener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
Presence presence = (Presence) packet; Presence presence = (Presence) packet;
final EntityFullJid from = presence.getFrom().asEntityFullJidIfPossible(); final EntityFullJid from = presence.getFrom().asEntityFullJidIfPossible();
@ -251,6 +253,7 @@ public class MultiUserChat {
// Listens for all messages that include a MUCUser extension and fire the invitation // Listens for all messages that include a MUCUser extension and fire the invitation
// rejection listeners if the message includes an invitation rejection. // rejection listeners if the message includes an invitation rejection.
declinesListener = new StanzaListener() { declinesListener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
Message message = (Message) packet; Message message = (Message) packet;
// Get the MUC User extension // Get the MUC User extension

View File

@ -82,6 +82,7 @@ public final class MultiUserChatManager extends Manager {
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(final XMPPConnection connection) { public void connectionCreated(final XMPPConnection connection) {
// Set on every established connection that this client supports the Multi-User // Set on every established connection that this client supports the Multi-User
// Chat protocol. This information will be used when another client tries to // Chat protocol. This information will be used when another client tries to
@ -149,6 +150,7 @@ public final class MultiUserChatManager extends Manager {
// Listens for all messages that include a MUCUser extension and fire the invitation // Listens for all messages that include a MUCUser extension and fire the invitation
// listeners if the message includes an invitation. // listeners if the message includes an invitation.
StanzaListener invitationPacketListener = new StanzaListener() { StanzaListener invitationPacketListener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
final Message message = (Message) packet; final Message message = (Message) packet;
// Get the MUCUser extension // Get the MUCUser extension

View File

@ -110,6 +110,7 @@ public class Occupant {
return nick; return nick;
} }
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(!(obj instanceof Occupant)) { if(!(obj instanceof Occupant)) {
return false; return false;
@ -118,6 +119,7 @@ public class Occupant {
return jid.equals(occupant.jid); return jid.equals(occupant.jid);
} }
@Override
public int hashCode() { public int hashCode() {
int result; int result;
result = affiliation.hashCode(); result = affiliation.hashCode();

View File

@ -92,10 +92,12 @@ public class GroupChatInvitation implements ExtensionElement {
return roomAddress; return roomAddress;
} }
@Override
public String getElementName() { public String getElementName() {
return ELEMENT; return ELEMENT;
} }
@Override
public String getNamespace() { public String getNamespace() {
return NAMESPACE; return NAMESPACE;
} }

View File

@ -72,10 +72,12 @@ public class MUCInitialPresence implements ExtensionElement {
} }
} }
@Override
public String getElementName() { public String getElementName() {
return ELEMENT; return ELEMENT;
} }
@Override
public String getNamespace() { public String getNamespace() {
return NAMESPACE; return NAMESPACE;
} }
@ -282,6 +284,7 @@ public class MUCInitialPresence implements ExtensionElement {
this.since = since; this.since = since;
} }
@Override
public XmlStringBuilder toXML() { public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this); XmlStringBuilder xml = new XmlStringBuilder(this);
xml.optIntAttribute("maxchars", getMaxChars()); xml.optIntAttribute("maxchars", getMaxChars());

View File

@ -158,6 +158,7 @@ public class MUCItem implements NamedElement {
return role; return role;
} }
@Override
public XmlStringBuilder toXML() { public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this); XmlStringBuilder xml = new XmlStringBuilder(this);
xml.optAttribute("affiliation", getAffiliation()); xml.optAttribute("affiliation", getAffiliation());

View File

@ -50,10 +50,12 @@ public class MUCUser implements ExtensionElement {
private String password; private String password;
private Destroy destroy; private Destroy destroy;
@Override
public String getElementName() { public String getElementName() {
return ELEMENT; return ELEMENT;
} }
@Override
public String getNamespace() { public String getNamespace() {
return NAMESPACE; return NAMESPACE;
} }

View File

@ -65,6 +65,7 @@ public class Nick implements ExtensionElement {
* *
* @see org.jivesoftware.smack.packet.PacketExtension#getElementName() * @see org.jivesoftware.smack.packet.PacketExtension#getElementName()
*/ */
@Override
public String getElementName() { public String getElementName() {
return ELEMENT_NAME; return ELEMENT_NAME;
} }
@ -74,6 +75,7 @@ public class Nick implements ExtensionElement {
* *
* @see org.jivesoftware.smack.packet.PacketExtension#getNamespace() * @see org.jivesoftware.smack.packet.PacketExtension#getNamespace()
*/ */
@Override
public String getNamespace() { public String getNamespace() {
return NAMESPACE; return NAMESPACE;
} }
@ -83,6 +85,7 @@ public class Nick implements ExtensionElement {
* *
* @see org.jivesoftware.smack.packet.PacketExtension#toXML() * @see org.jivesoftware.smack.packet.PacketExtension#toXML()
*/ */
@Override
public String toXML() { public String toXML() {
final StringBuilder buf = new StringBuilder(); final StringBuilder buf = new StringBuilder();

Some files were not shown because too many files have changed in this diff Show More