Browse Source

Enfore spaces for indentation

Although I'm in the tabs camp, Smack uses mostly spaces. Therefore it
is the logical choice for the indentation style.
omemo-legacy
Florian Schmaus 4 years ago
parent
commit
ef0af66b21
  1. 8
      config/checkstyle.xml
  2. 180
      smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java
  3. 16
      smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java
  4. 8
      smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java
  5. 336
      smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java
  6. 2
      smack-core/src/test/java/org/jivesoftware/smack/util/SHA1Test.java
  7. 10
      smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java
  8. 2
      smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java
  9. 2
      smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java
  10. 2
      smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java
  11. 502
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java
  12. 14
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferListener.java
  13. 178
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java
  14. 194
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java
  15. 580
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java
  16. 2
      smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/provider/RegistrationProvider.java
  17. 136
      smack-extensions/src/main/java/org/jivesoftware/smackx/nick/packet/Nick.java
  18. 278
      smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java
  19. 154
      smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/Privacy.java
  20. 40
      smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/provider/PrivacyProvider.java
  21. 20
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AccessModel.java
  22. 22
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java
  23. 34
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AffiliationsExtension.java
  24. 12
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ChildrenAssociationPolicy.java
  25. 8
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/CollectionNode.java
  26. 42
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigurationEvent.java
  27. 1330
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java
  28. 378
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureNodeFields.java
  29. 12
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EmbeddedPacketExtension.java
  30. 54
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java
  31. 24
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElementType.java
  32. 126
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNode.java
  33. 50
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNodeType.java
  34. 50
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/GetItemsRequest.java
  35. 142
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java
  36. 64
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemDeleteEvent.java
  37. 170
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemPublishEvent.java
  38. 8
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemReply.java
  39. 326
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java
  40. 588
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java
  41. 914
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
  42. 18
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeEvent.java
  43. 100
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeExtension.java
  44. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeType.java
  45. 48
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/OptionsExtension.java
  46. 154
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java
  47. 2
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PresenceState.java
  48. 94
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubElementType.java
  49. 448
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
  50. 78
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishItem.java
  51. 12
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishModel.java
  52. 56
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/RetractItem.java
  53. 70
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SimplePayload.java
  54. 62
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeExtension.java
  55. 396
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java
  56. 126
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeOptionFields.java
  57. 272
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java
  58. 88
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionEvent.java
  59. 122
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionsExtension.java
  60. 48
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/UnsubscribeExtension.java
  61. 24
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemDeleteListener.java
  62. 14
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemEventListener.java
  63. 14
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/NodeConfigListener.java
  64. 12
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java
  65. 52
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSubNamespace.java
  66. 10
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/AffiliationsProvider.java
  67. 16
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ConfigEventProvider.java
  68. 12
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/EventProvider.java
  69. 8
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/FormNodeProvider.java
  70. 8
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ItemsProvider.java
  71. 2
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/PubSubProvider.java
  72. 10
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/RetractEventProvider.java
  73. 8
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SimpleNodeProvider.java
  74. 40
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java
  75. 12
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionsProvider.java
  76. 26
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java
  77. 10
      smack-extensions/src/main/java/org/jivesoftware/smackx/si/packet/StreamInitiation.java
  78. 106
      smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java
  79. 88
      smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java
  80. 116
      smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ItemValidationTest.java
  81. 2
      smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java
  82. 2
      smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntries.java
  83. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleException.java
  84. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java
  85. 10
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleNegotiator.java
  86. 34
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java
  87. 22
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java
  88. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionStateEnded.java
  89. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/media/MediaNegotiator.java
  90. 6
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/JMFInit.java
  91. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioChannel.java
  92. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioMediaSession.java
  93. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioReceiver.java
  94. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/JmfMediaManager.java
  95. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/AudioMediaSession.java
  96. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/SpeexMediaManager.java
  97. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/ScreenShareSession.java
  98. 52
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/AbstractBufferedImageOp.java
  99. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageReceiver.java
  100. 4
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageTransmitter.java

8
config/checkstyle.xml

@ -35,10 +35,6 @@
<property name="format" value="^\s+$"/>
<property name="message" value="Line containing only whitespace character(s)"/>
</module>
<module name="RegexpSingleline">
<property name="format" value="^ +\t+"/>
<property name="message" value="Line containing tab(s) after space"/>
</module>
<module name="RegexpSingleline">
<!-- We use {2,} instead of + here to address the typical case where a file was written
with tabs but javadoc is causing '\t *' -->
@ -89,6 +85,10 @@
<property name="message" value="Usage of println"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="^\t+"/>
<property name="message" value="Indent must not use tab characters. Use space instead."/>
</module>
<module name="JavadocMethod">
<!-- TODO stricten those checks -->
<property name="scope" value="public"/>

180
smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -63,116 +63,116 @@ import android.os.SystemClock;
*/
public final class ServerPingWithAlarmManager extends Manager {
private static final Logger LOGGER = Logger.getLogger(ServerPingWithAlarmManager.class
.getName());
private static final Logger LOGGER = Logger.getLogger(ServerPingWithAlarmManager.class
.getName());
private static final String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION";
private static final String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION";
private static final Map<XMPPConnection, ServerPingWithAlarmManager> INSTANCES = new WeakHashMap<XMPPConnection, ServerPingWithAlarmManager>();
private static final Map<XMPPConnection, ServerPingWithAlarmManager> INSTANCES = new WeakHashMap<XMPPConnection, ServerPingWithAlarmManager>();
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) {
getInstanceFor(connection);
}
});
}
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) {
getInstanceFor(connection);
}
});
}
public static synchronized ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection) {
ServerPingWithAlarmManager serverPingWithAlarmManager = INSTANCES.get(connection);
if (serverPingWithAlarmManager == null) {
serverPingWithAlarmManager = new ServerPingWithAlarmManager(connection);
INSTANCES.put(connection, serverPingWithAlarmManager);
}
return serverPingWithAlarmManager;
}
public static synchronized ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection) {
ServerPingWithAlarmManager serverPingWithAlarmManager = INSTANCES.get(connection);
if (serverPingWithAlarmManager == null) {
serverPingWithAlarmManager = new ServerPingWithAlarmManager(connection);
INSTANCES.put(connection, serverPingWithAlarmManager);
}
return serverPingWithAlarmManager;
}
private boolean mEnabled = true;
private boolean mEnabled = true;
private ServerPingWithAlarmManager(XMPPConnection connection) {
super(connection);
}
private ServerPingWithAlarmManager(XMPPConnection connection) {
super(connection);
}
/**
* If enabled, ServerPingWithAlarmManager will call {@link PingManager#pingServerIfNecessary()}
* for the connection of this instance every half hour.
*
*
* @param enabled
*/
public void setEnabled(boolean enabled) {
mEnabled = enabled;
}
public boolean isEnabled() {
return mEnabled;
}
private static final BroadcastReceiver ALARM_BROADCAST_RECEIVER = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
LOGGER.fine("Ping Alarm broadcast received");
Set<Entry<XMPPConnection, ServerPingWithAlarmManager>> managers;
synchronized (ServerPingWithAlarmManager.class) {
// Make a copy to avoid ConcurrentModificationException when
// iterating directly over INSTANCES and the Set is modified
// concurrently by creating a new ServerPingWithAlarmManager.
managers = new HashSet<>(INSTANCES.entrySet());
}
for (Entry<XMPPConnection, ServerPingWithAlarmManager> entry : managers) {
XMPPConnection connection = entry.getKey();
if (entry.getValue().isEnabled()) {
LOGGER.fine("Calling pingServerIfNecessary for connection "
+ connection);
final PingManager pingManager = PingManager.getInstanceFor(connection);
// Android BroadcastReceivers have a timeout of 60 seconds.
// The connections reply timeout may be higher, which causes
// timeouts of the broadcast receiver and a subsequent ANR
// of the App of the broadcast receiver. We therefore need
// to call pingServerIfNecessary() in a new thread to avoid
// this. It could happen that the device gets back to sleep
// until the Thread runs, but that's a risk we are willing
// to take into account as it's unlikely.
Async.go(new Runnable() {
@Override
public void run() {
pingManager.pingServerIfNecessary();
}
}, "PingServerIfNecessary (" + connection.getConnectionCounter() + ')');
} else {
LOGGER.fine("NOT calling pingServerIfNecessary (disabled) on connection "
+ connection.getConnectionCounter());
}
}
}
};
private static Context sContext;
private static PendingIntent sPendingIntent;
private static AlarmManager sAlarmManager;
public void setEnabled(boolean enabled) {
mEnabled = enabled;
}
public boolean isEnabled() {
return mEnabled;
}
private static final BroadcastReceiver ALARM_BROADCAST_RECEIVER = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
LOGGER.fine("Ping Alarm broadcast received");
Set<Entry<XMPPConnection, ServerPingWithAlarmManager>> managers;
synchronized (ServerPingWithAlarmManager.class) {
// Make a copy to avoid ConcurrentModificationException when
// iterating directly over INSTANCES and the Set is modified
// concurrently by creating a new ServerPingWithAlarmManager.
managers = new HashSet<>(INSTANCES.entrySet());
}
for (Entry<XMPPConnection, ServerPingWithAlarmManager> entry : managers) {
XMPPConnection connection = entry.getKey();
if (entry.getValue().isEnabled()) {
LOGGER.fine("Calling pingServerIfNecessary for connection "
+ connection);
final PingManager pingManager = PingManager.getInstanceFor(connection);
// Android BroadcastReceivers have a timeout of 60 seconds.
// The connections reply timeout may be higher, which causes
// timeouts of the broadcast receiver and a subsequent ANR
// of the App of the broadcast receiver. We therefore need
// to call pingServerIfNecessary() in a new thread to avoid
// this. It could happen that the device gets back to sleep
// until the Thread runs, but that's a risk we are willing
// to take into account as it's unlikely.
Async.go(new Runnable() {
@Override
public void run() {
pingManager.pingServerIfNecessary();
}
}, "PingServerIfNecessary (" + connection.getConnectionCounter() + ')');
} else {
LOGGER.fine("NOT calling pingServerIfNecessary (disabled) on connection "
+ connection.getConnectionCounter());
}
}
}
};
private static Context sContext;
private static PendingIntent sPendingIntent;
private static AlarmManager sAlarmManager;
/**
* Register a pending intent with the AlarmManager to be broadcasted every half hour and
* register the alarm broadcast receiver to receive this intent. The receiver will check all
* known questions if a ping is Necessary when invoked by the alarm intent.
*
*
* @param context
*/
public static void onCreate(Context context) {
sContext = context;
context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION));
sAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
sPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(PING_ALARM_ACTION), 0);
sAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR,
AlarmManager.INTERVAL_HALF_HOUR, sPendingIntent);
}
public static void onCreate(Context context) {
sContext = context;
context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION));
sAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
sPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(PING_ALARM_ACTION), 0);
sAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR,
AlarmManager.INTERVAL_HALF_HOUR, sPendingIntent);
}
/**
* Unregister the alarm broadcast receiver and cancel the alarm.
*/
public static void onDestroy() {
sContext.unregisterReceiver(ALARM_BROADCAST_RECEIVER);
sAlarmManager.cancel(sPendingIntent);
}
public static void onDestroy() {
sContext.unregisterReceiver(ALARM_BROADCAST_RECEIVER);
sAlarmManager.cancel(sPendingIntent);
}
}

16
smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,12 +28,12 @@ import org.jivesoftware.smack.util.stringencoder.android.AndroidBase64UrlSafeEnc
public class AndroidSmackInitializer implements SmackInitializer {
@Override
public List<Exception> initialize() {
SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier());
Base64.setEncoder(AndroidBase64Encoder.getInstance());
Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance());
return null;
}
@Override
public List<Exception> initialize() {
SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier());
Base64.setEncoder(AndroidBase64Encoder.getInstance());
Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance());
return null;
}
}

8
smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java

@ -35,12 +35,12 @@ public final class IQTypeFilter extends FlexibleStanzaTypeFilter<IQ> {
public static final StanzaFilter ERROR = new IQTypeFilter(Type.error);
public static final StanzaFilter GET_OR_SET = new OrFilter(GET, SET);
private final IQ.Type type;
private final IQ.Type type;
private IQTypeFilter(IQ.Type type) {
private IQTypeFilter(IQ.Type type) {
super(IQ.class);
this.type = Objects.requireNonNull(type, "Type must not be null");
}
this.type = Objects.requireNonNull(type, "Type must not be null");
}
@Override
protected boolean acceptSpecific(IQ iq) {

336
smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java

@ -26,190 +26,190 @@ import org.junit.Test;
public class StanzaCollectorTest
{
@Test
public void verifyRollover() throws InterruptedException
{
TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5);
for (int i=0; i<6; i++)
{
Stanza testPacket = new TestPacket(i);
collector.processStanza(testPacket);
}
// Assert that '0' has rolled off
assertEquals("1", collector.nextResultBlockForever().getStanzaId());
assertEquals("2", collector.nextResultBlockForever().getStanzaId());
assertEquals("3", collector.nextResultBlockForever().getStanzaId());
assertEquals("4", collector.nextResultBlockForever().getStanzaId());
assertEquals("5", collector.pollResult().getStanzaId());
assertNull(collector.pollResult());
for (int i=10; i<15; i++)
{
Stanza testPacket = new TestPacket(i);
collector.processStanza(testPacket);
}
assertEquals("10", collector.nextResultBlockForever().getStanzaId());
assertEquals("11", collector.nextResultBlockForever().getStanzaId());
assertEquals("12", collector.nextResultBlockForever().getStanzaId());
assertEquals("13", collector.nextResultBlockForever().getStanzaId());
assertEquals("14", collector.pollResult().getStanzaId());
assertNull(collector.pollResult());
assertNull(collector.nextResult(1000));
}
@Test
public void verifyRollover() throws InterruptedException
{
TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5);
for (int i=0; i<6; i++)
{
Stanza testPacket = new TestPacket(i);
collector.processStanza(testPacket);
}
// Assert that '0' has rolled off
assertEquals("1", collector.nextResultBlockForever().getStanzaId());
assertEquals("2", collector.nextResultBlockForever().getStanzaId());
assertEquals("3", collector.nextResultBlockForever().getStanzaId());
assertEquals("4", collector.nextResultBlockForever().getStanzaId());
assertEquals("5", collector.pollResult().getStanzaId());
assertNull(collector.pollResult());
for (int i=10; i<15; i++)
{
Stanza testPacket = new TestPacket(i);
collector.processStanza(testPacket);
}
assertEquals("10", collector.nextResultBlockForever().getStanzaId());
assertEquals("11", collector.nextResultBlockForever().getStanzaId());
assertEquals("12", collector.nextResultBlockForever().getStanzaId());
assertEquals("13", collector.nextResultBlockForever().getStanzaId());
assertEquals("14", collector.pollResult().getStanzaId());
assertNull(collector.pollResult());
assertNull(collector.nextResult(1000));
}
/**
* Although this doesn't guarentee anything due to the nature of threading, it can potentially
* catch problems.
*/
@Test
public void verifyThreadSafety()
{
int insertCount = 500;
final TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), insertCount);
Thread consumer1 = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
while (true)
{
try
{
Thread.sleep(3);
}
catch (InterruptedException e)
{
}
@SuppressWarnings("unused")
Stanza packet = collector.nextResultBlockForever();
// System.out.println(Thread.currentThread().getName() + " packet: " + packet);
}
}
@Test
public void verifyThreadSafety()
{
int insertCount = 500;
final TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), insertCount);
Thread consumer1 = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
while (true)
{
try
{
Thread.sleep(3);
}
catch (InterruptedException e)
{
}
@SuppressWarnings("unused")
Stanza packet = collector.nextResultBlockForever();
// System.out.println(Thread.currentThread().getName() + " packet: " + packet);
}
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
consumer1.setName("consumer 1");
Thread consumer2 = new Thread(new Runnable()
{
@Override
public void run()
{
Stanza p = null;
do
{
try
{
Thread.sleep(3);
}
catch (InterruptedException e)
{
}
try {
}
});
consumer1.setName("consumer 1");
Thread consumer2 = new Thread(new Runnable()
{
@Override
public void run()
{
Stanza p = null;
do
{
try
{
Thread.sleep(3);
}
catch (InterruptedException e)
{
}
try {
p = collector.nextResult(1);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
// System.out.println(Thread.currentThread().getName() + " packet: " + p);
}
while (p != null);
}
});
consumer2.setName("consumer 2");
Thread consumer3 = new Thread(new Runnable()
{
@Override
public void run()
{
Stanza p = null;
do
{
try
{
Thread.sleep(3);
}
catch (InterruptedException e)
{
}
p = collector.pollResult();
// System.out.println(Thread.currentThread().getName() + " packet: " + p);
}
while (p != null);
}
});
consumer3.setName("consumer 3");
consumer1.start();
consumer2.start();
consumer3.start();
for(int i=0; i<insertCount; i++)
{
collector.processStanza(new TestPacket(i));
}
try
{
Thread.sleep(5000);
consumer3.join();
consumer2.join();
consumer1.interrupt();
}
catch (InterruptedException e)
{
}
//We cannot guarantee that this is going to pass due to the possible issue of timing between consumer 1
// and main, but the probability is extremely remote.
assertNull(collector.pollResult());
}
class OKEverything implements StanzaFilter
{
@Override
public boolean accept(Stanza packet)
{
return true;
}
}
class TestStanzaCollector extends StanzaCollector
{
protected TestStanzaCollector(XMPPConnection conection, StanzaFilter packetFilter, int size)
{
super(conection, StanzaCollector.newConfiguration().setStanzaFilter(packetFilter).setSize(size));
}
}
class TestPacket extends Stanza
{
public TestPacket(int i)
{
setStanzaId(String.valueOf(i));
}
@Override
public String toXML()
{
return "<packetId>" + getStanzaId() + "</packetId>";
}
// System.out.println(Thread.currentThread().getName() + " packet: " + p);
}
while (p != null);
}
});
consumer2.setName("consumer 2");
Thread consumer3 = new Thread(new Runnable()
{
@Override
public void run()
{
Stanza p = null;
do
{
try
{
Thread.sleep(3);
}
catch (InterruptedException e)
{
}
p = collector.pollResult();
// System.out.println(Thread.currentThread().getName() + " packet: " + p);
}
while (p != null);
}
});
consumer3.setName("consumer 3");
consumer1.start();
consumer2.start();
consumer3.start();
for(int i=0; i<insertCount; i++)
{
collector.processStanza(new TestPacket(i));
}
try
{
Thread.sleep(5000);
consumer3.join();
consumer2.join();
consumer1.interrupt();
}
catch (InterruptedException e)
{
}
//We cannot guarantee that this is going to pass due to the possible issue of timing between consumer 1
// and main, but the probability is extremely remote.
assertNull(collector.pollResult());
}
class OKEverything implements StanzaFilter
{
@Override
public boolean accept(Stanza packet)
{
return true;
}
}
class TestStanzaCollector extends StanzaCollector
{
protected TestStanzaCollector(XMPPConnection conection, StanzaFilter packetFilter, int size)
{
super(conection, StanzaCollector.newConfiguration().setStanzaFilter(packetFilter).setSize(size));
}
}
class TestPacket extends Stanza
{
public TestPacket(int i)
{
setStanzaId(String.valueOf(i));
}
@Override
public String toXML()
{
return "<packetId>" + getStanzaId() + "</packetId>";
}
@Override
public String toString() {
return toXML();
}
}
}
}

2
smack-core/src/test/java/org/jivesoftware/smack/util/SHA1Test.java

@ -28,7 +28,7 @@ import org.junit.Test;
*/
public class SHA1Test {
@Test
@Test
public void testHash() {
// Test null
// @TODO - should the StringUtils.hash(String) method be fixed to handle null input?

10
smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java

@ -27,7 +27,7 @@ import org.junit.Test;
* A test case for the StringUtils class.
*/
public class StringUtilsTest {
@Test
@Test
public void testEscapeForXml() {
String input = null;
@ -67,11 +67,11 @@ public class StringUtilsTest {
assertCharSequenceEquals("It&apos;s a good day today", StringUtils.escapeForXml(input));
}
public static void assertCharSequenceEquals(CharSequence expected, CharSequence actual) {
public static void assertCharSequenceEquals(CharSequence expected, CharSequence actual) {
assertEquals(expected.toString(), actual.toString());
}
}
@Test
@Test
public void testEncodeHex() {
String input = "";
String output = "";
@ -84,7 +84,7 @@ public class StringUtilsTest {
new String(output.getBytes()));
}
@Test
@Test
public void testRandomString() {
// Boundary test
String result = StringUtils.randomString(-1);

2
smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java

@ -203,7 +203,7 @@ public final class EnhancedDebuggerWindow {
* a tab panel for each connection that is being debugged.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private void createDebug() {
private void createDebug() {
frame = new JFrame("Smack Debug Window");

2
smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java

@ -18,6 +18,6 @@ package org.jivesoftware.smackx.blocking;
public interface AllJidsUnblockedListener {
void onAllJidsUnblocked();
void onAllJidsUnblocked();
}

2
smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java

@ -22,6 +22,6 @@ import org.jxmpp.jid.Jid;
public interface JidsBlockedListener {
void onJidsBlocked(List<Jid> blockedJids);
void onJidsBlocked(List<Jid> blockedJids);
}

502
smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java

@ -31,27 +31,27 @@ import org.jxmpp.jid.Jid;
*/
public abstract class FileTransfer {
private String fileName;
private String fileName;
private String filePath;
private String filePath;
private long fileSize;
private long fileSize;
private Jid peer;
private Jid peer;
private Status status = Status.initial;
private Status status = Status.initial;
private final Object statusMonitor = new Object();
protected FileTransferNegotiator negotiator;
protected FileTransferNegotiator negotiator;
protected String streamID;
protected String streamID;
protected long amountWritten = -1;
protected long amountWritten = -1;
private Error error;
private Error error;
private Exception exception;
private Exception exception;
/**
* Buffer size between input and output
@ -59,137 +59,137 @@ public abstract class FileTransfer {
private static final int BUFFER_SIZE = 8192;
protected FileTransfer(Jid peer, String streamID,
FileTransferNegotiator negotiator) {
this.peer = peer;
this.streamID = streamID;
this.negotiator = negotiator;
}
protected void setFileInfo(String fileName, long fileSize) {
this.fileName = fileName;
this.fileSize = fileSize;
}
protected void setFileInfo(String path, String fileName, long fileSize) {
this.filePath = path;
this.fileName = fileName;
this.fileSize = fileSize;
}
/**
* Returns the size of the file being transfered.
*
* @return Returns the size of the file being transfered.
*/
public long getFileSize() {
return fileSize;
}
/**
* Returns the name of the file being transfered.
*
* @return Returns the name of the file being transfered.
*/
public String getFileName() {
return fileName;
}
/**
* Returns the local path of the file.
*
* @return Returns the local path of the file.
*/
public String getFilePath() {
return filePath;
}
/**
* Returns the JID of the peer for this file transfer.
*
* @return Returns the JID of the peer for this file transfer.
*/
public Jid getPeer() {
return peer;
}
/**
* Returns the progress of the file transfer as a number between 0 and 1.
*
* @return Returns the progress of the file transfer as a number between 0
* and 1.
*/
public double getProgress() {
FileTransferNegotiator negotiator) {
this.peer = peer;
this.streamID = streamID;
this.negotiator = negotiator;
}
protected void setFileInfo(String fileName, long fileSize) {
this.fileName = fileName;
this.fileSize = fileSize;
}
protected void setFileInfo(String path, String fileName, long fileSize) {
this.filePath = path;
this.fileName = fileName;
this.fileSize = fileSize;
}
/**
* Returns the size of the file being transfered.
*
* @return Returns the size of the file being transfered.
*/
public long getFileSize() {
return fileSize;
}
/**
* Returns the name of the file being transfered.
*
* @return Returns the name of the file being transfered.
*/
public String getFileName() {
return fileName;
}
/**
* Returns the local path of the file.
*
* @return Returns the local path of the file.
*/
public String getFilePath() {
return filePath;
}
/**
* Returns the JID of the peer for this file transfer.
*
* @return Returns the JID of the peer for this file transfer.
*/
public Jid getPeer() {
return peer;
}
/**
* Returns the progress of the file transfer as a number between 0 and 1.
*
* @return Returns the progress of the file transfer as a number between 0
* and 1.
*/
public double getProgress() {
if (amountWritten <= 0 || fileSize <= 0) {
return 0;
}
return (double) amountWritten / (double) fileSize;
}
/**
* Returns true if the transfer has been cancelled, if it has stopped because
* of a an error, or the transfer completed successfully.
*
* @return Returns true if the transfer has been cancelled, if it has stopped
* because of a an error, or the transfer completed successfully.
*/
public boolean isDone() {
return status == Status.cancelled || status == Status.error
|| status == Status.complete || status == Status.refused;
}
/**
* Returns the current status of the file transfer.
*
* @return Returns the current status of the file transfer.
*/
public Status getStatus() {
return status;
}
protected void setError(Error type) {
this.error = type;
}
/**
* When {@link #getStatus()} returns that there was an {@link Status#error}
* during the transfer, the type of error can be retrieved through this
* method.
*
* @return Returns the type of error that occurred if one has occurred.
*/
public Error getError() {
return error;
}
/**
* If an exception occurs asynchronously it will be stored for later
* retrieval. If there is an error there maybe an exception set.
*
* @return The exception that occurred or null if there was no exception.
* @see #getError()
*/
public Exception getException() {
return exception;
}
}
/**
* Returns true if the transfer has been cancelled, if it has stopped because
* of a an error, or the transfer completed successfully.
*
* @return Returns true if the transfer has been cancelled, if it has stopped
* because of a an error, or the transfer completed successfully.
*/
public boolean isDone() {
return status == Status.cancelled || status == Status.error
|| status == Status.complete || status == Status.refused;
}
/**
* Returns the current status of the file transfer.
*
* @return Returns the current status of the file transfer.
*/
public Status getStatus() {
return status;
}
protected void setError(Error type) {
this.error = type;
}
/**
* When {@link #getStatus()} returns that there was an {@link Status#error}
* during the transfer, the type of error can be retrieved through this
* method.
*
* @return Returns the type of error that occurred if one has occurred.
*/
public Error getError() {
return error;
}
/**
* If an exception occurs asynchronously it will be stored for later
* retrieval. If there is an error there maybe an exception set.
*
* @return The exception that occurred or null if there was no exception.
* @see #getError()
*/
public Exception getException() {
return exception;
}
public String getStreamID() {
return streamID;
}
/**
* Cancels the file transfer.
*/
public abstract void cancel();
/**
* Cancels the file transfer.
*/
public abstract void cancel();
protected void setException(Exception exception) {
this.exception = exception;
}
protected void setException(Exception exception) {
this.exception = exception;
}
protected void setStatus(Status status) {
protected void setStatus(Status status) {
synchronized (statusMonitor) {
// CHECKSTYLE:OFF
this.status = status;
}
this.status = status;
}
// CHECKSTYLE:ON
}
@ -206,91 +206,91 @@ public abstract class FileTransfer {
protected void writeToStream(final InputStream in, final OutputStream out)
throws IOException
{
final byte[] b = new byte[BUFFER_SIZE];
int count = 0;
amountWritten = 0;
final byte[] b = new byte[BUFFER_SIZE];
int count = 0;
amountWritten = 0;
while ((count = in.read(b)) > 0 && !getStatus().equals(Status.cancelled)) {
out.write(b, 0, count);
amountWritten += count;
}
// the connection was likely terminated abruptly if these are not equal
if (!getStatus().equals(Status.cancelled) && getError() == Error.none
&& amountWritten != fileSize) {
// the connection was likely terminated abruptly if these are not equal
if (!getStatus().equals(Status.cancelled) && getError() == Error.none
&& amountWritten != fileSize) {
setStatus(Status.error);
this.error = Error.connection;
}
}
/**
* A class to represent the current status of the file transfer.
*
* @author Alexander Wenckus
*
*/
public enum Status {
/**
* An error occurred during the transfer.
*
* @see FileTransfer#getError()
*/
error("Error"),
/**
this.error = Error.connection;
}
}
/**
* A class to represent the current status of the file transfer.
*
* @author Alexander Wenckus
*
*/
public enum Status {
/**
* An error occurred during the transfer.
*
* @see FileTransfer#getError()
*/
error("Error"),
/**
* The initial status of the file transfer.
*/
initial("Initial"),
/**
* The file transfer is being negotiated with the peer. The party
* Receiving the file has the option to accept or refuse a file transfer
* request. If they accept, then the process of stream negotiation will
* begin. If they refuse the file will not be transfered.
*
* @see #negotiating_stream
*/
negotiating_transfer("Negotiating Transfer"),
/**
* The peer has refused the file transfer request halting the file
* transfer negotiation process.
*/
refused("Refused"),
/**
* The stream to transfer the file is being negotiated over the chosen
* stream type. After the stream negotiating process is complete the
* status becomes negotiated.
*
* @see #negotiated
*/
negotiating_stream("Negotiating Stream"),
/**
* After the stream negotiation has completed the intermediate state
* between the time when the negotiation is finished and the actual
* transfer begins.
*/
negotiated("Negotiated"),
/**
* The transfer is in progress.
*
* @see FileTransfer#getProgress()
*/
in_progress("In Progress"),
/**
* The transfer has completed successfully.
*/
complete("Complete"),
/**
* The file transfer was cancelled.
*/
cancelled("Cancelled");
* The file transfer is being negotiated with the peer. The party
* Receiving the file has the option to accept or refuse a file transfer
* request. If they accept, then the process of stream negotiation will
* begin. If they refuse the file will not be transfered.
*
* @see #negotiating_stream
*/
negotiating_transfer("Negotiating Transfer"),
/**
* The peer has refused the file transfer request halting the file
* transfer negotiation process.
*/
refused("Refused"),
/**
* The stream to transfer the file is being negotiated over the chosen
* stream type. After the stream negotiating process is complete the
* status becomes negotiated.
*
* @see #negotiated
*/
negotiating_stream("Negotiating Stream"),
/**
* After the stream negotiation has completed the intermediate state
* between the time when the negotiation is finished and the actual
* transfer begins.
*/
negotiated("Negotiated"),
/**
* The transfer is in progress.
*
* @see FileTransfer#getProgress()
*/
in_progress("In Progress"),
/**
* The transfer has completed successfully.
*/
complete("Complete"),
/**
* The file transfer was cancelled.
*/
cancelled("Cancelled");
private String status;
@ -312,55 +312,55 @@ public abstract class FileTransfer {
}
public enum Error {
/**
* No error.
*/
none("No error"),
/**
* The peer did not find any of the provided stream mechanisms
* acceptable.
*/
not_acceptable("The peer did not find any of the provided stream mechanisms acceptable."),
/**
* The provided file to transfer does not exist or could not be read.
*/
bad_file("The provided file to transfer does not exist or could not be read."),
/**
* The remote user did not respond or the connection timed out.
*/
no_response("The remote user did not respond or the connection timed out."),
/**
* An error occurred over the socket connected to send the file.
*/
connection("An error occured over the socket connected to send the file."),
/**
* An error occurred while sending or receiving the file.
*/
stream("An error occured while sending or recieving the file.");
private final String msg;
private Error(String msg) {
this.msg = msg;
}
/**
* Returns a String representation of this error.
*
* @return Returns a String representation of this error.
*/
public String getMessage() {
return msg;
}
public String toString() {
return msg;
}
}
/**
* No error.
*/
none("No error"),
/**
* The peer did not find any of the provided stream mechanisms
* acceptable.
*/
not_acceptable("The peer did not find any of the provided stream mechanisms acceptable."),
/**
* The provided file to transfer does not exist or could not be read.
*/
bad_file("The provided file to transfer does not exist or could not be read."),
/**
* The remote user did not respond or the connection timed out.
*/
no_response("The remote user did not respond or the connection timed out."),
/**
* An error occurred over the socket connected to send the file.
*/
connection("An error occured over the socket connected to send the file."),
/**
* An error occurred while sending or receiving the file.
*/
stream("An error occured while sending or recieving the file.");
private final String msg;
private Error(String msg) {
this.msg = msg;
}
/**
* Returns a String representation of this error.
*
* @return Returns a String representation of this error.
*/
public String getMessage() {
return msg;
}
public String toString() {
return msg;
}
}
}

14
smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferListener.java

@ -23,11 +23,11 @@ package org.jivesoftware.smackx.filetransfer;
* @author Alexander Wenckus
*/
public interface FileTransferListener {
/**
* A request to send a file has been recieved from another user.
*
* @param request
* The request from the other user.
*/
public void fileTransferRequest(final FileTransferRequest request);
/**
* A request to send a file has been recieved from another user.
*
* @param request
* The request from the other user.
*/
public void fileTransferRequest(final FileTransferRequest request);
}

178
smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java

@ -56,20 +56,20 @@ public final class FileTransferManager extends Manager {
return fileTransferManager;
}
private final FileTransferNegotiator fileTransferNegotiator;
private final List<FileTransferListener> listeners = new CopyOnWriteArrayList<FileTransferListener>();
/**
* Creates a file transfer manager to initiate and receive file transfers.
*
* @param connection
* The XMPPConnection that the file transfers will use.
*/
private FileTransferManager(XMPPConnection connection) {
super(connection);
this.fileTransferNegotiator = FileTransferNegotiator
.getInstanceFor(connection);
private final FileTransferNegotiator fileTransferNegotiator;
private final List<FileTransferListener> listeners = new CopyOnWriteArrayList<FileTransferListener>();
/**
* Creates a file transfer manager to initiate and receive file transfers.
*
* @param connection
* The XMPPConnection that the file transfers will use.
*/
private FileTransferManager(XMPPConnection connection) {
super(connection);
this.fileTransferNegotiator = FileTransferNegotiator
.getInstanceFor(connection);
connection.registerIQRequestHandler(new AbstractIqRequestHandler(StreamInitiation.ELEMENT,
StreamInitiation.NAMESPACE, IQ.Type.set, Mode.async) {
@Override
@ -82,42 +82,42 @@ public final class FileTransferManager extends Manager {
return null;
}
});
}
/**
* Add a file transfer listener to listen to incoming file transfer
* requests.
*
* @param li
* The listener
* @see #removeFileTransferListener(FileTransferListener)
* @see FileTransferListener
*/
public void addFileTransferListener(final FileTransferListener li) {
listeners.add(li);
}
/**
* Removes a file transfer listener.
*
* @param li
* The file transfer listener to be removed
* @see FileTransferListener
*/
public void removeFileTransferListener(final FileTransferListener li) {
listeners.remove(li);
}
/**
* Creates an OutgoingFileTransfer to send a file to another user.
*
* @param userID
* The fully qualified jabber ID (i.e. full JID) with resource of the user to
* send the file to.
* @return The send file object on which the negotiated transfer can be run.
* @exception IllegalArgumentException if userID is null or not a full JID
*/
public OutgoingFileTransfer createOutgoingFileTransfer(EntityFullJid userID) {
}
/**
* Add a file transfer listener to listen to incoming file transfer
* requests.
*
* @param li
* The listener
* @see #removeFileTransferListener(FileTransferListener)
* @see FileTransferListener
*/
public void addFileTransferListener(final FileTransferListener li) {
listeners.add(li);
}
/**
* Removes a file transfer listener.
*
* @param li
* The file transfer listener to be removed
* @see FileTransferListener
*/
public void removeFileTransferListener(final FileTransferListener li) {
listeners.remove(li);
}
/**
* Creates an OutgoingFileTransfer to send a file to another user.
*