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.
tags/4.2.0
Florian Schmaus 3 years ago
parent
commit
ef0af66b21
100 changed files with 4988 additions and 4996 deletions
  1. +4
    -4
      config/checkstyle.xml
  2. +90
    -90
      smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java
  3. +8
    -8
      smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java
  4. +4
    -4
      smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java
  5. +168
    -168
      smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java
  6. +1
    -1
      smack-core/src/test/java/org/jivesoftware/smack/util/SHA1Test.java
  7. +5
    -5
      smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java
  8. +1
    -1
      smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java
  9. +1
    -1
      smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java
  10. +1
    -1
      smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java
  11. +251
    -251
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java
  12. +7
    -7
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferListener.java
  13. +89
    -89
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java
  14. +97
    -97
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java
  15. +290
    -290
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java
  16. +1
    -1
      smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/provider/RegistrationProvider.java
  17. +68
    -68
      smack-extensions/src/main/java/org/jivesoftware/smackx/nick/packet/Nick.java
  18. +139
    -139
      smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java
  19. +77
    -77
      smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/Privacy.java
  20. +20
    -20
      smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/provider/PrivacyProvider.java
  21. +10
    -10
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AccessModel.java
  22. +11
    -11
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java
  23. +17
    -17
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AffiliationsExtension.java
  24. +6
    -6
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ChildrenAssociationPolicy.java
  25. +4
    -4
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/CollectionNode.java
  26. +21
    -21
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigurationEvent.java
  27. +665
    -665
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java
  28. +189
    -189
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureNodeFields.java
  29. +6
    -6
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EmbeddedPacketExtension.java
  30. +27
    -27
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java
  31. +12
    -12
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElementType.java
  32. +63
    -63
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNode.java
  33. +25
    -25
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNodeType.java
  34. +25
    -25
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/GetItemsRequest.java
  35. +70
    -72
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java
  36. +32
    -32
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemDeleteEvent.java
  37. +85
    -85
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemPublishEvent.java
  38. +4
    -4
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemReply.java
  39. +163
    -163
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java
  40. +294
    -294
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java
  41. +455
    -459
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
  42. +9
    -9
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeEvent.java
  43. +50
    -50
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeExtension.java
  44. +2
    -2
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeType.java
  45. +24
    -24
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/OptionsExtension.java
  46. +77
    -77
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java
  47. +1
    -1
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PresenceState.java
  48. +47
    -47
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubElementType.java
  49. +224
    -224
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
  50. +39
    -39
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishItem.java
  51. +6
    -6
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishModel.java
  52. +28
    -28
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/RetractItem.java
  53. +35
    -35
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SimplePayload.java
  54. +31
    -31
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeExtension.java
  55. +198
    -198
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java
  56. +63
    -63
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeOptionFields.java
  57. +136
    -136
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java
  58. +44
    -44
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionEvent.java
  59. +61
    -61
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionsExtension.java
  60. +24
    -24
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/UnsubscribeExtension.java
  61. +12
    -12
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemDeleteListener.java
  62. +7
    -7
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemEventListener.java
  63. +7
    -7
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/NodeConfigListener.java
  64. +6
    -6
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java
  65. +26
    -26
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSubNamespace.java
  66. +5
    -5
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/AffiliationsProvider.java
  67. +8
    -8
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ConfigEventProvider.java
  68. +5
    -7
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/EventProvider.java
  69. +4
    -4
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/FormNodeProvider.java
  70. +4
    -4
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ItemsProvider.java
  71. +1
    -1
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/PubSubProvider.java
  72. +5
    -5
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/RetractEventProvider.java
  73. +4
    -4
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SimpleNodeProvider.java
  74. +20
    -20
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java
  75. +6
    -6
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionsProvider.java
  76. +13
    -13
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java
  77. +5
    -5
      smack-extensions/src/main/java/org/jivesoftware/smackx/si/packet/StreamInitiation.java
  78. +53
    -53
      smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java
  79. +44
    -44
      smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java
  80. +58
    -58
      smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ItemValidationTest.java
  81. +1
    -1
      smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java
  82. +1
    -1
      smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntries.java
  83. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleException.java
  84. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java
  85. +5
    -5
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleNegotiator.java
  86. +17
    -17
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java
  87. +11
    -11
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java
  88. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionStateEnded.java
  89. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/media/MediaNegotiator.java
  90. +3
    -3
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/JMFInit.java
  91. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioChannel.java
  92. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioMediaSession.java
  93. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioReceiver.java
  94. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/JmfMediaManager.java
  95. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/AudioMediaSession.java
  96. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/SpeexMediaManager.java
  97. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/ScreenShareSession.java
  98. +26
    -26
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/AbstractBufferedImageOp.java
  99. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageReceiver.java
  100. +2
    -2
      smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageTransmitter.java

+ 4
- 4
config/checkstyle.xml View File

@@ -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"/>


+ 90
- 90
smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java View File

@@ -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);
}
}

+ 8
- 8
smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java View File

@@ -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;
}

}

+ 4
- 4
smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java View File

@@ -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) {


+ 168
- 168
smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java View File

@@ -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();
}
}
}
}

+ 1
- 1
smack-core/src/test/java/org/jivesoftware/smack/util/SHA1Test.java View File

@@ -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?


+ 5
- 5
smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java View File

@@ -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);


+ 1
- 1
smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java View File

@@ -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");



+ 1
- 1
smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java View File

@@ -18,6 +18,6 @@ package org.jivesoftware.smackx.blocking;

public interface AllJidsUnblockedListener {

void onAllJidsUnblocked();
void onAllJidsUnblocked();

}

+ 1
- 1
smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java View File

@@ -22,6 +22,6 @@ import org.jxmpp.jid.Jid;

public interface JidsBlockedListener {

void onJidsBlocked(List<Jid> blockedJids);
void onJidsBlocked(List<Jid> blockedJids);

}

+ 251
- 251
smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java View File

@@ -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;
}
}

}

+ 7
- 7
smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferListener.java View File

@@ -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);
}

+ 89
- 89
smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java View File

@@ -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.
*
* @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) {
// We need to create outgoing file transfers with a full JID since this method will later
// use XEP-0095 to negotiate the stream. This is done with IQ stanzas that need to be addressed to a full JID
// in order to reach an client entity.
@@ -125,45 +125,45 @@ public final class FileTransferManager extends Manager {
throw new IllegalArgumentException("userID was null");
}

return new OutgoingFileTransfer(connection().getUser(), userID,
FileTransferNegotiator.getNextStreamID(),
fileTransferNegotiator);
}

/**
* When the file transfer request is acceptable, this method should be
* invoked. It will create an IncomingFileTransfer which allows the
* transmission of the file to procede.
*
* @param request
* The remote request that is being accepted.
* @return The IncomingFileTransfer which manages the download of the file
* from the transfer initiator.
*/
protected IncomingFileTransfer createIncomingFileTransfer(
FileTransferRequest request) {
if (request == null) {
throw new NullPointerException("RecieveRequest cannot be null");
}

IncomingFileTransfer transfer = new IncomingFileTransfer(request,
return new OutgoingFileTransfer(connection().getUser(), userID,
FileTransferNegotiator.getNextStreamID(),
fileTransferNegotiator);
transfer.setFileInfo(request.getFileName(), request.getFileSize());

return transfer;
}

/**
* Reject an incoming file transfer.
* <p>
* Specified in XEP-95 4.2 and 3.2 Example 8
* </p>
* @param request
* @throws NotConnectedException
* @throws InterruptedException
*/
protected void rejectIncomingFileTransfer(FileTransferRequest request) throws NotConnectedException, InterruptedException {
StreamInitiation initiation = request.getStreamInitiation();
}

/**
* When the file transfer request is acceptable, this method should be
* invoked. It will create an IncomingFileTransfer which allows the
* transmission of the file to procede.
*
* @param request
* The remote request that is being accepted.
* @return The IncomingFileTransfer which manages the download of the file
* from the transfer initiator.
*/
protected IncomingFileTransfer createIncomingFileTransfer(
FileTransferRequest request) {
if (request == null) {
throw new NullPointerException("RecieveRequest cannot be null");
}

IncomingFileTransfer transfer = new IncomingFileTransfer(request,
fileTransferNegotiator);
transfer.setFileInfo(request.getFileName(), request.getFileSize());

return transfer;
}

/**
* Reject an incoming file transfer.
* <p>
* Specified in XEP-95 4.2 and 3.2 Example 8
* </p>
* @param request
* @throws NotConnectedException
* @throws InterruptedException
*/
protected void rejectIncomingFileTransfer(FileTransferRequest request) throws NotConnectedException, InterruptedException {
StreamInitiation initiation = request.getStreamInitiation();

// Reject as specified in XEP-95 4.2. Note that this is not to be confused with the Socks 5
// Bytestream rejection as specified in XEP-65 5.3.1 Example 13, which says that
@@ -172,5 +172,5 @@ public final class FileTransferManager extends Manager {
IQ rejection = IQ.createErrorResponse(initiation, XMPPError.getBuilder(
XMPPError.Condition.forbidden));
connection().sendStanza(rejection);
}
}
}

+ 97
- 97
smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java View File

@@ -27,113 +27,113 @@ import org.jxmpp.jid.Jid;
*
*/
public class FileTransferRequest {
private final StreamInitiation streamInitiation;
private final StreamInitiation streamInitiation;

private final FileTransferManager manager;
private final FileTransferManager manager;

/**
* A recieve request is constructed from the Stream Initiation request
* received from the initator.
*
* @param manager
* The manager handling this file transfer
*
* @param si
* The Stream initiaton recieved from the initiator.
*/
public FileTransferRequest(FileTransferManager manager, StreamInitiation si) {
this.streamInitiation = si;
this.manager = manager;
}
/**
* A recieve request is constructed from the Stream Initiation request
* received from the initator.
*
* @param manager
* The manager handling this file transfer
*
* @param si
* The Stream initiaton recieved from the initiator.
*/
public FileTransferRequest(FileTransferManager manager, StreamInitiation si) {
this.streamInitiation = si;
this.manager = manager;
}

/**
* Returns the name of the file.
*
* @return Returns the name of the file.
*/
public String getFileName() {
return streamInitiation.getFile().getName();
}
/**
* Returns the name of the file.
*
* @return Returns the name of the file.
*/
public String getFileName() {
return streamInitiation.getFile().getName();
}

/**
* Returns the size in bytes of the file.
*
* @return Returns the size in bytes of the file.
*/
public long getFileSize() {
return streamInitiation.getFile().getSize();
}
/**
* Returns the size in bytes of the file.
*
* @return Returns the size in bytes of the file.
*/
public long getFileSize() {
return streamInitiation.getFile().getSize();
}

/**
* Returns the description of the file provided by the requestor.
*
* @return Returns the description of the file provided by the requestor.
*/
public String getDescription() {
return streamInitiation.getFile().getDesc();
}
/**
* Returns the description of the file provided by the requestor.
*
* @return Returns the description of the file provided by the requestor.
*/
public String getDescription() {
return streamInitiation.getFile().getDesc();
}

/**
* Returns the mime-type of the file.
*
* @return Returns the mime-type of the file.
*/
public String getMimeType() {
return streamInitiation.getMimeType();
}
/**
* Returns the mime-type of the file.
*
* @return Returns the mime-type of the file.
*/
public String getMimeType() {
return streamInitiation.getMimeType();
}

/**
* Returns the fully-qualified jabber ID of the user that requested this
* file transfer.
*
* @return Returns the fully-qualified jabber ID of the user that requested
* this file transfer.
*/
public Jid getRequestor() {
return streamInitiation.getFrom();
}
/**
* Returns the fully-qualified jabber ID of the user that requested this
* file transfer.
*
* @return Returns the fully-qualified jabber ID of the user that requested
* this file transfer.
*/
public Jid getRequestor() {
return streamInitiation.getFrom();
}

/**
* Returns the stream ID that uniquely identifies this file transfer.
*
* @return Returns the stream ID that uniquely identifies this file
* transfer.
*/
public String getStreamID() {
return streamInitiation.getSessionID();
}
/**
* Returns the stream ID that uniquely identifies this file transfer.
*
* @return Returns the stream ID that uniquely identifies this file
* transfer.
*/
public String getStreamID() {
return streamInitiation.getSessionID();
}

/**
* Returns the stream initiation stanza(/packet) that was sent by the requestor which
* contains the parameters of the file transfer being transfer and also the
* methods available to transfer the file.
*
* @return Returns the stream initiation stanza(/packet) that was sent by the
* requestor which contains the parameters of the file transfer
* being transfer and also the methods available to transfer the
* file.
*/
protected StreamInitiation getStreamInitiation() {
return streamInitiation;
}
/**
* Returns the stream initiation stanza(/packet) that was sent by the requestor which
* contains the parameters of the file transfer being transfer and also the
* methods available to transfer the file.
*
* @return Returns the stream initiation stanza(/packet) that was sent by the
* requestor which contains the parameters of the file transfer
* being transfer and also the methods available to transfer the
* file.
*/
protected StreamInitiation getStreamInitiation() {
return streamInitiation;
}

/**
* Accepts this file transfer and creates the incoming file transfer.
*
* @return Returns the <b><i>IncomingFileTransfer</b></i> on which the
* file transfer can be carried out.
*/
public IncomingFileTransfer accept() {
return manager.createIncomingFileTransfer(this);
}
/**
* Accepts this file transfer and creates the incoming file transfer.
*
* @return Returns the <b><i>IncomingFileTransfer</b></i> on which the
* file transfer can be carried out.
*/
public IncomingFileTransfer accept() {
return manager.createIncomingFileTransfer(this);
}

/**
* Rejects the file transfer request.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void reject() throws NotConnectedException, InterruptedException {
manager.rejectIncomingFileTransfer(this);
}
/**
* Rejects the file transfer request.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void reject() throws NotConnectedException, InterruptedException {
manager.rejectIncomingFileTransfer(this);
}

}

+ 290
- 290
smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java View File

@@ -43,7 +43,7 @@ import org.jxmpp.jid.Jid;
public class OutgoingFileTransfer extends FileTransfer {
private static final Logger LOGGER = Logger.getLogger(OutgoingFileTransfer.class.getName());

private static int RESPONSE_TIMEOUT = 60 * 1000;
private static int RESPONSE_TIMEOUT = 60 * 1000;
private NegotiationProgress callback;

/**
@@ -58,349 +58,349 @@ public class OutgoingFileTransfer extends FileTransfer {
return RESPONSE_TIMEOUT;
}

/**
* Sets the time in milliseconds after which the file transfer negotiation
* process will timeout if the other user has not responded.
*
* @param responseTimeout
* The timeout time in milliseconds.
*/
public static void setResponseTimeout(int responseTimeout) {
RESPONSE_TIMEOUT = responseTimeout;
}
private OutputStream outputStream;
private Jid initiator;
private Thread transferThread;
protected OutgoingFileTransfer(Jid initiator, Jid target,
String streamID, FileTransferNegotiator transferNegotiator) {
super(target, streamID, transferNegotiator);
this.initiator = initiator;
}
protected void setOutputStream(OutputStream stream) {
if (outputStream == null) {
this.outputStream = stream;
}
}
/**
* Returns the output stream connected to the peer to transfer the file. It
* is only available after it has been successfully negotiated by the
* {@link StreamNegotiator}.
*
* @return Returns the output stream connected to the peer to transfer the
* file.
*/
protected OutputStream getOutputStream() {
if (getStatus().equals(FileTransfer.Status.negotiated)) {
return outputStream;
} else {
return null;
}
}
/**
* This method handles the negotiation of the file transfer and the stream,
* it only returns the created stream after the negotiation has been completed.
*
* @param fileName
* The name of the file that will be transmitted. It is
* preferable for this name to have an extension as it will be
* used to determine the type of file it is.
* @param fileSize
* The size in bytes of the file that will be transmitted.
* @param description
* A description of the file that will be transmitted.
* @return The OutputStream that is connected to the peer to transmit the
* file.
* @throws XMPPException
* Thrown if an error occurs during the file transfer
* negotiation process.
* @throws SmackException if there was no response from the server.
* @throws InterruptedException
*/
public synchronized OutputStream sendFile(String fileName, long fileSize,
String description) throws XMPPException, SmackException, InterruptedException {
if (isDone() || outputStream != null) {
throw new IllegalStateException(
"The negotation process has already"
+ " been attempted on this file transfer");
}
try {
setFileInfo(fileName, fileSize);
this.outputStream = negotiateStream(fileName, fileSize, description);
} catch (XMPPErrorException e) {
handleXMPPException(e);
throw e;
}
return outputStream;
}
/**
* This methods handles the transfer and stream negotiation process. It
* returns immediately and its progress will be updated through the
* {@link NegotiationProgress} callback.
*
* @param fileName
* The name of the file that will be transmitted. It is
* preferable for this name to have an extension as it will be
* used to determine the type of file it is.
* @param fileSize
* The size in bytes of the file that will be transmitted.
* @param description
* A description of the file that will be transmitted.
* @param progress
* A callback to monitor the progress of the file transfer
* negotiation process and to retrieve the OutputStream when it
* is complete.
*/
public synchronized void sendFile(final String fileName,
final long fileSize, final String description,
final NegotiationProgress progress)
/**
* Sets the time in milliseconds after which the file transfer negotiation
* process will timeout if the other user has not responded.
*
* @param responseTimeout
* The timeout time in milliseconds.
*/
public static void setResponseTimeout(int responseTimeout) {
RESPONSE_TIMEOUT = responseTimeout;
}
private OutputStream outputStream;
private Jid initiator;
private Thread transferThread;
protected OutgoingFileTransfer(Jid initiator, Jid target,
String streamID, FileTransferNegotiator transferNegotiator) {
super(target, streamID, transferNegotiator);
this.initiator = initiator;
}
protected void setOutputStream(OutputStream stream) {
if (outputStream == null) {
this.outputStream = stream;
}
}
/**
* Returns the output stream connected to the peer to transfer the file. It
* is only available after it has been successfully negotiated by the
* {@link StreamNegotiator}.
*
* @return Returns the output stream connected to the peer to transfer the
* file.
*/
protected OutputStream getOutputStream() {
if (getStatus().equals(FileTransfer.Status.negotiated)) {
return outputStream;
} else {
return null;
}