1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 16:22:06 +01:00

more work on generic

add ' quoting
fix IntegerInstantiation is more memory friendly

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11024 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Michael Will 2009-06-04 11:58:25 +00:00 committed by michael.will
parent 634afb2cad
commit 1edc69780b
7 changed files with 40 additions and 27 deletions

View file

@ -31,6 +31,7 @@ import java.util.Random;
public class StringUtils {
private static final char[] QUOTE_ENCODE = """.toCharArray();
private static final char[] APOS_ENCODE = "'".toCharArray();
private static final char[] AMP_ENCODE = "&".toCharArray();
private static final char[] LT_ENCODE = "<".toCharArray();
private static final char[] GT_ENCODE = ">".toCharArray();
@ -326,6 +327,13 @@ public class StringUtils {
last = i + 1;
out.append(QUOTE_ENCODE);
}
else if (ch == '\'') {
if (i > last) {
out.append(input, last, i - last);
}
last = i + 1;
out.append(APOS_ENCODE);
}
}
if (last == 0) {
return string;

View file

@ -253,7 +253,8 @@ public class EnhancedDebugger implements SmackDebugger {
new DefaultTableModel(
new Object[]{"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"},
0) {
public boolean isCellEditable(int rowIndex, int mColIndex) {
private static final long serialVersionUID = 8136121224474217264L;
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
@ -645,7 +646,8 @@ public class EnhancedDebugger implements SmackDebugger {
new DefaultTableModel(new Object[][]{{"IQ", 0, 0}, {"Message", 0, 0},
{"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}},
new Object[]{"Type", "Received", "Sent"}) {
public boolean isCellEditable(int rowIndex, int mColIndex) {
private static final long serialVersionUID = -6793886085109589269L;
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
};
@ -711,20 +713,20 @@ public class EnhancedDebugger implements SmackDebugger {
* Updates the statistics table
*/
private void updateStatistics() {
statisticsTable.setValueAt(new Integer(receivedIQPackets), 0, 1);
statisticsTable.setValueAt(new Integer(sentIQPackets), 0, 2);
statisticsTable.setValueAt(Integer.valueOf(receivedIQPackets), 0, 1);
statisticsTable.setValueAt(Integer.valueOf(sentIQPackets), 0, 2);
statisticsTable.setValueAt(new Integer(receivedMessagePackets), 1, 1);
statisticsTable.setValueAt(new Integer(sentMessagePackets), 1, 2);
statisticsTable.setValueAt(Integer.valueOf(receivedMessagePackets), 1, 1);
statisticsTable.setValueAt(Integer.valueOf(sentMessagePackets), 1, 2);
statisticsTable.setValueAt(new Integer(receivedPresencePackets), 2, 1);
statisticsTable.setValueAt(new Integer(sentPresencePackets), 2, 2);
statisticsTable.setValueAt(Integer.valueOf(receivedPresencePackets), 2, 1);
statisticsTable.setValueAt(Integer.valueOf(sentPresencePackets), 2, 2);
statisticsTable.setValueAt(new Integer(receivedOtherPackets), 3, 1);
statisticsTable.setValueAt(new Integer(sentOtherPackets), 3, 2);
statisticsTable.setValueAt(Integer.valueOf(receivedOtherPackets), 3, 1);
statisticsTable.setValueAt(Integer.valueOf(sentOtherPackets), 3, 2);
statisticsTable.setValueAt(new Integer(receivedPackets), 4, 1);
statisticsTable.setValueAt(new Integer(sentPackets), 4, 2);
statisticsTable.setValueAt(Integer.valueOf(receivedPackets), 4, 1);
statisticsTable.setValueAt(Integer.valueOf(sentPackets), 4, 2);
}
/**

View file

@ -48,7 +48,7 @@ public class FileTransferManager {
private final FileTransferNegotiator fileTransferNegotiator;
private List listeners;
private List<FileTransferListener> listeners;
private XMPPConnection connection;
@ -83,7 +83,7 @@ public class FileTransferManager {
}
private void initListeners() {
listeners = new ArrayList();
listeners = new ArrayList<FileTransferListener>();
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {

View file

@ -175,7 +175,7 @@ public class FileTransferNegotiator {
*
* @return Returns a collection of the supported transfer protocols.
*/
public static Collection getSupportedProtocols() {
public static Collection<String> getSupportedProtocols() {
return Collections.unmodifiableList(Arrays.asList(PROTOCOLS));
}
@ -271,8 +271,8 @@ public class FileTransferNegotiator {
private FormField getStreamMethodField(DataForm form) {
FormField field = null;
for (Iterator it = form.getFields(); it.hasNext();) {
field = (FormField) it.next();
for (Iterator<FormField> it = form.getFields(); it.hasNext();) {
field = it.next();
if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) {
break;
}
@ -286,8 +286,8 @@ public class FileTransferNegotiator {
String variable;
boolean isByteStream = false;
boolean isIBB = false;
for (Iterator it = field.getOptions(); it.hasNext();) {
variable = ((FormField.Option) it.next()).getValue();
for (Iterator<FormField.Option> it = field.getOptions(); it.hasNext();) {
variable = it.next().getValue();
if (variable.equals(BYTE_STREAM) && !IBB_ONLY) {
isByteStream = true;
}

View file

@ -179,7 +179,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
*/
private SelectedHostInfo selectHost(Bytestream streamHostsInfo)
throws XMPPException {
Iterator it = streamHostsInfo.getStreamHosts().iterator();
Iterator<StreamHost> it = streamHostsInfo.getStreamHosts().iterator();
StreamHost selectedHost = null;
Socket socket = null;
while (it.hasNext()) {

View file

@ -127,9 +127,9 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa
catch (XMPPException e) {
return null;
}
Iterator itx = info.getIdentities();
Iterator<DiscoverInfo.Identity> itx = info.getIdentities();
while (itx.hasNext()) {
DiscoverInfo.Identity identity = (DiscoverInfo.Identity) itx.next();
DiscoverInfo.Identity identity = itx.next();
if ("proxy".equalsIgnoreCase(identity.getCategory())
&& "bytestreams".equalsIgnoreCase(
identity.getType())) {
@ -145,9 +145,9 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa
.getInstanceFor(connection);
try {
DiscoverItems discoItems = manager.discoverItems(connection.getServiceName());
Iterator it = discoItems.getItems();
Iterator<DiscoverItems.Item> it = discoItems.getItems();
while (it.hasNext()) {
DiscoverItems.Item item = (DiscoverItems.Item) it.next();
DiscoverItems.Item item = it.next();
String proxy = checkIsProxy(manager, item);
if (proxy != null) {
proxies.add(proxy);
@ -167,12 +167,12 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa
*/
private void initStreamHosts() {
List<Bytestream.StreamHost> streamHosts = new ArrayList<Bytestream.StreamHost>();
Iterator it = proxies.iterator();
Iterator<String> it = proxies.iterator();
IQ query;
PacketCollector collector;
Bytestream response;
while (it.hasNext()) {
String jid = it.next().toString();
String jid = it.next();
query = new IQ() {
public String getChildElementXML() {
return "<query xmlns=\"http://jabber.org/protocol/bytestreams\"/>";

View file

@ -93,6 +93,9 @@ public class StringUtilsTest extends TestCase {
input = "&";
assertEquals("&amp;", StringUtils.escapeForXML(input));
input = "It's a good day today";
assertEquals("It&apos;s a good day today", StringUtils.escapeForXML(input));
}
public void testHash() {