mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-02-07 09:26:25 +01:00
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.
This commit is contained in:
parent
ffe9397e66
commit
ef0af66b21
125 changed files with 5336 additions and 5344 deletions
|
@ -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"/>
|
||||
|
|
|
@ -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 void setEnabled(boolean enabled) {
|
||||
mEnabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return mEnabled;
|
||||
}
|
||||
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 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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
@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);
|
||||
}
|
||||
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());
|
||||
// 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);
|
||||
}
|
||||
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());
|
||||
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));
|
||||
}
|
||||
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);
|
||||
@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);
|
||||
}
|
||||
}
|
||||
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");
|
||||
}
|
||||
});
|
||||
consumer1.setName("consumer 1");
|
||||
|
||||
Thread consumer2 = new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Stanza p = null;
|
||||
Thread consumer2 = new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Stanza p = null;
|
||||
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(3);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
try {
|
||||
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");
|
||||
// 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;
|
||||
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");
|
||||
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();
|
||||
consumer1.start();
|
||||
consumer2.start();
|
||||
consumer3.start();
|
||||
|
||||
for(int i=0; i<insertCount; i++)
|
||||
{
|
||||
collector.processStanza(new TestPacket(i));
|
||||
}
|
||||
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());
|
||||
}
|
||||
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 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 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));
|
||||
}
|
||||
class TestPacket extends Stanza
|
||||
{
|
||||
public TestPacket(int i)
|
||||
{
|
||||
setStanzaId(String.valueOf(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toXML()
|
||||
{
|
||||
return "<packetId>" + getStanzaId() + "</packetId>";
|
||||
}
|
||||
@Override
|
||||
public String toXML()
|
||||
{
|
||||
return "<packetId>" + getStanzaId() + "</packetId>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toXML();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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'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);
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -18,6 +18,6 @@ package org.jivesoftware.smackx.blocking;
|
|||
|
||||
public interface AllJidsUnblockedListener {
|
||||
|
||||
void onAllJidsUnblocked();
|
||||
void onAllJidsUnblocked();
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,6 @@ import org.jxmpp.jid.Jid;
|
|||
|
||||
public interface JidsBlockedListener {
|
||||
|
||||
void onJidsBlocked(List<Jid> blockedJids);
|
||||
void onJidsBlocked(List<Jid> blockedJids);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
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 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;
|
||||
}
|
||||
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 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 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 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 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() {
|
||||
/**
|
||||
* 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 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;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
this.error = Error.connection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to represent the current status of the file transfer.
|
||||
*
|
||||
* @author Alexander Wenckus
|
||||
*
|
||||
*/
|
||||
public enum Status {
|
||||
/**
|
||||
* 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"),
|
||||
/**
|
||||
* 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 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 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"),
|
||||
/**
|
||||
* 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"),
|
||||
/**
|
||||
* 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 is in progress.
|
||||
*
|
||||
* @see FileTransfer#getProgress()
|
||||
*/
|
||||
in_progress("In Progress"),
|
||||
|
||||
/**
|
||||
* The transfer has completed successfully.
|
||||
*/
|
||||
complete("Complete"),
|
||||
/**
|
||||
* The transfer has completed successfully.
|
||||
*/
|
||||
complete("Complete"),
|
||||
|
||||
/**
|
||||
* The file transfer was cancelled.
|
||||
*/
|
||||
cancelled("Cancelled");
|
||||
/**
|
||||
* 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"),
|
||||
/**
|
||||
* 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 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 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."),
|
||||
/**
|
||||
* 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 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.");
|
||||
/**
|
||||
* An error occurred while sending or receiving the file.
|
||||
*/
|
||||
stream("An error occured while sending or recieving the file.");
|
||||
|
||||
private final String msg;
|
||||
private final String msg;
|
||||
|
||||
private Error(String msg) {
|
||||
this.msg = 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;
|
||||
}
|
||||
/**
|
||||
* Returns a String representation of this error.
|
||||
*
|
||||
* @return Returns a String representation of this error.
|
||||
*/
|
||||
public String getMessage(< |