diff --git a/apps/BOB/src/net/i2p/BOB/Lifted.java b/apps/BOB/src/net/i2p/BOB/Lifted.java index 47268243677aea05d4ec7c1d2d21a9fc851beb52..6c38cba777da0bb1ff37bd0f09349319dddf8944 100644 --- a/apps/BOB/src/net/i2p/BOB/Lifted.java +++ b/apps/BOB/src/net/i2p/BOB/Lifted.java @@ -15,7 +15,7 @@ */ package net.i2p.BOB; -import java.util.Enumeration; +import java.util.Map; import java.util.Properties; /** @@ -39,10 +39,8 @@ public class Lifted { * **/ public static void copyProperties(Properties src_prop, Properties dest_prop) { - for (Enumeration propertyNames = src_prop.propertyNames(); - propertyNames.hasMoreElements();) { - Object key = propertyNames.nextElement(); - dest_prop.put(key, src_prop.get(key)); + for (Map.Entry<Object, Object> e : src_prop.entrySet()) { + dest_prop.put((String)e.getKey(), (String)e.getValue()); } } } diff --git a/apps/desktopgui/src/net/i2p/desktopgui/Main.java b/apps/desktopgui/src/net/i2p/desktopgui/Main.java index 993970e30c8a32c1c5407eda8910eea1a6fc586b..c07e03f44671aa3246d3e39e6c893caac70b9296 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/Main.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/Main.java @@ -7,9 +7,6 @@ package net.i2p.desktopgui; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; -import java.awt.GraphicsEnvironment; - -import net.i2p.I2PAppContext; import net.i2p.desktopgui.router.RouterManager; import net.i2p.desktopgui.util.*; import net.i2p.util.Log; diff --git a/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java b/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java index 1a29d8871bd201201967ad7a3020816920aec42e..f124ee3f62eaa3ab8eee99f5862a0a4822f3bc3a 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java @@ -1,28 +1,15 @@ package net.i2p.desktopgui; import java.awt.AWTException; -import java.awt.Desktop; import java.awt.Image; -import java.awt.MenuItem; import java.awt.PopupMenu; import java.awt.SystemTray; import java.awt.Toolkit; import java.awt.TrayIcon; -import java.awt.Desktop.Action; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; -import javax.swing.SwingWorker; - import net.i2p.desktopgui.i18n.DesktopguiTranslator; import net.i2p.desktopgui.router.RouterManager; -import net.i2p.desktopgui.util.BrowseException; -import net.i2p.desktopgui.util.ConfigurationManager; -import net.i2p.desktopgui.util.I2PDesktop; import net.i2p.util.Log; /** diff --git a/apps/desktopgui/src/net/i2p/desktopgui/gui/DesktopguiConfigurationFrame.java b/apps/desktopgui/src/net/i2p/desktopgui/gui/DesktopguiConfigurationFrame.java index ae45bf24712da3d906c94a7287b89902d15f3d78..1e49f66093196c53e0bb23b38c48331fd1fde6b2 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/gui/DesktopguiConfigurationFrame.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/gui/DesktopguiConfigurationFrame.java @@ -32,7 +32,6 @@ public class DesktopguiConfigurationFrame extends javax.swing.JFrame { * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ - @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { @@ -115,7 +114,7 @@ public class DesktopguiConfigurationFrame extends javax.swing.JFrame { System.out.println("Enabling desktopgui"); } try { - RouterManager.getRouterContext().setProperty(property, value); + RouterManager.getRouterContext().router().saveConfig(property, value); } catch (Exception ex) { Logger.getLogger(DesktopguiConfigurationFrame.class.getName()).log(Level.SEVERE, null, ex); } diff --git a/apps/desktopgui/src/net/i2p/desktopgui/router/RouterManager.java b/apps/desktopgui/src/net/i2p/desktopgui/router/RouterManager.java index 63f6ad588aaf02b4aa8dfee167a70165ffd7f820..82b36938ac3f7de5cecfeac20a8678df7457c84e 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/router/RouterManager.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/router/RouterManager.java @@ -5,8 +5,6 @@ import java.io.IOException; import org.tanukisoftware.wrapper.WrapperManager; import net.i2p.I2PAppContext; -import net.i2p.desktopgui.i18n.DesktopguiTranslator; -import net.i2p.desktopgui.util.ConfigurationManager; import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.util.Log; diff --git a/apps/desktopgui/src/net/i2p/desktopgui/util/I2PDesktop.java b/apps/desktopgui/src/net/i2p/desktopgui/util/I2PDesktop.java index ad6e14cb315d8265f873a4ebe9cd04a87825eb7e..6ddfc4a970d810eabae4fd147223a4f64310b969 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/util/I2PDesktop.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/util/I2PDesktop.java @@ -1,13 +1,8 @@ package net.i2p.desktopgui.util; import java.awt.Desktop; -import java.awt.TrayIcon; import java.awt.Desktop.Action; -import java.io.IOException; import java.net.URI; -import java.net.URISyntaxException; - -import net.i2p.desktopgui.router.RouterManager; import net.i2p.util.Log; public class I2PDesktop { diff --git a/apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java b/apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java index 8ec5442dd00541bf16007ce9989e8b10d3462b38..97deb7339f9e0a17f8a8dea2967883cc622ef783 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java +++ b/apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java @@ -156,11 +156,11 @@ public class MetaInfo if (val == null) { this.announce_list = null; } else { - this.announce_list = new ArrayList(); + this.announce_list = new ArrayList<List<String>>(); List<BEValue> bl1 = val.getList(); for (BEValue bev : bl1) { List<BEValue> bl2 = bev.getList(); - List<String> sl2 = new ArrayList(); + List<String> sl2 = new ArrayList<String>(); for (BEValue bev2 : bl2) { sl2.add(bev2.getString()); } @@ -259,9 +259,9 @@ public class MetaInfo if (size == 0) throw new InvalidBEncodingException("zero size files list"); - List<List<String>> m_files = new ArrayList(size); - List<List<String>> m_files_utf8 = new ArrayList(size); - List<Long> m_lengths = new ArrayList(size); + List<List<String>> m_files = new ArrayList<List<String>>(size); + List<List<String>> m_files_utf8 = new ArrayList<List<String>>(size); + List<Long> m_lengths = new ArrayList<Long>(size); long l = 0; for (int i = 0; i < list.size(); i++) { @@ -287,7 +287,7 @@ public class MetaInfo if (path_length == 0) throw new InvalidBEncodingException("zero size file path list"); - List<String> file = new ArrayList(path_length); + List<String> file = new ArrayList<String>(path_length); Iterator<BEValue> it = path_list.iterator(); while (it.hasNext()) { String s = it.next().getString(); @@ -310,7 +310,7 @@ public class MetaInfo path_list = val.getList(); path_length = path_list.size(); if (path_length > 0) { - file = new ArrayList(path_length); + file = new ArrayList<String>(path_length); it = path_list.iterator(); while (it.hasNext()) file.add(it.next().getString()); @@ -573,10 +573,10 @@ public class MetaInfo */ public MetaInfo reannounce(String announce) throws InvalidBEncodingException { - Map<String, BEValue> m = new HashMap(); + Map<String, BEValue> m = new HashMap<String, BEValue>(); if (announce != null) m.put("announce", new BEValue(DataHelper.getUTF8(announce))); - Map info = createInfoMap(); + Map<String, BEValue> info = createInfoMap(); m.put("info", new BEValue(info)); return new MetaInfo(m); } @@ -586,12 +586,12 @@ public class MetaInfo */ public synchronized byte[] getTorrentData() { - Map m = new HashMap(); + Map<String, Object> m = new HashMap<String, Object>(); if (announce != null) m.put("announce", announce); if (announce_list != null) m.put("announce-list", announce_list); - Map info = createInfoMap(); + Map<String, BEValue> info = createInfoMap(); m.put("info", info); // don't save this locally, we should only do this once return BEncoder.bencode(m); @@ -615,31 +615,42 @@ public class MetaInfo if (_log.shouldLog(Log.WARN)) _log.warn("Creating new infomap", new Exception()); // otherwise we must create it - Map info = new HashMap(); - info.put("name", name); + Map<String, BEValue> info = new HashMap<String, BEValue>(); + info.put("name", new BEValue(DataHelper.getUTF8(name))); if (name_utf8 != null) - info.put("name.utf-8", name_utf8); + info.put("name.utf-8", new BEValue(DataHelper.getUTF8(name_utf8))); // BEP 27 if (privateTorrent) - info.put("private", "1"); + info.put("private", new BEValue(DataHelper.getUTF8("1"))); - info.put("piece length", Integer.valueOf(piece_length)); - info.put("pieces", piece_hashes); + info.put("piece length", new BEValue(Integer.valueOf(piece_length))); + info.put("pieces", new BEValue(piece_hashes)); if (files == null) - info.put("length", Long.valueOf(length)); + info.put("length", new BEValue(Long.valueOf(length))); else { - List l = new ArrayList(); + List<BEValue> l = new ArrayList<BEValue>(); for (int i = 0; i < files.size(); i++) { - Map file = new HashMap(); - file.put("path", files.get(i)); - if ( (files_utf8 != null) && (files_utf8.size() > i) ) - file.put("path.utf-8", files_utf8.get(i)); - file.put("length", lengths.get(i)); - l.add(file); + Map<String, BEValue> file = new HashMap<String, BEValue>(); + List<String> fi = files.get(i); + List<BEValue> befiles = new ArrayList<BEValue>(fi.size()); + for (int j = 0; j < fi.size(); j++) { + befiles.add(new BEValue(DataHelper.getUTF8(fi.get(j)))); + } + file.put("path", new BEValue(befiles)); + if ( (files_utf8 != null) && (files_utf8.size() > i) ) { + List<String> fiu = files_utf8.get(i); + List<BEValue> beufiles = new ArrayList<BEValue>(fiu.size()); + for (int j = 0; j < fiu.size(); j++) { + beufiles.add(new BEValue(DataHelper.getUTF8(fiu.get(j)))); + } + file.put("path.utf-8", new BEValue(beufiles)); + } + file.put("length", new BEValue(lengths.get(i))); + l.add(new BEValue(file)); } - info.put("files", l); + info.put("files", new BEValue(l)); } // TODO if we add the ability for other keys in the first constructor diff --git a/apps/i2psnark/java/src/org/klomp/snark/PartialPiece.java b/apps/i2psnark/java/src/org/klomp/snark/PartialPiece.java index bfeb49b7f509880578a2b218868d19e6bc6ef5b2..bcf0aefd0b21d36b2e148ac25c97ca9a1bd1a086 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PartialPiece.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PartialPiece.java @@ -31,7 +31,7 @@ import net.i2p.util.SecureFile; * * @since 0.8.2 */ -class PartialPiece implements Comparable { +class PartialPiece implements Comparable<PartialPiece> { // we store the piece so we can use it in compareTo() private final Piece piece; @@ -295,8 +295,7 @@ class PartialPiece implements Comparable { * then rarest first, * then highest downloaded first */ - public int compareTo(Object o) throws ClassCastException { - PartialPiece opp = (PartialPiece)o; + public int compareTo(PartialPiece opp) { int d = this.piece.compareTo(opp.piece); if (d != 0) return d; diff --git a/apps/i2psnark/java/src/org/klomp/snark/Peer.java b/apps/i2psnark/java/src/org/klomp/snark/Peer.java index 821c39db8d9fda6fb4bb13c1aeed174425f3182e..683b3f2217f2bc98b05460a15243d90e67fd8c41 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Peer.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Peer.java @@ -39,7 +39,7 @@ import net.i2p.util.Log; import org.klomp.snark.bencode.BEValue; -public class Peer implements Comparable +public class Peer implements Comparable<Peer> { private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(Peer.class); // Identifying property, the peer id of the other side. @@ -194,7 +194,7 @@ public class Peer implements Comparable * Compares the PeerIDs. * @deprecated unused? */ - public int compareTo(Object o) + public int compareTo(Peer o) { Peer p = (Peer)o; int rv = peerID.compareTo(p.peerID); diff --git a/apps/i2psnark/java/src/org/klomp/snark/PeerID.java b/apps/i2psnark/java/src/org/klomp/snark/PeerID.java index cac80c8261215e8653e7e6560cfe50b083e6dd5d..16dc9224a99730669a8b49b34d2dbb504924805f 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PeerID.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PeerID.java @@ -42,7 +42,7 @@ import org.klomp.snark.bencode.InvalidBEncodingException; * and the PeerID is not required. * Equality is now determined solely by the dest hash. */ -class PeerID implements Comparable +class PeerID implements Comparable<PeerID> { private byte[] id; private Destination address; @@ -76,15 +76,15 @@ class PeerID implements Comparable * Creates a PeerID from a Map containing BEncoded peer id, ip and * port. */ - public PeerID(Map m) + public PeerID(Map<String, BEValue> m) throws InvalidBEncodingException, UnknownHostException { - BEValue bevalue = (BEValue)m.get("peer id"); + BEValue bevalue = m.get("peer id"); if (bevalue == null) throw new InvalidBEncodingException("peer id missing"); id = bevalue.getBytes(); - bevalue = (BEValue)m.get("ip"); + bevalue = m.get("ip"); if (bevalue == null) throw new InvalidBEncodingException("ip missing"); address = I2PSnarkUtil.getDestinationFromBase64(bevalue.getString()); @@ -195,10 +195,8 @@ class PeerID implements Comparable * Compares port, address and id. * @deprecated unused? and will NPE now that address can be null? */ - public int compareTo(Object o) + public int compareTo(PeerID pid) { - PeerID pid = (PeerID)o; - int result = port - pid.port; if (result != 0) return result; diff --git a/apps/i2psnark/java/src/org/klomp/snark/Piece.java b/apps/i2psnark/java/src/org/klomp/snark/Piece.java index 582505bc47b6c67cc9610125e25dc811b944966e..202afe4c4dc43773260516e7eebc965407851cd0 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Piece.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Piece.java @@ -7,7 +7,7 @@ import java.util.Set; * This class is used solely by PeerCoordinator. * Caller must synchronize on many of these methods. */ -class Piece implements Comparable { +class Piece implements Comparable<Piece> { private final int id; private final Set<PeerID> peers; @@ -26,11 +26,11 @@ class Piece implements Comparable { * Highest priority first, * then rarest first */ - public int compareTo(Object o) throws ClassCastException { - int pdiff = ((Piece)o).priority - this.priority; // reverse + public int compareTo(Piece op) { + int pdiff = op.priority - this.priority; // reverse if (pdiff != 0) return pdiff; - return this.peers.size() - ((Piece)o).peers.size(); + return this.peers.size() - op.peers.size(); } @Override diff --git a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java index 66b372d614ee5ed6252cc7b825c133fc637c7e74..15b246bf0259a09dda5fcfbc96348a5714ea553a 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java +++ b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java @@ -424,7 +424,7 @@ public class SnarkManager implements CompleteListener { String i2cpHost = _config.getProperty(PROP_I2CP_HOST); int i2cpPort = getInt(PROP_I2CP_PORT, 7654); String opts = _config.getProperty(PROP_I2CP_OPTS); - Map i2cpOpts = new HashMap(); + Map<String, String> i2cpOpts = new HashMap<String, String>(); if (opts != null) { StringTokenizer tok = new StringTokenizer(opts, " "); while (tok.hasMoreTokens()) { @@ -1652,7 +1652,7 @@ public class SnarkManager implements CompleteListener { */ private void monitorTorrents(File dir) { String fileNames[] = dir.list(TorrentFilenameFilter.instance()); - List<String> foundNames = new ArrayList(0); + List<String> foundNames = new ArrayList<String>(0); if (fileNames != null) { for (int i = 0; i < fileNames.length; i++) { try { @@ -1738,7 +1738,7 @@ public class SnarkManager implements CompleteListener { * @since 0.9.1 */ public List<Tracker> getSortedTrackers() { - List<Tracker> rv = new ArrayList(_trackerMap.values()); + List<Tracker> rv = new ArrayList<Tracker>(_trackerMap.values()); Collections.sort(rv, new IgnoreCaseComparator()); return rv; } diff --git a/apps/i2psnark/java/src/org/klomp/snark/bencode/BDecoder.java b/apps/i2psnark/java/src/org/klomp/snark/bencode/BDecoder.java index 2dc4e57b102c8f0473e96eb5fec609a17ea71662..5384154d1bbe1b12ae9ac49578040c512cbb7f2a 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/bencode/BDecoder.java +++ b/apps/i2psnark/java/src/org/klomp/snark/bencode/BDecoder.java @@ -281,7 +281,7 @@ public class BDecoder + (char)c + "'"); indicator = 0; - List result = new ArrayList(); + List<BEValue> result = new ArrayList<BEValue>(); c = getNextIndicator(); while (c != 'e') { @@ -308,7 +308,7 @@ public class BDecoder + (char)c + "'"); indicator = 0; - Map result = new HashMap(); + Map<String, BEValue> result = new HashMap<String, BEValue>(); c = getNextIndicator(); while (c != 'e') { diff --git a/apps/i2psnark/java/src/org/klomp/snark/bencode/BEValue.java b/apps/i2psnark/java/src/org/klomp/snark/bencode/BEValue.java index 4cae2881ae6c7d70a5e809c7187348b2d6484cd8..0664065fb54277e70c9070478a8d272d5e69b1f1 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/bencode/BEValue.java +++ b/apps/i2psnark/java/src/org/klomp/snark/bencode/BEValue.java @@ -49,12 +49,12 @@ public class BEValue this.value = value; } - public BEValue(List value) + public BEValue(List<BEValue> value) { this.value = value; } - public BEValue(Map value) + public BEValue(Map<String, BEValue> value) { this.value = value; } @@ -142,11 +142,12 @@ public class BEValue * succeeds when the BEValue is actually a List, otherwise it will * throw a InvalidBEncodingException. */ + @SuppressWarnings("unchecked") public List<BEValue> getList() throws InvalidBEncodingException { try { - return (List)value; + return (List<BEValue>)value; } catch (ClassCastException cce) { @@ -159,11 +160,12 @@ public class BEValue * values. This operation only succeeds when the BEValue is actually * a Map, otherwise it will throw a InvalidBEncodingException. */ + @SuppressWarnings("unchecked") public Map<String, BEValue> getMap() throws InvalidBEncodingException { try { - return (Map)value; + return (Map<String, BEValue>)value; } catch (ClassCastException cce) { diff --git a/apps/i2psnark/java/src/org/klomp/snark/bencode/BEncoder.java b/apps/i2psnark/java/src/org/klomp/snark/bencode/BEncoder.java index 9584b0d9db322e8fa1276be415cc190e46bee4a3..4cb55541ff634c748e58cc9b78bad1022aaf8784 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/bencode/BEncoder.java +++ b/apps/i2psnark/java/src/org/klomp/snark/bencode/BEncoder.java @@ -59,9 +59,9 @@ public class BEncoder else if (o instanceof Number) bencode((Number)o, out); else if (o instanceof List) - bencode((List)o, out); + bencode((List<?>)o, out); else if (o instanceof Map) - bencode((Map<String, Object>)o, out); + bencode((Map<?, ?>)o, out); else if (o instanceof BEValue) bencode(((BEValue)o).getValue(), out); else @@ -110,7 +110,7 @@ public class BEncoder out.write('e'); } - public static byte[] bencode(List l) + public static byte[] bencode(List<?> l) { try { @@ -124,10 +124,10 @@ public class BEncoder } } - public static void bencode(List l, OutputStream out) throws IOException + public static void bencode(List<?> l, OutputStream out) throws IOException { out.write('l'); - Iterator it = l.iterator(); + Iterator<?> it = l.iterator(); while (it.hasNext()) bencode(it.next(), out); out.write('e'); @@ -175,7 +175,7 @@ public class BEncoder // Keys must be sorted. XXX - But is this the correct order? Set<String> s = m.keySet(); - List<String> l = new ArrayList(s); + List<String> l = new ArrayList<String>(s); Collections.sort(l); Iterator<String> it = l.iterator(); diff --git a/apps/i2psnark/java/src/org/klomp/snark/dht/PersistDHT.java b/apps/i2psnark/java/src/org/klomp/snark/dht/PersistDHT.java index c690bc340a26e946c9e25f8d35829f5c0fe9b1a9..8ecd111ef7b5ddbef82caf7e1683f9f969fb9788 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/dht/PersistDHT.java +++ b/apps/i2psnark/java/src/org/klomp/snark/dht/PersistDHT.java @@ -37,10 +37,10 @@ abstract class PersistDHT { public static synchronized void loadDHT(KRPC krpc, File file) { Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class); int count = 0; - FileInputStream in = null; + BufferedReader br = null; try { - in = new FileInputStream(file); - BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); + br = new BufferedReader(new InputStreamReader( + new FileInputStream(file), "ISO-8859-1")); String line = null; while ( (line = br.readLine()) != null) { if (line.startsWith("#")) @@ -61,7 +61,7 @@ abstract class PersistDHT { if (log.shouldLog(Log.WARN) && file.exists()) log.warn("Error reading the DHT File", ioe); } finally { - if (in != null) try { in.close(); } catch (IOException ioe) {} + if (br != null) try { br.close(); } catch (IOException ioe) {} } if (log.shouldLog(Log.INFO)) log.info("Loaded " + count + " nodes from " + file); diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/BasicServlet.java b/apps/i2psnark/java/src/org/klomp/snark/web/BasicServlet.java index 1383ff2bb68940362b8ba692fd4b008f4f2b1047..593f7e21d3aa3f941e3d1bc959fe089ebcdd6726 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/BasicServlet.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/BasicServlet.java @@ -27,7 +27,6 @@ import java.util.Enumeration; import java.util.List; import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.UnavailableException; import javax.servlet.http.HttpServlet; @@ -325,7 +324,7 @@ class BasicServlet extends HttpServlet long content_length = content.getContentLength(); // see if there are any range headers - Enumeration reqRanges = request.getHeaders("Range"); + Enumeration<?> reqRanges = request.getHeaders("Range"); if (reqRanges == null || !reqRanges.hasMoreElements()) { // if there were no ranges, send entire entity diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java index 5606a6186fb502991fbcd34ffeb761ffe8d92c64..6329217f613d348666d21754c7a75750d35319c5 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java @@ -1,12 +1,8 @@ package org.klomp.snark.web; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; import java.text.Collator; import java.text.DecimalFormat; import java.text.SimpleDateFormat; @@ -16,7 +12,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.Enumeration; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -26,14 +21,11 @@ import java.util.TreeSet; import javax.servlet.ServletConfig; import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import net.i2p.I2PAppContext; import net.i2p.data.Base64; import net.i2p.data.DataHelper; -import net.i2p.util.I2PAppThread; import net.i2p.util.Log; import org.klomp.snark.I2PSnarkUtil; @@ -208,7 +200,8 @@ public class I2PSnarkServlet extends BasicServlet { resp.sendError(404); } else { String base = addPaths(req.getRequestURI(), "/"); - String listing = getListHTML(resource, base, true, method.equals("POST") ? req.getParameterMap() : null); + @SuppressWarnings("unchecked") // TODO-Java6: Remove cast, return type is correct + String listing = getListHTML(resource, base, true, method.equals("POST") ? (Map<String, String[]>) req.getParameterMap() : null); if (method.equals("POST")) { // P-R-G sendRedirect(req, resp, ""); @@ -684,7 +677,8 @@ public class I2PSnarkServlet extends BasicServlet { String action = req.getParameter("action"); if (action == null) { // http://www.onenaught.com/posts/382/firefox-4-change-input-type-image-only-submits-x-and-y-not-name - Map params = req.getParameterMap(); + @SuppressWarnings("unchecked") // TODO-Java6: Remove cast, return type is correct + Map<String, String[]> params = req.getParameterMap(); for (Object o : params.keySet()) { String key = (String) o; if (key.startsWith("action_") && key.endsWith(".x")) { @@ -758,8 +752,7 @@ public class I2PSnarkServlet extends BasicServlet { if (torrent != null) { byte infoHash[] = Base64.decode(torrent); if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1 - for (Iterator iter = _manager.listTorrentFiles().iterator(); iter.hasNext(); ) { - String name = (String)iter.next(); + for (String name : _manager.listTorrentFiles() ) { Snark snark = _manager.getTorrent(name); if ( (snark != null) && (DataHelper.eq(infoHash, snark.getInfoHash())) ) { _manager.stopTorrent(snark, false); @@ -781,8 +774,7 @@ public class I2PSnarkServlet extends BasicServlet { if (torrent != null) { byte infoHash[] = Base64.decode(torrent); if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1 - for (Iterator iter = _manager.listTorrentFiles().iterator(); iter.hasNext(); ) { - String name = (String)iter.next(); + for (String name : _manager.listTorrentFiles() ) { Snark snark = _manager.getTorrent(name); if ( (snark != null) && (DataHelper.eq(infoHash, snark.getInfoHash())) ) { MetaInfo meta = snark.getMetaInfo(); @@ -809,8 +801,7 @@ public class I2PSnarkServlet extends BasicServlet { if (torrent != null) { byte infoHash[] = Base64.decode(torrent); if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1 - for (Iterator iter = _manager.listTorrentFiles().iterator(); iter.hasNext(); ) { - String name = (String)iter.next(); + for (String name : _manager.listTorrentFiles() ) { Snark snark = _manager.getTorrent(name); if ( (snark != null) && (DataHelper.eq(infoHash, snark.getInfoHash())) ) { MetaInfo meta = snark.getMetaInfo(); @@ -849,7 +840,7 @@ public class I2PSnarkServlet extends BasicServlet { } } // step 2 make Set of dirs with reverse sort - Set<File> dirs = new TreeSet(Collections.reverseOrder()); + Set<File> dirs = new TreeSet<File>(Collections.reverseOrder()); for (List<String> list : files) { for (int i = 1; i < list.size(); i++) { dirs.add(Storage.getFileFromNames(f, list.subList(0, i))); @@ -922,8 +913,8 @@ public class I2PSnarkServlet extends BasicServlet { if (announceURL.equals("none")) announceURL = null; _lastAnnounceURL = announceURL; - List<String> backupURLs = new ArrayList(); - Enumeration e = req.getParameterNames(); + List<String> backupURLs = new ArrayList<String>(); + Enumeration<?> e = req.getParameterNames(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (!(o instanceof String)) @@ -955,7 +946,7 @@ public class I2PSnarkServlet extends BasicServlet { _manager.addMessage(_("Error - Cannot mix private and public trackers in a torrent")); return; } - announceList = new ArrayList(backupURLs.size()); + announceList = new ArrayList<List<String>>(backupURLs.size()); for (String url : backupURLs) { announceList.add(Collections.singletonList(url)); } @@ -1017,10 +1008,10 @@ public class I2PSnarkServlet extends BasicServlet { if (action.equals(_("Delete selected")) || action.equals(_("Save tracker configuration"))) { boolean changed = false; Map<String, Tracker> trackers = _manager.getTrackerMap(); - List<String> removed = new ArrayList(); - List<String> open = new ArrayList(); - List<String> priv = new ArrayList(); - Enumeration e = req.getParameterNames(); + List<String> removed = new ArrayList<String>(); + List<String> open = new ArrayList<String>(); + List<String> priv = new ArrayList<String>(); + Enumeration<?> e = req.getParameterNames(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (!(o instanceof String)) @@ -1045,7 +1036,7 @@ public class I2PSnarkServlet extends BasicServlet { } open.removeAll(removed); - List<String> oldOpen = new ArrayList(_manager.util().getOpenTrackers()); + List<String> oldOpen = new ArrayList<String>(_manager.util().getOpenTrackers()); Collections.sort(oldOpen); Collections.sort(open); if (!open.equals(oldOpen)) @@ -1054,7 +1045,7 @@ public class I2PSnarkServlet extends BasicServlet { priv.removeAll(removed); // open trumps private priv.removeAll(open); - List<String> oldPriv = new ArrayList(_manager.getPrivateTrackers()); + List<String> oldPriv = new ArrayList<String>(_manager.getPrivateTrackers()); Collections.sort(oldPriv); Collections.sort(priv); if (!priv.equals(oldPriv)) @@ -1074,11 +1065,11 @@ public class I2PSnarkServlet extends BasicServlet { _manager.saveTrackerMap(); // open trumps private if (req.getParameter("_add_open_") != null) { - List newOpen = new ArrayList(_manager.util().getOpenTrackers()); + List<String> newOpen = new ArrayList<String>(_manager.util().getOpenTrackers()); newOpen.add(aurl); _manager.saveOpenTrackers(newOpen); } else if (req.getParameter("_add_private_") != null) { - List newPriv = new ArrayList(_manager.getPrivateTrackers()); + List<String> newPriv = new ArrayList<String>(_manager.getPrivateTrackers()); newPriv.add(aurl); _manager.savePrivateTrackers(newPriv); } @@ -1141,7 +1132,7 @@ public class I2PSnarkServlet extends BasicServlet { } private List<Snark> getSortedSnarks(HttpServletRequest req) { - ArrayList<Snark> rv = new ArrayList(_manager.getTorrents()); + ArrayList<Snark> rv = new ArrayList<Snark>(_manager.getTorrents()); Collections.sort(rv, new TorrentNameComparator()); return rv; } @@ -1916,7 +1907,7 @@ public class I2PSnarkServlet extends BasicServlet { //out.write("port: <input type=\"text\" name=\"eepPort\" value=\"" // + _manager.util().getEepProxyPort() + "\" size=\"5\" maxlength=\"5\" /><br>\n"); - Map<String, String> options = new TreeMap(_manager.util().getI2CPOptions()); + Map<String, String> options = new TreeMap<String, String>(_manager.util().getI2CPOptions()); out.write("<tr><td>"); out.write(_("Inbound Settings")); out.write(":<td>"); @@ -2212,7 +2203,7 @@ public class I2PSnarkServlet extends BasicServlet { * @return String of HTML or null if postParams != null * @since 0.7.14 */ - private String getListHTML(File r, String base, boolean parent, Map postParams) + private String getListHTML(File r, String base, boolean parent, Map<String, String[]> postParams) throws IOException { File[] ls = null; @@ -2388,7 +2379,7 @@ public class I2PSnarkServlet extends BasicServlet { .append(":</b> ") .append(formatSize(needed)); if (meta != null) { - List files = meta.getFiles(); + List<List<String>> files = meta.getFiles(); int fileCount = files != null ? files.size() : 1; buf.append(" <img alt=\"\" border=\"0\" src=\"" + _imgPath + "file.png\" > <b>") .append(_("Files")) @@ -2648,17 +2639,16 @@ public class I2PSnarkServlet extends BasicServlet { } /** @since 0.8.1 */ - private void savePriorities(Snark snark, Map postParams) { + private void savePriorities(Snark snark, Map<String, String[]> postParams) { Storage storage = snark.getStorage(); if (storage == null) return; - Set<Map.Entry> entries = postParams.entrySet(); - for (Map.Entry entry : entries) { - String key = (String)entry.getKey(); + for (Map.Entry<String, String[]> entry : postParams.entrySet()) { + String key = entry.getKey(); if (key.startsWith("pri.")) { try { String file = key.substring(4); - String val = ((String[])entry.getValue())[0]; // jetty arrays + String val = entry.getValue()[0]; // jetty arrays int pri = Integer.parseInt(val); storage.setPriority(file, pri); //System.err.println("Priority now " + pri + " for " + file); diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/InclusiveByteRange.java b/apps/i2psnark/java/src/org/klomp/snark/web/InclusiveByteRange.java index 17ae473a2a4c9d1eeb11a0f0e76b6b69e927eb47..e71e5e3bcc86e110fba4490a54916e98cc9fcec9 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/InclusiveByteRange.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/InclusiveByteRange.java @@ -73,7 +73,7 @@ public class InclusiveByteRange * @param size Size of the resource. * @return List of satisfiable ranges */ - public static List<InclusiveByteRange> satisfiableRanges(Enumeration headers, long size) + public static List<InclusiveByteRange> satisfiableRanges(Enumeration<?> headers, long size) { List<InclusiveByteRange> satRanges = null; @@ -128,7 +128,7 @@ public class InclusiveByteRange if (first < size) { if (satRanges == null) - satRanges = new ArrayList(4); + satRanges = new ArrayList<InclusiveByteRange>(4); InclusiveByteRange range = new InclusiveByteRange(first,last); satRanges.add(range); } diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/MimeTypes.java b/apps/i2psnark/java/src/org/klomp/snark/web/MimeTypes.java index e24764ff5e662eeda41684077fdbcf3aa234d9f4..f0b9af7dfdc8bd4a41f827c037f6de6ef8767a45 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/MimeTypes.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/MimeTypes.java @@ -21,8 +21,6 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.concurrent.ConcurrentHashMap; -import javax.servlet.ServletContext; - /* ------------------------------------------------------------ */ /** @@ -48,7 +46,7 @@ class MimeTypes private final Map<String, String> _mimeMap; public MimeTypes() { - _mimeMap = new ConcurrentHashMap(); + _mimeMap = new ConcurrentHashMap<String, String>(); } /* ------------------------------------------------------------ */ diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java index e48a6bc569759e0b2d389abe6205339a4748d63f..d2f75123005b422981158f7121423ab6d5f3fab4 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java @@ -366,7 +366,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging { * @since 0.9.1 */ public void setClientOptions(Properties opts) { - for (Iterator iter = _clientOptions.keySet().iterator(); iter.hasNext();) { + for (Iterator<Object> iter = _clientOptions.keySet().iterator(); iter.hasNext();) { Object key = iter.next(); if (!opts.containsKey(key)) iter.remove(); @@ -1667,8 +1667,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging { */ void routerDisconnected() { _log.error(getPrefix() + "Router disconnected - firing notification events"); - for (Iterator<ConnectionEventListener> iter = listeners.iterator(); iter.hasNext();) { - ConnectionEventListener lsnr = iter.next(); + for (ConnectionEventListener lsnr : listeners) { if (lsnr != null) lsnr.routerDisconnected(); } } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java index 8d5f4ff4baa13ddfd0cd8b230be6080b14a3dc23..5daa64935fc58ceb9438e4e5246178934f511fdd 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java @@ -16,7 +16,6 @@ import java.net.Socket; import java.net.SocketException; import java.net.SocketTimeoutException; import java.security.GeneralSecurityException; -import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; @@ -320,8 +319,8 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { synchronized (lock) { if (!forced && sockMgr.listSockets().size() != 0) { l.log("There are still active connections!"); - for (Iterator<I2PSocket> it = sockMgr.listSockets().iterator(); it.hasNext();) { - l.log("->" + it.next()); + for (I2PSocket skt : sockMgr.listSockets()) { + l.log("->" + skt); } return false; } @@ -365,7 +364,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { */ private void buildSocketMap(Properties props) { _socketMap.clear(); - for (Map.Entry e : props.entrySet()) { + for (Map.Entry<Object, Object> e : props.entrySet()) { String key = (String) e.getKey(); if (key.startsWith("targetForPort.")) { key = key.substring("targetForPort.".length()); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java index a02de79b2601cb58e91b8d52f81512c970b973fe..1b1fdefcfabf14576c874702e68ae93e5f56d407 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java @@ -413,7 +413,7 @@ public class TunnelController implements Logging { */ public Properties getClientOptionProps() { Properties opts = new Properties(); - for (Map.Entry e : _config.entrySet()) { + for (Map.Entry<Object, Object> e : _config.entrySet()) { String key = (String) e.getKey(); if (key.startsWith("option.")) { key = key.substring("option.".length()); @@ -471,7 +471,7 @@ public class TunnelController implements Logging { */ public void setConfig(Properties config, String prefix) { Properties props = new Properties(); - for (Map.Entry e : config.entrySet()) { + for (Map.Entry<Object, Object> e : config.entrySet()) { String key = (String) e.getKey(); if (key.startsWith(prefix)) { key = key.substring(prefix.length()); @@ -516,7 +516,7 @@ public class TunnelController implements Logging { */ public Properties getConfig(String prefix) { Properties rv = new Properties(); - for (Map.Entry e : _config.entrySet()) { + for (Map.Entry<Object, Object> e : _config.entrySet()) { String key = (String) e.getKey(); String val = (String) e.getValue(); rv.setProperty(prefix + key, val); @@ -538,7 +538,7 @@ public class TunnelController implements Logging { */ public String getClientOptions() { StringBuilder opts = new StringBuilder(64); - for (Map.Entry e : _config.entrySet()) { + for (Map.Entry<Object, Object> e : _config.entrySet()) { String key = (String) e.getKey(); if (key.startsWith("option.")) { key = key.substring("option.".length()); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/I2PSOCKSTunnel.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/I2PSOCKSTunnel.java index b66d613a8ced9f0545e75fb04e162f351737b179..f6df4a56b5fd2820e03f06f67b2fd8598b96331e 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/I2PSOCKSTunnel.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/I2PSOCKSTunnel.java @@ -70,7 +70,7 @@ public class I2PSOCKSTunnel extends I2PTunnelClientBase { private void parseOptions() { Properties opts = getTunnel().getClientOptions(); proxies = new HashMap<String, List<String>>(1); - for (Map.Entry e : opts.entrySet()) { + for (Map.Entry<Object, Object> e : opts.entrySet()) { String prop = (String)e.getKey(); if ((!prop.startsWith(PROP_PROXY_PREFIX)) || prop.length() <= PROP_PROXY_PREFIX.length()) continue; diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java index c3160b841980d1c2cce83ccbe53b75517bf8d827..6e917cf0c13725e81306fac0803a51a9e2c40e42 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java @@ -373,7 +373,7 @@ public class EditBean extends IndexBean { boolean isMD5Proxy = "httpclient".equals(tun.getType()) || "connectclient".equals(tun.getType()); Map<String, String> sorted = new TreeMap<String, String>(); - for (Map.Entry e : opts.entrySet()) { + for (Map.Entry<Object, Object> e : opts.entrySet()) { String key = (String)e.getKey(); if (_noShowSet.contains(key)) continue; diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java index 71199960cd7a7f80edfe8ad988b398c349e37d91..ebfb0c707f0fb86ff4fa4c6edf7d8b808588d975 100644 --- a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java +++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java @@ -5,7 +5,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Constructor; -import java.util.Iterator; import java.util.Map; import java.util.Properties; @@ -202,7 +201,7 @@ public class I2PSocketManagerFactory { if (opts == null) opts = new Properties(); Properties syscopy = (Properties) System.getProperties().clone(); - for (Map.Entry e : syscopy.entrySet()) { + for (Map.Entry<Object, Object> e : syscopy.entrySet()) { String name = (String) e.getKey(); if (!opts.containsKey(name)) opts.setProperty(name, (String) e.getValue()); diff --git a/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java b/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java index db883a65370469640c8c3552f589b4a79b45936a..b1141a66d580b0bee716ed33b5d99797da3a9385 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java @@ -1535,7 +1535,7 @@ public class ConsoleUpdateManager implements UpdateManager { } /** debug */ - private static void toString(StringBuilder buf, Collection col) { + private static void toString(StringBuilder buf, Collection<?> col) { List<String> list = new ArrayList<String>(col.size()); for (Object o : col) { list.add(o.toString()); @@ -1549,7 +1549,7 @@ public class ConsoleUpdateManager implements UpdateManager { /** debug */ private static void toString(StringBuilder buf, Map<?, ?> map) { List<String> list = new ArrayList<String>(map.size()); - for (Map.Entry entry : map.entrySet()) { + for (Map.Entry<?, ?> entry : map.entrySet()) { String key = entry.getKey().toString(); String val = entry.getValue().toString(); list.add("[" + key + "] = [" + val + "]<br>"); diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java index 9850bd383376b935ce8462bedd08a01b600d2fe4..9ae98ce991c4bfea63e0605a5fd142d23bbd3137 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java @@ -3,7 +3,6 @@ package net.i2p.router.web; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; -import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.Set; @@ -139,8 +138,7 @@ public class ConfigClientsHelper extends HelperBase { buf.append("<tr><th align=\"right\">" + _("WebApp") + "</th><th>" + _("Run at Startup?") + "</th><th>" + _("Control") + "</th><th align=\"left\">" + _("Description") + "</th></tr>\n"); Properties props = RouterConsoleRunner.webAppProperties(_context); Set<String> keys = new TreeSet(props.keySet()); - for (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) { - String name = iter.next(); + for (String name : keys) { if (name.startsWith(RouterConsoleRunner.PREFIX) && name.endsWith(RouterConsoleRunner.ENABLED)) { String app = name.substring(RouterConsoleRunner.PREFIX.length(), name.lastIndexOf(RouterConsoleRunner.ENABLED)); String val = props.getProperty(name); @@ -165,8 +163,7 @@ public class ConfigClientsHelper extends HelperBase { buf.append("<tr><th align=\"right\">" + _("Plugin") + "</th><th>" + _("Run at Startup?") + "</th><th>" + _("Control") + "</th><th align=\"left\">" + _("Description") + "</th></tr>\n"); Properties props = PluginStarter.pluginProperties(); Set<String> keys = new TreeSet(props.keySet()); - for (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) { - String name = iter.next(); + for (String name : keys) { if (name.startsWith(PluginStarter.PREFIX) && name.endsWith(PluginStarter.ENABLED)) { String app = name.substring(PluginStarter.PREFIX.length(), name.lastIndexOf(PluginStarter.ENABLED)); String val = props.getProperty(name); diff --git a/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java index 5dafe42a54df60b93e21f55094282b26e5343011..7fd1a30c7cb7b349b548bf74a5766bc19f33c220 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java @@ -418,8 +418,8 @@ public class NetDbRenderer { int cost = addr.getCost(); if (!((style.equals("SSU") && cost == 5) || (style.equals("NTCP") && cost == 10))) buf.append('[').append(_("cost")).append('=').append("" + cost).append("] "); - Map p = addr.getOptionsMap(); - for (Map.Entry e : (Set<Map.Entry>) p.entrySet()) { + Map<Object, Object> p = addr.getOptionsMap(); + for (Map.Entry<Object, Object> e : p.entrySet()) { String name = (String) e.getKey(); String val = (String) e.getValue(); buf.append('[').append(_(DataHelper.stripHTML(name))).append('=').append(DataHelper.stripHTML(val)).append("] "); @@ -428,8 +428,8 @@ public class NetDbRenderer { buf.append("</td></tr>\n"); if (full) { buf.append("<tr><td>" + _("Stats") + ": <br><code>"); - Map p = info.getOptionsMap(); - for (Map.Entry e : (Set<Map.Entry>) p.entrySet()) { + Map<Object, Object> p = info.getOptionsMap(); + for (Map.Entry<Object, Object> e : p.entrySet()) { String key = (String) e.getKey(); String val = (String) e.getValue(); buf.append(DataHelper.stripHTML(key)).append(" = ").append(DataHelper.stripHTML(val)).append("<br>\n"); diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java index 1f261b97dc89979b587222492bff5df1be5e095e..24633f495ccd21ffe2b8cd57ffcb6870f24a0bc9 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java @@ -832,7 +832,7 @@ public class PluginStarter implements Runnable { */ private static void addPath(URL u) throws Exception { URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); - Class urlClass = URLClassLoader.class; + Class<URLClassLoader> urlClass = URLClassLoader.class; Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class}); method.setAccessible(true); method.invoke(urlClassLoader, new Object[]{u}); diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java index 19cd5ed591f9ebac31d93430f00ea24802dd1758..276acd342aaaf48053e045f377bfaaeb415e2807 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.io.Writer; import java.text.DecimalFormat; import java.util.Comparator; -import java.util.Iterator; import java.util.Set; import java.util.TreeSet; @@ -45,8 +44,7 @@ class ProfileOrganizerRenderer { Set<PeerProfile> order = new TreeSet<PeerProfile>(mode == 2 ? new HashComparator() : new ProfileComparator()); int older = 0; int standard = 0; - for (Iterator<Hash> iter = peers.iterator(); iter.hasNext();) { - Hash peer = iter.next(); + for (Hash peer : peers) { if (_organizer.getUs().equals(peer)) continue; PeerProfile prof = _organizer.getProfile(peer); if (mode == 2) { @@ -94,8 +92,7 @@ class ProfileOrganizerRenderer { buf.append("<th> </th>"); buf.append("</tr>"); int prevTier = 1; - for (Iterator<PeerProfile> iter = order.iterator(); iter.hasNext();) { - PeerProfile prof = iter.next(); + for (PeerProfile prof : order) { Hash peer = prof.getPeer(); int tier = 0; @@ -217,8 +214,7 @@ class ProfileOrganizerRenderer { buf.append("<th class=\"smallhead\">").append(_("1d Fail Rate")).append("</th>"); buf.append("</tr>"); RateAverages ra = RateAverages.getTemp(); - for (Iterator<PeerProfile> iter = order.iterator(); iter.hasNext();) { - PeerProfile prof = iter.next(); + for (PeerProfile prof : order) { Hash peer = prof.getPeer(); buf.append("<tr><td align=\"center\" nowrap>"); diff --git a/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java index ac032e4974d6d3bf41d612831effa24e5bfcd3ef..a548cbe5980d568ba0f0ff1fdac577b891dc5ffc 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java @@ -7,7 +7,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeSet; @@ -417,8 +416,7 @@ public class SummaryHelper extends HelperBase { Collections.sort(clients, new AlphaComparator()); buf.append("<table>"); - for (Iterator<Destination> iter = clients.iterator(); iter.hasNext(); ) { - Destination client = iter.next(); + for (Destination client : clients) { String name = getName(client); Hash h = client.calculateHash(); diff --git a/apps/sam/java/src/net/i2p/sam/SAMBridge.java b/apps/sam/java/src/net/i2p/sam/SAMBridge.java index a528e7ae203f453f4093a1df1292d810bf9f192a..580f5e88ed35c36236d357110dcfbd73bea34485 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMBridge.java +++ b/apps/sam/java/src/net/i2p/sam/SAMBridge.java @@ -20,7 +20,6 @@ import java.nio.channels.SocketChannel; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.Properties; @@ -214,12 +213,12 @@ public class SAMBridge implements Runnable, ClientApp { private void loadKeys() { synchronized (nameToPrivKeys) { nameToPrivKeys.clear(); - FileInputStream in = null; + BufferedReader br = null; try { - in = new FileInputStream(persistFilename); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + br = new BufferedReader(new InputStreamReader( + new FileInputStream(persistFilename))); String line = null; - while ( (line = reader.readLine()) != null) { + while ( (line = br.readLine()) != null) { int eq = line.indexOf('='); String name = line.substring(0, eq); String privKeys = line.substring(eq+1); @@ -230,7 +229,7 @@ public class SAMBridge implements Runnable, ClientApp { } catch (IOException ioe) { _log.error("Unable to read the keys from " + persistFilename, ioe); } finally { - if (in != null) try { in.close(); } catch (IOException ioe) {} + if (br != null) try { br.close(); } catch (IOException ioe) {} } } } @@ -244,9 +243,9 @@ public class SAMBridge implements Runnable, ClientApp { FileOutputStream out = null; try { out = new FileOutputStream(persistFilename); - for (Iterator iter = nameToPrivKeys.keySet().iterator(); iter.hasNext(); ) { - String name = (String)iter.next(); - String privKeys = nameToPrivKeys.get(name); + for (Map.Entry<String, String> entry : nameToPrivKeys.entrySet()) { + String name = entry.getKey(); + String privKeys = entry.getValue(); out.write(name.getBytes()); out.write('='); out.write(privKeys.getBytes()); diff --git a/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java b/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java index 0c02f1e753b2f7d4e54d1436cbaf8c4f6459c8c7..50f1352fde3ce87b193b20d4f5fbad894b7a6e81 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java +++ b/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java @@ -381,15 +381,15 @@ public class SAMStreamSession { */ private void removeAllSocketHandlers() { Integer id; - Set keySet; - Iterator iter; + Set<Integer> keySet; + Iterator<Integer> iter; synchronized (handlersMapLock) { keySet = handlersMap.keySet(); iter = keySet.iterator(); while (iter.hasNext()) { - id = (Integer)iter.next(); + id = iter.next(); handlersMap.get(id).stopRunning(); sendersMap.get(id).shutDownGracefully(); } diff --git a/apps/sam/java/src/net/i2p/sam/SAMUtils.java b/apps/sam/java/src/net/i2p/sam/SAMUtils.java index 6497f4f1c79f1c68f063ba5fc82543bb6c1a6e81..2d8e867adb509cc95327dc53c715581e45cd7a06 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMUtils.java +++ b/apps/sam/java/src/net/i2p/sam/SAMUtils.java @@ -11,7 +11,7 @@ package net.i2p.sam; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.Enumeration; +import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; @@ -188,14 +188,13 @@ public class SAMUtils { /* Dump a Properties object in an human-readable form */ private static String dumpProperties(Properties props) { - Enumeration names = props.propertyNames(); StringBuilder builder = new StringBuilder(); String key, val; boolean firstIter = true; - while (names.hasMoreElements()) { - key = (String)names.nextElement(); - val = props.getProperty(key); + for (Map.Entry<Object, Object> entry : props.entrySet()) { + key = (String) entry.getKey(); + val = (String) entry.getValue(); if (!firstIter) { builder.append(";"); diff --git a/apps/sam/java/src/net/i2p/sam/SAMv3StreamSession.java b/apps/sam/java/src/net/i2p/sam/SAMv3StreamSession.java index 40e049b9be0b584d6e52ecd3dc83254b89665f02..c8c3361f803890bb2c692541ce40d68399d327d0 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMv3StreamSession.java +++ b/apps/sam/java/src/net/i2p/sam/SAMv3StreamSession.java @@ -8,7 +8,6 @@ package net.i2p.sam; * */ -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InterruptedIOException; import java.net.ConnectException; @@ -16,12 +15,9 @@ import java.net.NoRouteToHostException; import java.util.Properties; import net.i2p.I2PException; -import net.i2p.client.I2PClient; import net.i2p.client.streaming.I2PServerSocket; import net.i2p.client.streaming.I2PSocket; -import net.i2p.client.streaming.I2PSocketManagerFactory; import net.i2p.client.streaming.I2PSocketOptions; -import net.i2p.data.Base64; import net.i2p.data.DataFormatException; import net.i2p.data.Destination; import net.i2p.util.I2PAppThread; diff --git a/apps/streaming/java/src/net/i2p/client/streaming/Connection.java b/apps/streaming/java/src/net/i2p/client/streaming/Connection.java index db086d883f293f8cc8eb4adbb670260af63ad78c..9c2a9051f172afd8c158478b9ae6a2b57fa4514d 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/Connection.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/Connection.java @@ -15,7 +15,6 @@ import net.i2p.client.I2PSession; import net.i2p.data.DataHelper; import net.i2p.data.Destination; import net.i2p.util.Log; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; import net.i2p.util.SimpleTimer2; @@ -125,7 +124,7 @@ class Connection { // FIXME pass through a passive flush delay setting as the 4th arg _outputStream = new MessageOutputStream(_context, timer, _receiver, (opts == null ? Packet.MAX_PAYLOAD_SIZE : opts.getMaxMessageSize())); _timer = timer; - _outboundPackets = new TreeMap(); + _outboundPackets = new TreeMap<Long, PacketLocal>(); if (opts != null) { _localPort = opts.getLocalPort(); _remotePort = opts.getPort(); @@ -469,7 +468,7 @@ class Connection { } if (!nacked) { // aka ACKed if (acked == null) - acked = new ArrayList(8); + acked = new ArrayList<PacketLocal>(8); PacketLocal ackedPacket = e.getValue(); ackedPacket.ackReceived(); acked.add(ackedPacket); diff --git a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionHandler.java b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionHandler.java index 2c22b637147b07f980b795ce017f6d8d5c4cf728..2758735b99b3b7783f9cdeb5482347ead6cc6bb3 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionHandler.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionHandler.java @@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit; import net.i2p.I2PAppContext; import net.i2p.data.Destination; import net.i2p.util.Log; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; /** diff --git a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java index 9f2c5d5df10710a4c500bbad7f39481f7036560b..0e5b0dccbd1dad931665bbab1ca13ba02dc1c9c7 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java @@ -767,13 +767,13 @@ class ConnectionOptions extends I2PSocketOptionsImpl { // but avoid concurrent modification just in case Set<Hash> accessList, blackList; if (accessListEnabled) - accessList = new HashSet(); + accessList = new HashSet<Hash>(); else - accessList = Collections.EMPTY_SET; + accessList = Collections.emptySet(); if (blackListEnabled) - blackList = new HashSet(); + blackList = new HashSet<Hash>(); else - blackList = Collections.EMPTY_SET; + blackList = Collections.emptySet(); if (accessListEnabled || blackListEnabled) { String hashes = opts.getProperty(PROP_ACCESS_LIST); if (hashes == null) diff --git a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java index 011c9497f5ebc954ebfa3365131c604e0751add1..f758c749fd9fe1900e05d9865d3da86e93d69816 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java @@ -7,7 +7,6 @@ import net.i2p.I2PException; import net.i2p.data.DataHelper; import net.i2p.data.Destination; import net.i2p.util.Log; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; /** diff --git a/apps/streaming/java/src/net/i2p/client/streaming/MessageHandler.java b/apps/streaming/java/src/net/i2p/client/streaming/MessageHandler.java index 4aba07d31429ae246e7e0de160152d5a18bc70dc..63b15c8291f606195b55e9a4c6f0fc2e701d08e9 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/MessageHandler.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/MessageHandler.java @@ -1,6 +1,5 @@ package net.i2p.client.streaming; -import java.util.Iterator; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; @@ -8,6 +7,7 @@ import net.i2p.I2PAppContext; import net.i2p.client.I2PSession; import net.i2p.client.I2PSessionException; import net.i2p.client.I2PSessionMuxedListener; +import net.i2p.client.streaming.I2PSocketManager.DisconnectListener; import net.i2p.util.Log; /** @@ -25,7 +25,7 @@ class MessageHandler implements I2PSessionMuxedListener { public MessageHandler(I2PAppContext ctx, ConnectionManager mgr) { _manager = mgr; _context = ctx; - _listeners = new CopyOnWriteArraySet(); + _listeners = new CopyOnWriteArraySet<DisconnectListener>(); _log = ctx.logManager().getLog(MessageHandler.class); _context.statManager().createRateStat("stream.packetReceiveFailure", "When do we fail to decrypt or otherwise receive a packet sent to us?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 }); } @@ -93,8 +93,7 @@ class MessageHandler implements I2PSessionMuxedListener { _log.warn("I2PSession disconnected"); _manager.disconnectAllHard(); - for (Iterator<I2PSocketManager.DisconnectListener> iter = _listeners.iterator(); iter.hasNext(); ) { - I2PSocketManager.DisconnectListener lsnr = iter.next(); + for (I2PSocketManager.DisconnectListener lsnr : _listeners) { lsnr.sessionDisconnected(); } _listeners.clear(); diff --git a/apps/streaming/java/src/net/i2p/client/streaming/MessageInputStream.java b/apps/streaming/java/src/net/i2p/client/streaming/MessageInputStream.java index bcfb643956feb6fd9347807e15d0f0bc77ee7730..d062737308b1f28ffc0326b04dacea5b3b5f648d 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/MessageInputStream.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/MessageInputStream.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InterruptedIOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -63,11 +62,11 @@ class MessageInputStream extends InputStream { public MessageInputStream(I2PAppContext ctx) { _log = ctx.logManager().getLog(MessageInputStream.class); - _readyDataBlocks = new ArrayList(4); + _readyDataBlocks = new ArrayList<ByteArray>(4); _highestReadyBlockId = -1; _highestBlockId = -1; _readTimeout = -1; - _notYetReadyBlocks = new HashMap(4); + _notYetReadyBlocks = new HashMap<Long, ByteArray>(4); _dataLock = new Object(); //_cache = ByteCache.getInstance(128, Packet.MAX_PAYLOAD_SIZE); } @@ -110,7 +109,7 @@ class MessageInputStream extends InputStream { // ACK } else { if (ids == null) - ids = new ArrayList(4); + ids = new ArrayList<Long>(4); ids.add(l); } } diff --git a/apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java b/apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java index e528abe2c703f665dae3affa8214c9ea9bec97c0..7dd10c331d950341a851592493aa681520c8831c 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java @@ -2,8 +2,6 @@ package net.i2p.client.streaming; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.Set; - import net.i2p.I2PAppContext; import net.i2p.I2PException; import net.i2p.data.Destination; diff --git a/apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java b/apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java index 71b5d084b1c90d7e42df8a61c882950a895ffa2e..37ebb0f54f598dddf42a908176f2ffb2037060a5 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java @@ -8,6 +8,7 @@ import java.util.concurrent.atomic.AtomicInteger; import net.i2p.I2PAppContext; import net.i2p.data.Destination; import net.i2p.data.SessionKey; +import net.i2p.data.SessionTag; import net.i2p.util.Log; import net.i2p.util.SimpleTimer2; @@ -68,12 +69,12 @@ class PacketLocal extends Packet implements MessageOutputStream.WriteStatus { /** * @deprecated should always return null or an empty set */ - public Set getTagsSent() { return Collections.EMPTY_SET; } + public Set<SessionTag> getTagsSent() { return Collections.emptySet(); } /** * @deprecated I2PSession throws out the tags */ - public void setTagsSent(Set tags) { + public void setTagsSent(Set<SessionTag> tags) { if (tags != null && !tags.isEmpty()) _log.error("Who is sending tags thru the streaming lib? " + tags.size()); /**** diff --git a/apps/streaming/java/src/net/i2p/client/streaming/PcapWriter.java b/apps/streaming/java/src/net/i2p/client/streaming/PcapWriter.java index 00448f45d9d13e52fcb35368179403d18a581932..716f41ff8460a5cfefdcfcbb35811f12c1126bae 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/PcapWriter.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/PcapWriter.java @@ -9,7 +9,6 @@ import java.io.OutputStream; import net.i2p.I2PAppContext; import net.i2p.data.DataFormatException; import net.i2p.data.DataHelper; -import net.i2p.data.Hash; /** * Write a standard pcap file with a "TCP" packet that can be analyzed with diff --git a/apps/streaming/java/src/net/i2p/client/streaming/SchedulerChooser.java b/apps/streaming/java/src/net/i2p/client/streaming/SchedulerChooser.java index 1dd473907aa165f1e8e63a32c41a76e6722e0458..34195cc284f02b312277b9b684b1d569839c6780 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/SchedulerChooser.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/SchedulerChooser.java @@ -36,8 +36,8 @@ class SchedulerChooser { return _nullScheduler; } - private List createSchedulers() { - List rv = new ArrayList(8); + private List<TaskScheduler> createSchedulers() { + List<TaskScheduler> rv = new ArrayList<TaskScheduler>(8); rv.add(new SchedulerHardDisconnected(_context)); rv.add(new SchedulerPreconnect(_context)); rv.add(new SchedulerConnecting(_context)); diff --git a/apps/streaming/java/src/net/i2p/client/streaming/SchedulerImpl.java b/apps/streaming/java/src/net/i2p/client/streaming/SchedulerImpl.java index 5d042c9ff0ab5927004ce7c2f5ecda1c9c51400e..0b8c7fa8a43786d65d95e7ed627c13c3da80b3e1 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/SchedulerImpl.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/SchedulerImpl.java @@ -2,7 +2,6 @@ package net.i2p.client.streaming; import net.i2p.I2PAppContext; import net.i2p.util.Log; -import net.i2p.util.SimpleScheduler; /** * Base scheduler diff --git a/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectInactivityTest.java b/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectInactivityTest.java index 0b945037ccced7b258661de5c440d55f7ba26b14..2ef2338eaabc878d9092c20904f5b2e815cf5d82 100644 --- a/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectInactivityTest.java +++ b/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectInactivityTest.java @@ -6,7 +6,6 @@ import org.junit.Test; import net.i2p.I2PAppContext; -import net.i2p.client.I2PClient; import net.i2p.client.I2PSession; import net.i2p.util.Log; diff --git a/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTest.java b/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTest.java index c2c880c38a063d9c99e40e21b689506631de1868..4a9d32b1306bdd5ac033cc75054ec22f57631a1d 100644 --- a/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTest.java +++ b/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTest.java @@ -6,7 +6,6 @@ import org.junit.Before; import org.junit.Test; import net.i2p.I2PAppContext; -import net.i2p.client.I2PClient; import net.i2p.client.I2PSession; import net.i2p.util.Log; diff --git a/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTimeoutTest.java b/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTimeoutTest.java index c2d530a679d962f179ea7a6a6489016fe9e435b8..8bfffc5f5d909018f9f005cf1cebc01ba686dd08 100644 --- a/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTimeoutTest.java +++ b/apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTimeoutTest.java @@ -6,7 +6,6 @@ import java.util.Properties; import org.junit.Test; import net.i2p.I2PAppContext; -import net.i2p.client.I2PClient; import net.i2p.client.I2PClientFactory; import net.i2p.client.I2PSession; import net.i2p.data.Destination; diff --git a/apps/streaming/java/test/junit/net/i2p/client/streaming/EchoLargeTest.java b/apps/streaming/java/test/junit/net/i2p/client/streaming/EchoLargeTest.java index 72d136b9efe48bc052c65ebb246240a2012e3da9..52a643a8f623b9db0066bf0a689e8f39e210fe63 100644 --- a/apps/streaming/java/test/junit/net/i2p/client/streaming/EchoLargeTest.java +++ b/apps/streaming/java/test/junit/net/i2p/client/streaming/EchoLargeTest.java @@ -9,7 +9,6 @@ import org.junit.Test; import net.i2p.I2PAppContext; import net.i2p.client.I2PSession; -import net.i2p.data.Base64; import net.i2p.util.Log; /** diff --git a/apps/streaming/java/test/junit/net/i2p/client/streaming/MessageInputStreamTest.java b/apps/streaming/java/test/junit/net/i2p/client/streaming/MessageInputStreamTest.java index f42727248bcabb623404aa1f4ee9d58cff6b4eff..da9d08d8dc4442377d5065c5c2837e959c2f6198 100644 --- a/apps/streaming/java/test/junit/net/i2p/client/streaming/MessageInputStreamTest.java +++ b/apps/streaming/java/test/junit/net/i2p/client/streaming/MessageInputStreamTest.java @@ -59,7 +59,7 @@ public class MessageInputStreamTest extends TestCase { _context.random().nextBytes(orig); MessageInputStream in = new MessageInputStream(_context); - ArrayList order = new ArrayList(32); + ArrayList<Integer> order = new ArrayList<Integer>(32); for (int i = 0; i < orig.length / 1024; i++) order.add(new Integer(i)); Collections.shuffle(order); @@ -92,7 +92,7 @@ public class MessageInputStreamTest extends TestCase { MessageInputStream in = new MessageInputStream(_context); for (int n = 0; n < 3; n++) { - ArrayList order = new ArrayList(32); + ArrayList<Integer> order = new ArrayList<Integer>(32); for (int i = 0; i < orig.length / 1024; i++) order.add(new Integer(i)); Collections.shuffle(order); @@ -126,7 +126,7 @@ public class MessageInputStreamTest extends TestCase { _context.random().nextBytes(orig); MessageInputStream in = new MessageInputStream(_context); - ArrayList order = new ArrayList(32); + ArrayList<Integer> order = new ArrayList<Integer>(32); for (int i = 0; i < orig.length / 1024; i++) order.add(new Integer(i)); Collections.shuffle(order); diff --git a/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java b/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java index ebd0ee913f5ee006194075d1f7030ad11c5397af..b0a150bd1fe794f512142b8afa299cf67d80c633 100644 --- a/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java +++ b/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java @@ -30,9 +30,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Comparator; -import java.util.Enumeration; import java.util.LinkedList; import java.util.Locale; +import java.util.Map; import java.util.Properties; import net.i2p.data.DataFormatException; @@ -151,10 +151,9 @@ public class AddressbookBean extends BaseBean fis = new FileInputStream( getFileName() ); addressbook.load( fis ); LinkedList<AddressBean> list = new LinkedList<AddressBean>(); - Enumeration e = addressbook.keys(); - while( e.hasMoreElements() ) { - String name = (String)e.nextElement(); - String destination = addressbook.getProperty( name ); + for( Map.Entry<Object, Object> entry : addressbook.entrySet() ) { + String name = (String) entry.getKey(); + String destination = (String) entry.getValue(); if( filter != null && filter.length() > 0 ) { if( filter.compareTo( "0-9" ) == 0 ) { char first = name.charAt(0); diff --git a/apps/susidns/src/java/src/i2p/susi/dns/ConfigBean.java b/apps/susidns/src/java/src/i2p/susi/dns/ConfigBean.java index d74f94ff6a91678816068cac140e2f2c30470a41..faa5d09db37e3d94481348bcfd7b6e5b8792d93f 100644 --- a/apps/susidns/src/java/src/i2p/susi/dns/ConfigBean.java +++ b/apps/susidns/src/java/src/i2p/susi/dns/ConfigBean.java @@ -88,7 +88,7 @@ public class ConfigBean implements Serializable { // use loadProps to trim Properties props = new OrderedProperties(); DataHelper.loadProps(props, file); - for (Map.Entry e : props.entrySet()) { + for (Map.Entry<Object, Object> e : props.entrySet()) { buf.append((String) e.getKey()).append('=') .append((String) e.getValue()).append('\n'); } diff --git a/apps/susimail/src/src/i2p/susi/util/Folder.java b/apps/susimail/src/src/i2p/susi/util/Folder.java index c8cd9b7669d13f741cbea730a445abacc995b2b0..a6798c2afd79f11efbd695e3222bd02470d291a3 100644 --- a/apps/susimail/src/src/i2p/susi/util/Folder.java +++ b/apps/susimail/src/src/i2p/susi/util/Folder.java @@ -41,7 +41,7 @@ import java.util.Iterator; * * @author susi */ -public class Folder { +public class Folder<O extends Object> { public static final String PAGESIZE = "pager.pagesize"; public static final int DEFAULT_PAGESIZE = 10; @@ -50,10 +50,10 @@ public class Folder { public static final boolean UP = true; private int pages, pageSize, currentPage; - private Object[] unsortedElements, elements; - private Hashtable sorter; + private O[] unsortedElements, elements; + private Hashtable<String, Comparator<O>> sorter; private boolean sortingDirection; - Comparator currentSorter; + Comparator<O> currentSorter; public Folder() { @@ -61,7 +61,7 @@ public class Folder { pageSize = 0; currentPage = 1; unsortedElements = null; - sorter = new Hashtable(); + sorter = new Hashtable<String, Comparator<O>>(); sortingDirection = UP; currentSorter = null; } @@ -129,12 +129,13 @@ public class Folder { * @param source Array to copy. * @return Copy of source. */ - private Object[] copyArray( Object[] source ) + @SuppressWarnings("unchecked") + private O[] copyArray( O[] source ) { Object[] destination = new Object[source.length]; for( int i = 0; i < source.length; i++ ) destination[i] = source[i]; - return destination; + return (O[])destination; } /** * Recalculates variables. @@ -171,9 +172,9 @@ public class Folder { /** * Set the array of objects the folder should manage. * - * @param elements Array of Objects. + * @param elements Array of Os. */ - public void setElements( Object[] elements ) + public void setElements( O[] elements ) { this.unsortedElements = elements; if( currentSorter != null ) @@ -187,9 +188,9 @@ public class Folder { * Returns an iterator containing the elements on the current page. * @return Iterator containing the elements on the current page. */ - public Iterator currentPageIterator() + public Iterator<O> currentPageIterator() { - ArrayList list = new ArrayList(); + ArrayList<O> list = new ArrayList<O>(); if( elements != null ) { int pageSize = getPageSize(); int offset = ( currentPage - 1 ) * pageSize; @@ -249,7 +250,7 @@ public class Folder { * @param id ID to identify the Comparator with @link sortBy() * @param sorter a Comparator to sort the Array given by @link setElements() */ - public void addSorter( String id, Comparator sorter ) + public void addSorter( String id, Comparator<O> sorter ) { this.sorter.put( id, sorter ); } @@ -263,7 +264,7 @@ public class Folder { */ public void sortBy( String id ) { - currentSorter = (Comparator)sorter.get( id ); + currentSorter = sorter.get( id ); sort(); } @@ -273,9 +274,9 @@ public class Folder { * @param x Position of the element on the current page. * @return Element on the current page on the given position. */ - public Object getElementAtPosXonCurrentPage( int x ) + public O getElementAtPosXonCurrentPage( int x ) { - Object result = null; + O result = null; if( elements != null ) { int pageSize = getPageSize(); int offset = ( currentPage - 1 ) * pageSize; @@ -306,7 +307,7 @@ public class Folder { * * @return First element. */ - public Object getFirstElement() + public O getFirstElement() { /* * sorting direction is taken into account from getElement @@ -319,7 +320,7 @@ public class Folder { * * @return Last element. */ - public Object getLastElement() + public O getLastElement() { /* * sorting direction is taken into account from getElement @@ -333,7 +334,7 @@ public class Folder { * @param element * @return index */ - private int getIndexOf( Object element ) + private int getIndexOf( O element ) { if( elements != null ) { for( int i = 0; i < elements.length; i++ ) @@ -350,9 +351,9 @@ public class Folder { * @param element * @return The next element */ - public Object getNextElement( Object element ) + public O getNextElement( O element ) { - Object result = null; + O result = null; int i = getIndexOf( element ); @@ -371,9 +372,9 @@ public class Folder { * @param element * @return The previous element */ - public Object getPreviousElement( Object element ) + public O getPreviousElement( O element ) { - Object result = null; + O result = null; int i = getIndexOf( element ); @@ -390,9 +391,9 @@ public class Folder { * @param i * @return Element at index i */ - private Object getElement( int i ) + private O getElement( int i ) { - Object result = null; + O result = null; if( elements != null ) { if( sortingDirection == DOWN ) @@ -424,7 +425,7 @@ public class Folder { * * @param element */ - public boolean isLastElement( Object element ) + public boolean isLastElement( O element ) { if( elements == null ) return false; @@ -437,7 +438,7 @@ public class Folder { * * @param element */ - public boolean isFirstElement( Object element ) + public boolean isFirstElement( O element ) { if( elements == null ) return false; diff --git a/apps/susimail/src/src/i2p/susi/webmail/Mail.java b/apps/susimail/src/src/i2p/susi/webmail/Mail.java index 56be408b5536168631338342a55b6caa1df50361..4cd3cf729f338ebe218d2707abae7f4ee538397d 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/Mail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/Mail.java @@ -36,7 +36,6 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; -import java.util.Iterator; import java.util.Locale; /** @@ -143,10 +142,10 @@ public class Mail { } public static void appendRecipients( StringBuilder buf, ArrayList<String> recipients, String prefix ) { - for( Iterator<String> it = recipients.iterator(); it.hasNext(); ) { + for( String recipient : recipients ) { buf.append( prefix ); prefix ="\t"; - buf.append( it.next() ); + buf.append( recipient ); buf.append( "\r\n" ); } } diff --git a/apps/susimail/src/src/i2p/susi/webmail/RequestWrapper.java b/apps/susimail/src/src/i2p/susi/webmail/RequestWrapper.java index bf0f3519e8c7f6c5c3457b8895a9e78fb75d0df6..30e8bb44662f16aea6d603e6ddbf5268e6e766a1 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/RequestWrapper.java +++ b/apps/susimail/src/src/i2p/susi/webmail/RequestWrapper.java @@ -102,6 +102,7 @@ public class RequestWrapper { /** * @return List of request parameter names */ + @SuppressWarnings("unchecked") // TODO-Java6: Remove, type is correct public Enumeration<String> getParameterNames() { if( multiPartRequest != null ) { if( cachedParameterNames == null ) { diff --git a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java index 54e23c83edb7ea5e8b3622ea3457974da1faf0bc..bded822b3d30de9abed3265eaf659eb032bb23ed 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java @@ -49,7 +49,6 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.Enumeration; import java.util.Iterator; -import java.util.ListIterator; import java.util.Locale; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -316,7 +315,7 @@ public class WebMail extends HttpServlet int state, smtpPort; POP3MailBox mailbox; MailCache mailCache; - Folder folder; + Folder<String> folder; String user, pass, host, error, info; String replyTo, replyCC; String subject, body, showUIDL; @@ -413,8 +412,7 @@ public class WebMail extends HttpServlet if( mailPart.multipart ) { if( mailPart.type.compareTo( "multipart/alternative" ) == 0 ) { MailPart chosen = null; - for( ListIterator li = mailPart.parts.listIterator(); li.hasNext(); ) { - MailPart subPart = (MailPart)li.next(); + for( MailPart subPart : mailPart.parts ) { if( subPart.type != null && subPart.type.compareTo( "text/plain" ) == 0 ) chosen = subPart; } @@ -423,16 +421,14 @@ public class WebMail extends HttpServlet return; } } - for( ListIterator li = mailPart.parts.listIterator(); li.hasNext(); ) { - MailPart part = (MailPart)li.next(); + for( MailPart part : mailPart.parts ) { showPart( out, part, level + 1, html ); } } else if( mailPart.message ) { - for( ListIterator li = mailPart.parts.listIterator(); li.hasNext(); ) { - MailPart part = (MailPart)li.next(); + for( MailPart part : mailPart.parts ) { showPart( out, part, level + 1, html ); - } + } } else { boolean showBody = false; @@ -627,7 +623,7 @@ public class WebMail extends HttpServlet sessionObject.smtpPort = smtpPortNo; sessionObject.state = STATE_LIST; sessionObject.mailCache = new MailCache( sessionObject.mailbox ); - sessionObject.folder = new Folder(); + sessionObject.folder = new Folder<String>(); sessionObject.folder.setElements( sessionObject.mailbox.getUIDLs() ); sessionObject.folder.addSorter( SORT_ID, new IDSorter( sessionObject.mailCache ) ); sessionObject.folder.addSorter( SORT_SENDER, new SenderSorter( sessionObject.mailCache ) ); @@ -1052,8 +1048,8 @@ public class WebMail extends HttpServlet return part; if( part.multipart || part.message ) { - for( Iterator it = part.parts.iterator(); it.hasNext(); ) { - MailPart subPart = getMailPartFromHashCode( (MailPart)it.next(), hashCode ); + for( MailPart p : part.parts ) { + MailPart subPart = getMailPartFromHashCode( p, hashCode ); if( subPart != null ) return subPart; } @@ -1275,7 +1271,7 @@ public class WebMail extends HttpServlet if( sessionObject.state == STATE_LIST ) { processFolderButtons( sessionObject, request ); - for( Iterator it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) { + for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) { String uidl = (String)it.next(); Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FETCH_HEADER ); if( mail != null && mail.error.length() > 0 ) { @@ -1525,8 +1521,7 @@ public class WebMail extends HttpServlet } if( multipart ) { - for( Iterator it = sessionObject.attachments.iterator(); it.hasNext(); ) { - Attachment attachment = (Attachment)it.next(); + for( Attachment attachment : sessionObject.attachments ) { body.append( "\r\n--" + boundary + "\r\nContent-type: " + attachment.getContentType() + "\r\nContent-Disposition: attachment; filename=\"" + attachment.getFileName() + "\"\r\nContent-Transfer-Encoding: " + attachment.getTransferEncoding() + "\r\n\r\n" ); body.append( attachment.getData() ); } @@ -1620,12 +1615,11 @@ public class WebMail extends HttpServlet if( sessionObject.attachments != null && !sessionObject.attachments.isEmpty() ) { boolean wroteHeader = false; - for( Iterator it = sessionObject.attachments.iterator(); it.hasNext(); ) { + for( Attachment attachment : sessionObject.attachments ) { if( !wroteHeader ) { out.println( "<tr><td colspan=\"2\" align=\"center\">" + _("Attachments:") + "</td></tr>" ); wroteHeader = true; } - Attachment attachment = (Attachment)it.next(); out.println( "<tr><td colspan=\"2\" align=\"center\"><input type=\"checkbox\" class=\"optbox\" name=\"check" + attachment.hashCode() + "\" value=\"1\"> " + attachment.getFileName() + "</td></tr>"); } } @@ -1687,7 +1681,7 @@ public class WebMail extends HttpServlet thSpacer + "<th>" + sortHeader( SORT_SIZE, _("Size"), sessionObject.imgPath ) + "</th></tr>" ); int bg = 0; int i = 0; - for( Iterator it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) { + for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) { String uidl = (String)it.next(); Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FETCH_HEADER ); String link = "<a href=\"" + myself + "?" + SHOW + "=" + i + "\">"; diff --git a/apps/susimail/src/src/i2p/susi/webmail/encoding/Base64.java b/apps/susimail/src/src/i2p/susi/webmail/encoding/Base64.java index d866b210b9ef9b21c991bbe2cf3d2e0da17ad852..0709d6578f4b8875df531546fdffb89370e440fa 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/encoding/Base64.java +++ b/apps/susimail/src/src/i2p/susi/webmail/encoding/Base64.java @@ -28,7 +28,6 @@ import i2p.susi.util.ReadBuffer; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.StringBufferInputStream; /** * @author susi @@ -58,7 +57,7 @@ public class Base64 implements Encoding { */ public String encode(String str) throws EncodingException { try { - return encode( new StringBufferInputStream( str ) ); + return encode( new ByteArrayInputStream( str.getBytes() ) ); }catch (IOException e) { throw new EncodingException( e.getMessage() ); } diff --git a/apps/susimail/src/src/i2p/susi/webmail/encoding/EncodingFactory.java b/apps/susimail/src/src/i2p/susi/webmail/encoding/EncodingFactory.java index 76723ef910057d37d41a7753281e560a526e16df..fbc6d1a4b86223455253f87acf722e150af28a4f 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/encoding/EncodingFactory.java +++ b/apps/susimail/src/src/i2p/susi/webmail/encoding/EncodingFactory.java @@ -46,7 +46,7 @@ public class EncodingFactory { String[] classNames = list.split( ";" ); for( int i = 0; i < classNames.length; i++ ) { try { - Class c = Class.forName( classNames[i] ); + Class<?> c = Class.forName( classNames[i] ); Encoding e = (Encoding)c.newInstance(); encodings.put( e.getName(), e ); Debug.debug( Debug.DEBUG, "Registered " + e.getClass().getName() ); diff --git a/apps/susimail/src/src/i2p/susi/webmail/encoding/HeaderLine.java b/apps/susimail/src/src/i2p/susi/webmail/encoding/HeaderLine.java index 96dab529520a2d5870ef862191235166eff70c72..8ce8a8e4dda6fb9085a927ae757017cb1b4e36dd 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/encoding/HeaderLine.java +++ b/apps/susimail/src/src/i2p/susi/webmail/encoding/HeaderLine.java @@ -29,7 +29,6 @@ import i2p.susi.util.ReadBuffer; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.StringBufferInputStream; /** * @author susi @@ -47,7 +46,7 @@ public class HeaderLine implements Encoding { */ public String encode(String text) throws EncodingException { try { - return encode( new StringBufferInputStream( text ) ); + return encode( new ByteArrayInputStream( text.getBytes() ) ); } catch (IOException e) { throw new EncodingException( "IOException occured." ); } diff --git a/apps/susimail/src/src/i2p/susi/webmail/encoding/QuotedPrintable.java b/apps/susimail/src/src/i2p/susi/webmail/encoding/QuotedPrintable.java index 2194b24c0c0d939d17f4946d427dd74cb54015cd..fd7006f7a821ccffdfec9f2c2deb20b185a20acf 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/encoding/QuotedPrintable.java +++ b/apps/susimail/src/src/i2p/susi/webmail/encoding/QuotedPrintable.java @@ -29,7 +29,6 @@ import i2p.susi.util.ReadBuffer; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.StringBufferInputStream; /** * @author susi @@ -57,7 +56,7 @@ public class QuotedPrintable implements Encoding { */ public String encode(String text) throws EncodingException { try { - return encode( new StringBufferInputStream( text ) ); + return encode( new ByteArrayInputStream( text.getBytes() ) ); }catch (IOException e) { throw new EncodingException( "IOException occured." ); } diff --git a/apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java b/apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java index ad98213094ad4e3f41b6c60e315701320021da5d..e6a47cc0c2a5fe7a5cd1e340eefcd7ddad2c0dfb 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java +++ b/apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java @@ -59,8 +59,6 @@ public class POP3MailBox { private Object synchronizer = null; - private Object[] uidls = null; - /** * @param host * @param port @@ -275,7 +273,6 @@ public class POP3MailBox { uidlToID.clear(); uidlList.clear(); - uidls = null; readBuffer = sendCmdNa( "UIDL", DEFAULT_BUFSIZE ); if( readBuffer != null ) { @@ -295,7 +292,6 @@ public class POP3MailBox { } } } - uidls = uidlList.toArray(); } else { System.err.println( "Error getting UIDL list from pop3 server."); @@ -350,7 +346,6 @@ public class POP3MailBox { uidlList.clear(); uidlToID.clear(); sizes.clear(); - uidls = null; mails = 0; } /** @@ -649,7 +644,7 @@ public class POP3MailBox { private int getIDfromUIDL( String uidl ) { int result = -1; - Integer intObject = (Integer)uidlToID.get( uidl ); + Integer intObject = uidlToID.get( uidl ); if( intObject != null ) { result = intObject.intValue(); } @@ -662,15 +657,15 @@ public class POP3MailBox { */ public String getUIDLfromID( int id ) { - return (String)uidlList.get( id ); + return uidlList.get( id ); } /** * * @return A list of the available UIDLs. */ - public Object[] getUIDLs() + public String[] getUIDLs() { - return uidls; + return uidlList.toArray(new String[uidlList.size()]); } /** * diff --git a/core/java/findbugs-exclude.xml b/core/java/findbugs-exclude.xml new file mode 100644 index 0000000000000000000000000000000000000000..bdc50bdc9ca9520de593a9363b056bd132ef7edf --- /dev/null +++ b/core/java/findbugs-exclude.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<FindBugsFilter> + <Match> + <Class name="net.metanotion.io.block.index.BSkipSpan" /> + <Field name="nextPage" /> + <Bug pattern="UR_UNINIT_READ" /> + </Match> +</FindBugsFilter> diff --git a/core/java/src/net/i2p/I2PAppContext.java b/core/java/src/net/i2p/I2PAppContext.java index 9a45598f4b9dc8ace33c732aa800a1c492b9481c..136079fd025b232b972ba96175d7abf072c4b148 100644 --- a/core/java/src/net/i2p/I2PAppContext.java +++ b/core/java/src/net/i2p/I2PAppContext.java @@ -121,6 +121,7 @@ public class I2PAppContext { private final File _logDir; private final File _appDir; private volatile File _tmpDir; + private final Random _tmpDirRand = new Random(); // split up big lock on this to avoid deadlocks private final Object _lock1 = new Object(), _lock2 = new Object(), _lock3 = new Object(), _lock4 = new Object(), _lock5 = new Object(), _lock6 = new Object(), _lock7 = new Object(), _lock8 = new Object(), @@ -403,7 +404,7 @@ public class I2PAppContext { String d = getProperty("i2p.dir.temp", System.getProperty("java.io.tmpdir")); // our random() probably isn't warmed up yet byte[] rand = new byte[6]; - (new Random()).nextBytes(rand); + _tmpDirRand.nextBytes(rand); String f = "i2p-" + Base64.encode(rand) + ".tmp"; _tmpDir = new SecureDirectory(d, f); if (_tmpDir.exists()) { @@ -535,11 +536,12 @@ public class I2PAppContext { * * @return set of Strings containing the names of defined system properties */ - public Set<String> getPropertyNames() { + @SuppressWarnings({ "unchecked", "rawtypes" }) + public Set<String> getPropertyNames() { // clone to avoid ConcurrentModificationException - Set names = new HashSet(((Properties) System.getProperties().clone()).keySet()); + Set<String> names = new HashSet<String>((Set<String>) (Set) ((Properties) System.getProperties().clone()).keySet()); // TODO-Java6: s/keySet()/stringPropertyNames()/ if (_overrideProps != null) - names.addAll(_overrideProps.keySet()); + names.addAll((Set<String>) (Set) _overrideProps.keySet()); // TODO-Java6: s/keySet()/stringPropertyNames()/ return names; } diff --git a/core/java/src/net/i2p/client/I2PSessionImpl.java b/core/java/src/net/i2p/client/I2PSessionImpl.java index 465ff8a69ac585b8d551ee464e9344999a2fdca9..8cf7ad095e827365bdbd093f3a123d51443fcaf3 100644 --- a/core/java/src/net/i2p/client/I2PSessionImpl.java +++ b/core/java/src/net/i2p/client/I2PSessionImpl.java @@ -18,7 +18,6 @@ import java.net.Socket; import java.net.UnknownHostException; import java.security.GeneralSecurityException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; @@ -288,8 +287,8 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa /** save some memory, don't pass along the pointless properties */ private Properties filter(Properties options) { Properties rv = new Properties(); - for (Iterator iter = options.keySet().iterator(); iter.hasNext();) { - String key = (String) iter.next(); + for (Object oKey : options.keySet()) { // TODO-Java6: s/keySet()/stringPropertyNames()/ + String key = (String) oKey; if (key.startsWith("java.") || key.startsWith("user.") || key.startsWith("os.") || diff --git a/core/java/src/net/i2p/client/naming/MetaNamingService.java b/core/java/src/net/i2p/client/naming/MetaNamingService.java index 03e0ef7f9bc959e593de9ab2bd13562c108c1be4..fab433a8dfc35f59a255dfc1d7492022a0be8759 100644 --- a/core/java/src/net/i2p/client/naming/MetaNamingService.java +++ b/core/java/src/net/i2p/client/naming/MetaNamingService.java @@ -38,8 +38,8 @@ public class MetaNamingService extends DummyNamingService { _services = new CopyOnWriteArrayList<NamingService>(); while (tok.hasMoreTokens()) { try { - Class cls = Class.forName(tok.nextToken()); - Constructor con = cls.getConstructor(new Class[] { I2PAppContext.class }); + Class<?> cls = Class.forName(tok.nextToken()); + Constructor<?> con = cls.getConstructor(new Class[] { I2PAppContext.class }); addNamingService((NamingService)con.newInstance(new Object[] { context }), false); } catch (Exception ex) { } diff --git a/core/java/src/net/i2p/client/naming/NamingService.java b/core/java/src/net/i2p/client/naming/NamingService.java index ceade7e317cebf6a9112edb0e3e3ff23baa3440f..001cc421b9b44c32bcc358ea2f765892a64547e4 100644 --- a/core/java/src/net/i2p/client/naming/NamingService.java +++ b/core/java/src/net/i2p/client/naming/NamingService.java @@ -462,8 +462,8 @@ public abstract class NamingService { NamingService instance = null; String impl = context.getProperty(PROP_IMPL, DEFAULT_IMPL); try { - Class cls = Class.forName(impl); - Constructor con = cls.getConstructor(new Class[] { I2PAppContext.class }); + Class<?> cls = Class.forName(impl); + Constructor<?> con = cls.getConstructor(new Class[] { I2PAppContext.class }); instance = (NamingService)con.newInstance(new Object[] { context }); } catch (Exception ex) { Log log = context.logManager().getLog(NamingService.class); diff --git a/core/java/src/net/i2p/crypto/ECConstants.java b/core/java/src/net/i2p/crypto/ECConstants.java index a3d563f877139fe04f93f21e1bb37ecfa72f4d21..8487523b00afc9213c39c7ac5b212782724062fa 100644 --- a/core/java/src/net/i2p/crypto/ECConstants.java +++ b/core/java/src/net/i2p/crypto/ECConstants.java @@ -41,8 +41,8 @@ class ECConstants { boolean loaded; if (Security.getProvider("BC") == null) { try { - Class cls = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); - Constructor con = cls.getConstructor(new Class[0]); + Class<?> cls = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); + Constructor<?> con = cls.getConstructor(new Class[0]); Provider bc = (Provider)con.newInstance(new Object[0]); Security.addProvider(bc); log("Added BC provider"); diff --git a/core/java/src/net/i2p/crypto/TransientSessionKeyManager.java b/core/java/src/net/i2p/crypto/TransientSessionKeyManager.java index 8ebfdbf9030d98f902662004860778baab421eaf..4f4dba1e73c29ec41a9c5f825fcd56780c74c774 100644 --- a/core/java/src/net/i2p/crypto/TransientSessionKeyManager.java +++ b/core/java/src/net/i2p/crypto/TransientSessionKeyManager.java @@ -541,12 +541,10 @@ public class TransientSessionKeyManager extends SessionKeyManager { if (old != null) { // drop both old and tagSet tags synchronized (_inboundTagSets) { - for (Iterator<SessionTag> iter = old.getTags().iterator(); iter.hasNext(); ) { - SessionTag tag = iter.next(); + for (SessionTag tag : old.getTags()) { _inboundTagSets.remove(tag); } - for (Iterator<SessionTag> iter = sessionTags.iterator(); iter.hasNext(); ) { - SessionTag tag = iter.next(); + for (SessionTag tag : sessionTags) { _inboundTagSets.remove(tag); } } @@ -734,8 +732,7 @@ public class TransientSessionKeyManager extends SessionKeyManager { buf.append("<tr><td><b>Session key</b>: ").append(skey.toBase64()).append("</td>" + "<td><b># Sets:</b> ").append(sets.size()).append("</td></tr>" + "<tr><td colspan=\"2\"><ul>"); - for (Iterator<TagSet> siter = sets.iterator(); siter.hasNext();) { - TagSet ts = siter.next(); + for (TagSet ts : sets) { int size = ts.getTags().size(); total += size; buf.append("<li><b>ID: ").append(ts.getID()); @@ -1050,8 +1047,7 @@ public class TransientSessionKeyManager extends SessionKeyManager { public long getLastExpirationDate() { long last = 0; synchronized (_tagSets) { - for (Iterator<TagSet> iter = _tagSets.iterator(); iter.hasNext();) { - TagSet set = iter.next(); + for (TagSet set : _tagSets) { if ( (set.getDate() > last) && (!set.getTags().isEmpty()) ) last = set.getDate(); } diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index 83fe675ffff9799514f992cc3140ef869e7a931d..744dff36ea256e2e619ae7ea92933f9feab4ae90 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -226,7 +226,7 @@ public class DataHelper { p = props; } ByteArrayOutputStream baos = new ByteArrayOutputStream(p.size() * 64); - for (Map.Entry entry : p.entrySet()) { + for (Map.Entry<Object, Object> entry : p.entrySet()) { String key = (String) entry.getKey(); String val = (String) entry.getValue(); if (utf8) @@ -273,7 +273,7 @@ public class DataHelper { OrderedProperties p = new OrderedProperties(); p.putAll(props); ByteArrayOutputStream baos = new ByteArrayOutputStream(p.size() * 64); - for (Map.Entry entry : p.entrySet()) { + for (Map.Entry<Object, Object> entry : p.entrySet()) { String key = (String) entry.getKey(); String val = (String) entry.getValue(); writeStringUTF8(baos, key); @@ -367,7 +367,7 @@ public class DataHelper { * (unless the options param is an OrderedProperties) */ public static String toString(Properties options) { - return toString((Map) options); + return toString((Map<?, ?>) options); } /** @@ -378,7 +378,7 @@ public class DataHelper { public static String toString(Map<?, ?> options) { StringBuilder buf = new StringBuilder(); if (options != null) { - for (Map.Entry entry : options.entrySet()) { + for (Map.Entry<?, ?> entry : options.entrySet()) { String key = (String) entry.getKey(); String val = (String) entry.getValue(); buf.append("[").append(key).append("] = [").append(val).append("]"); @@ -470,7 +470,7 @@ public class DataHelper { try { out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(file), "UTF-8"))); out.println("# NOTE: This I2P config file must use UTF-8 encoding"); - for (Map.Entry entry : props.entrySet()) { + for (Map.Entry<Object, Object> entry : props.entrySet()) { String name = (String) entry.getKey(); String val = (String) entry.getValue(); if (name.contains("#") || @@ -497,10 +497,10 @@ public class DataHelper { * Pretty print the collection * */ - public static String toString(Collection col) { + public static String toString(Collection<?> col) { StringBuilder buf = new StringBuilder(); if (col != null) { - for (Iterator iter = col.iterator(); iter.hasNext();) { + for (Iterator<?> iter = col.iterator(); iter.hasNext();) { Object o = iter.next(); buf.append("[").append(o).append("]"); if (iter.hasNext()) buf.append(", "); @@ -964,12 +964,12 @@ public class DataHelper { * based on the value of each at each step along the way. * */ - public final static boolean eq(Collection lhs, Collection rhs) { + public final static boolean eq(Collection<?> lhs, Collection<?> rhs) { if ((lhs == null) && (rhs == null)) return true; if ((lhs == null) || (rhs == null)) return false; if (lhs.size() != rhs.size()) return false; - Iterator liter = lhs.iterator(); - Iterator riter = rhs.iterator(); + Iterator<?> liter = lhs.iterator(); + Iterator<?> riter = rhs.iterator(); while ((liter.hasNext()) && (riter.hasNext())) if (!(eq(liter.next(), riter.next()))) return false; return true; @@ -1132,10 +1132,10 @@ public class DataHelper { * Calculate the hashcode of the collection, using 0 for null * */ - public static int hashCode(Collection col) { + public static int hashCode(Collection<?> col) { if (col == null) return 0; int c = 0; - for (Iterator iter = col.iterator(); iter.hasNext();) + for (Iterator<?> iter = col.iterator(); iter.hasNext();) c = 7 * c + hashCode(iter.next()); return c; } diff --git a/core/java/src/net/i2p/data/PrivateKeyFile.java b/core/java/src/net/i2p/data/PrivateKeyFile.java index 2808f9a699b937024fc9d61cece9da05d89ca35a..f2535f6fe660412363326c7b959258b4b634b3d3 100644 --- a/core/java/src/net/i2p/data/PrivateKeyFile.java +++ b/core/java/src/net/i2p/data/PrivateKeyFile.java @@ -6,7 +6,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.util.Iterator; import java.util.Map; import java.util.Properties; @@ -402,8 +401,7 @@ public class PrivateKeyFile { System.out.println("Attempting to verify using " + sz + " hosts, this may take a while"); } - for (Iterator iter = hosts.entrySet().iterator(); iter.hasNext(); ) { - Map.Entry entry = (Map.Entry)iter.next(); + for (Map.Entry<Object, Object> entry : hosts.entrySet()) { String s = (String) entry.getValue(); Destination signer = new Destination(s); // make it go faster if we have the signerHash hint diff --git a/core/java/src/net/i2p/data/RouterAddress.java b/core/java/src/net/i2p/data/RouterAddress.java index 0b6fde6e0f0fa6871623664afc9b3209c732d308..4cdf3c554d7b633224ddc5bd0b425253e387b181 100644 --- a/core/java/src/net/i2p/data/RouterAddress.java +++ b/core/java/src/net/i2p/data/RouterAddress.java @@ -157,7 +157,7 @@ public class RouterAddress extends DataStructureImpl { * @return an unmodifiable view, non-null, sorted * @since 0.8.13 */ - public Map getOptionsMap() { + public Map<Object, Object> getOptionsMap() { return Collections.unmodifiableMap(_options); } @@ -324,7 +324,7 @@ public class RouterAddress extends DataStructureImpl { buf.append("\n\tCost: ").append(_cost); //buf.append("\n\tExpiration: ").append(_expiration); buf.append("\n\tOptions (").append(_options.size()).append("):"); - for (Map.Entry e : _options.entrySet()) { + for (Map.Entry<Object, Object> e : _options.entrySet()) { String key = (String) e.getKey(); String val = (String) e.getValue(); buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]"); diff --git a/core/java/src/net/i2p/data/RouterInfo.java b/core/java/src/net/i2p/data/RouterInfo.java index 72b54b8a96ec8a5002e5c4f9f72b28e90ace6926..214937815e164c26b0bbba686eb874b0514c88b7 100644 --- a/core/java/src/net/i2p/data/RouterInfo.java +++ b/core/java/src/net/i2p/data/RouterInfo.java @@ -244,7 +244,7 @@ public class RouterInfo extends DatabaseEntry { * @return an unmodifiable view, non-null, sorted * @since 0.8.13 */ - public Map getOptionsMap() { + public Map<Object, Object> getOptionsMap() { return Collections.unmodifiableMap(_options); } @@ -626,7 +626,7 @@ public class RouterInfo extends DatabaseEntry { } } buf.append("\n\tOptions (").append(_options.size()).append("):"); - for (Map.Entry e : _options.entrySet()) { + for (Map.Entry<Object, Object> e : _options.entrySet()) { String key = (String) e.getKey(); String val = (String) e.getValue(); buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]"); diff --git a/core/java/src/net/i2p/data/i2cp/SessionConfig.java b/core/java/src/net/i2p/data/i2cp/SessionConfig.java index ee5f898730d1c17fd891e736a12b02960c55cbdd..cd6db38e4edc9cb06d19a17287cfe9c073db1624 100644 --- a/core/java/src/net/i2p/data/i2cp/SessionConfig.java +++ b/core/java/src/net/i2p/data/i2cp/SessionConfig.java @@ -225,7 +225,7 @@ public class SessionConfig extends DataStructureImpl { buf.append("\n\tOptions: #: ").append(_options.size()); Properties sorted = new OrderedProperties(); sorted.putAll(_options); - for (Map.Entry e : sorted.entrySet()) { + for (Map.Entry<Object, Object> e : sorted.entrySet()) { String key = (String) e.getKey(); String val = (String) e.getValue(); buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]"); diff --git a/core/java/src/net/i2p/stat/StatManager.java b/core/java/src/net/i2p/stat/StatManager.java index d148bbe30481ee07916e503884814b5d2486e6d5..b8cf6c46666dd81f52a6317d77e1afabd4124d4c 100644 --- a/core/java/src/net/i2p/stat/StatManager.java +++ b/core/java/src/net/i2p/stat/StatManager.java @@ -2,7 +2,6 @@ package net.i2p.stat; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.SortedSet; @@ -63,8 +62,7 @@ public class StatManager { public StatLog getStatLog() { return _statLog; } public void setStatLog(StatLog log) { _statLog = log; - for (Iterator<RateStat> iter = _rateStats.values().iterator(); iter.hasNext(); ) { - RateStat rs = iter.next(); + for (RateStat rs : _rateStats.values()) { rs.setStatLog(log); } } @@ -168,8 +166,7 @@ public class StatManager { } } } - for (Iterator<RateStat> iter = _rateStats.values().iterator(); iter.hasNext();) { - RateStat stat = iter.next(); + for (RateStat stat : _rateStats.values()) { if (stat != null) { stat.coalesceStats(); } diff --git a/core/java/src/net/i2p/util/Clock.java b/core/java/src/net/i2p/util/Clock.java index 3efbbb7d69f1c45e72be6f3da2f4ae80b4d82a9c..294d3ffa6d51ff56974f3f0e54d5842fc3be3a7b 100644 --- a/core/java/src/net/i2p/util/Clock.java +++ b/core/java/src/net/i2p/util/Clock.java @@ -68,7 +68,6 @@ public class Clock implements Timestamper.UpdateListener { * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now()) */ public synchronized void setOffset(long offsetMs, boolean force) { - if (false) return; long delta = offsetMs - _offset; if (!force) { if ((offsetMs > MAX_OFFSET) || (offsetMs < 0 - MAX_OFFSET)) { @@ -113,7 +112,7 @@ public class Clock implements Timestamper.UpdateListener { /* * @return the current delta from System.currentTimeMillis() in milliseconds */ - public long getOffset() { + public synchronized long getOffset() { return _offset; } diff --git a/core/java/src/net/i2p/util/EepGet.java b/core/java/src/net/i2p/util/EepGet.java index 45dc5a2c6fba66bae16137c2738f6d2ad07475ec..92fef09968da7018f5cc8c093a353765d97e2097 100644 --- a/core/java/src/net/i2p/util/EepGet.java +++ b/core/java/src/net/i2p/util/EepGet.java @@ -384,6 +384,7 @@ public class EepGet { fmt.format("%7.2f", Double.valueOf(lifetimeKBps)); buf.append(" KBps"); System.out.println(buf.toString()); + fmt.close(); } _lastComplete = now; } diff --git a/core/java/src/net/i2p/util/FileUtil.java b/core/java/src/net/i2p/util/FileUtil.java index 382be5441616521b46ae62664cb04fec18061bc9..0e77b9eb183d7aed9ec3d84c7265e13f54b60e09 100644 --- a/core/java/src/net/i2p/util/FileUtil.java +++ b/core/java/src/net/i2p/util/FileUtil.java @@ -295,7 +295,7 @@ public class FileUtil { //Pack200.newUnpacker().unpack(in, out); if (!_failedOracle) { try { - Class p200 = Class.forName("java.util.jar.Pack200", true, ClassLoader.getSystemClassLoader()); + Class<?> p200 = Class.forName("java.util.jar.Pack200", true, ClassLoader.getSystemClassLoader()); Method newUnpacker = p200.getMethod("newUnpacker", (Class[]) null); Object unpacker = newUnpacker.invoke(null,(Object[]) null); Method unpack = unpacker.getClass().getMethod("unpack", new Class[] {InputStream.class, JarOutputStream.class}); @@ -316,8 +316,8 @@ public class FileUtil { //(new Archive(in, out)).unpack(); if (!_failedApache) { try { - Class p200 = Class.forName("org.apache.harmony.unpack200.Archive", true, ClassLoader.getSystemClassLoader()); - Constructor newUnpacker = p200.getConstructor(new Class[] {InputStream.class, JarOutputStream.class}); + Class<?> p200 = Class.forName("org.apache.harmony.unpack200.Archive", true, ClassLoader.getSystemClassLoader()); + Constructor<?> newUnpacker = p200.getConstructor(new Class[] {InputStream.class, JarOutputStream.class}); Object unpacker = newUnpacker.newInstance(new Object[] {in, out}); Method unpack = unpacker.getClass().getMethod("unpack", (Class[]) null); // throws IOException or Pack200Exception diff --git a/core/java/src/net/i2p/util/Log.java b/core/java/src/net/i2p/util/Log.java index 42f54b06aa0fe8cdeaae12b6a3c0df2330ac0962..5f6d06e5197c0afddff421dcab6395419a76211b 100644 --- a/core/java/src/net/i2p/util/Log.java +++ b/core/java/src/net/i2p/util/Log.java @@ -25,7 +25,7 @@ import net.i2p.I2PAppContext; * @author jrandom */ public class Log { - private final Class _class; + private final Class<?> _class; private final String _className; private final String _name; private int _minPriority; @@ -75,7 +75,7 @@ public class Log { * Warning - not recommended. * Use I2PAppContext.getGlobalContext().logManager().getLog(cls) */ - public Log(Class cls) { + public Log(Class<?> cls) { this(I2PAppContext.getGlobalContext().logManager(), cls, null); _manager.addLog(this); } @@ -89,7 +89,7 @@ public class Log { _manager.addLog(this); } - Log(LogManager manager, Class cls) { + Log(LogManager manager, Class<?> cls) { this(manager, cls, null); } @@ -97,7 +97,7 @@ public class Log { this(manager, null, name); } - Log(LogManager manager, Class cls, String name) { + Log(LogManager manager, Class<?> cls, String name) { _manager = manager; _class = cls; _className = cls != null ? cls.getName() : null; @@ -229,7 +229,7 @@ public class Log { /** @return the LogScope (private class) */ public Object getScope() { return _scope; } - static String getScope(String name, Class cls) { + static String getScope(String name, Class<?> cls) { if ( (name == null) && (cls == null) ) return "f00"; if (cls == null) return name; if (name == null) return cls.getName(); @@ -239,7 +239,7 @@ public class Log { private static final class LogScope { private final String _scopeCache; - public LogScope(String name, Class cls) { + public LogScope(String name, Class<?> cls) { _scopeCache = getScope(name, cls); } diff --git a/core/java/src/net/i2p/util/LogManager.java b/core/java/src/net/i2p/util/LogManager.java index bb348229ded56bce5c78b5e7497dd424dcb2babc..871037b65d5b5f72ce7f95c818b1e54f6509811d 100644 --- a/core/java/src/net/i2p/util/LogManager.java +++ b/core/java/src/net/i2p/util/LogManager.java @@ -166,9 +166,9 @@ public class LogManager { t.start(); } - public Log getLog(Class cls) { return getLog(cls, null); } + public Log getLog(Class<?> cls) { return getLog(cls, null); } public Log getLog(String name) { return getLog(null, name); } - public Log getLog(Class cls, String name) { + public Log getLog(Class<?> cls, String name) { String scope = Log.getScope(name, cls); boolean isNew = false; Log rv = _logs.get(scope); @@ -186,7 +186,7 @@ public class LogManager { /** now used by ConfigLogingHelper */ public List<Log> getLogs() { - return new ArrayList(_logs.values()); + return new ArrayList<Log>(_logs.values()); } /** @@ -407,7 +407,7 @@ public class LogManager { private void parseLimits(Properties config, String recordPrefix) { _limits.clear(); if (config != null) { - for (Map.Entry e : config.entrySet()) { + for (Map.Entry<Object, Object> e : config.entrySet()) { String key = (String) e.getKey(); // if we're filtering the records (e.g. logger.record.*) then diff --git a/core/java/src/net/i2p/util/LogRecord.java b/core/java/src/net/i2p/util/LogRecord.java index cf6b34728f7c617d1a6bef7d1c0267f7a7828918..5d45314a861400b7bdb4d3788cb844e0903b2c15 100644 --- a/core/java/src/net/i2p/util/LogRecord.java +++ b/core/java/src/net/i2p/util/LogRecord.java @@ -15,14 +15,14 @@ package net.i2p.util; */ class LogRecord { private final long _date; - private final Class _source; + private final Class<?> _source; private final String _name; private final String _threadName; private final int _priority; private final String _message; private final Throwable _throwable; - public LogRecord(Class src, String name, String threadName, int priority, String msg, Throwable t) { + public LogRecord(Class<?> src, String name, String threadName, int priority, String msg, Throwable t) { _date = Clock.getInstance().now(); _source = src; _name = name; @@ -36,7 +36,7 @@ class LogRecord { return _date; } - public Class getSource() { + public Class<?> getSource() { return _source; } diff --git a/core/java/src/net/i2p/util/OrderedProperties.java b/core/java/src/net/i2p/util/OrderedProperties.java index 56323f267176b7f194898bcf978e5c9e9694743f..cce7b0e6832daa313139f067e8e2d4c92a78288d 100644 --- a/core/java/src/net/i2p/util/OrderedProperties.java +++ b/core/java/src/net/i2p/util/OrderedProperties.java @@ -35,19 +35,19 @@ public class OrderedProperties extends Properties { } @Override - public Set keySet() { - return Collections.unmodifiableSortedSet(new TreeSet(super.keySet())); + public Set<Object> keySet() { + return Collections.unmodifiableSortedSet(new TreeSet<Object>(super.keySet())); } @Override public Set<Map.Entry<Object, Object>> entrySet() { - TreeSet<Map.Entry<Object, Object>> rv = new TreeSet(new EntryComparator()); + TreeSet<Map.Entry<Object, Object>> rv = new TreeSet<Map.Entry<Object, Object>>(new EntryComparator()); rv.addAll(super.entrySet()); return Collections.unmodifiableSortedSet(rv); } - private static class EntryComparator implements Comparator<Map.Entry> { - public int compare(Map.Entry l, Map.Entry r) { + private static class EntryComparator implements Comparator<Map.Entry<Object, Object>> { + public int compare(Map.Entry<Object, Object> l, Map.Entry<Object, Object> r) { return ((String)l.getKey()).compareTo(((String)r.getKey())); } } diff --git a/core/java/src/net/i2p/util/SimpleTimer.java b/core/java/src/net/i2p/util/SimpleTimer.java index d4b537e584e9dba18c20369b467fb8c5061e4936..a5ad981f7be7202f5e4f68fb3bb9a15941e4cdfb 100644 --- a/core/java/src/net/i2p/util/SimpleTimer.java +++ b/core/java/src/net/i2p/util/SimpleTimer.java @@ -2,7 +2,6 @@ package net.i2p.util; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -155,8 +154,7 @@ public class SimpleTimer { if ( (_events.size() != _eventTimes.size()) ) { _log.error("Skewed events: " + _events.size() + " for " + _eventTimes.size()); - for (Iterator<TimedEvent> iter = _eventTimes.keySet().iterator(); iter.hasNext(); ) { - TimedEvent evt = iter.next(); + for (TimedEvent evt : _eventTimes.keySet()) { Long when = _eventTimes.get(evt); TimedEvent cur = _events.get(when); if (cur != evt) { diff --git a/core/java/src/net/i2p/util/SystemVersion.java b/core/java/src/net/i2p/util/SystemVersion.java index 80114d0a7e27582349637f54a2d40820484ccf6d..639bab00b653d8fc6e3837b08fc4e87c8e6d9398 100644 --- a/core/java/src/net/i2p/util/SystemVersion.java +++ b/core/java/src/net/i2p/util/SystemVersion.java @@ -47,7 +47,7 @@ public abstract class SystemVersion { int sdk = 0; if (_isAndroid) { try { - Class ver = Class.forName("android.os.Build.VERSION", true, ClassLoader.getSystemClassLoader()); + Class<?> ver = Class.forName("android.os.Build.VERSION", true, ClassLoader.getSystemClassLoader()); Field field = ver.getField("SDK_INT"); sdk = field.getInt(null); } catch (Exception e) {} diff --git a/core/java/test/junit/net/i2p/client/naming/BlockfileNamingServiceTest.java b/core/java/test/junit/net/i2p/client/naming/BlockfileNamingServiceTest.java index 3a3603692848b0aabd0d1a7edffdfde9a7d209ba..bc633934c9201515a64c4bd8f1474d0bc83a6c3a 100644 --- a/core/java/test/junit/net/i2p/client/naming/BlockfileNamingServiceTest.java +++ b/core/java/test/junit/net/i2p/client/naming/BlockfileNamingServiceTest.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; +import java.util.Set; import net.i2p.I2PAppContext; import net.i2p.data.DataHelper; @@ -22,7 +23,8 @@ public class BlockfileNamingServiceTest extends TestCase { List<String> _names; File hostsTxt, routerDir; - public void setUp() throws Exception { + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void setUp() throws Exception { I2PAppContext ctx = new I2PAppContext(); routerDir = ctx.getRouterDir(); @@ -31,7 +33,7 @@ public class BlockfileNamingServiceTest extends TestCase { Properties props = new Properties(); assertNotNull("test classpath not set correctly",is); DataHelper.loadProps(props, is, true); - _names = new ArrayList(props.keySet()); + _names = new ArrayList<String>((Set<String>) (Set) props.keySet()); // TODO-Java6: s/keySet()/stringPropertyNames()/ Collections.shuffle(_names); is.close(); diff --git a/core/java/test/junit/net/i2p/stat/SimpleStatDumper.java b/core/java/test/junit/net/i2p/stat/SimpleStatDumper.java index fd47800f228fe1fb8ea00fc34a0e2557ba184540..889820477e37a16d6e569fee6bbcce777fcc3185 100644 --- a/core/java/test/junit/net/i2p/stat/SimpleStatDumper.java +++ b/core/java/test/junit/net/i2p/stat/SimpleStatDumper.java @@ -1,7 +1,6 @@ package net.i2p.stat; import java.util.Arrays; -import java.util.Iterator; import java.util.Set; import java.util.TreeSet; @@ -22,8 +21,7 @@ public class SimpleStatDumper { private static void dumpFrequencies(I2PAppContext ctx, StringBuilder buf) { Set<String> frequencies = new TreeSet<String>(ctx.statManager().getFrequencyNames()); - for (Iterator<String> iter = frequencies.iterator(); iter.hasNext();) { - String name = iter.next(); + for (String name : frequencies) { FrequencyStat freq = ctx.statManager().getFrequency(name); buf.append('\n'); buf.append(freq.getGroupName()).append('.').append(freq.getName()).append(": ") @@ -42,8 +40,7 @@ public class SimpleStatDumper { private static void dumpRates(I2PAppContext ctx, StringBuilder buf) { Set<String> rates = new TreeSet<String>(ctx.statManager().getRateNames()); - for (Iterator<String> iter = rates.iterator(); iter.hasNext();) { - String name = iter.next(); + for (String name : rates) { RateStat rate = ctx.statManager().getRate(name); buf.append('\n'); buf.append(rate.getGroupName()).append('.').append(rate.getName()).append(": ") diff --git a/core/java/test/junit/net/i2p/stat/StatLogSplitter.java b/core/java/test/junit/net/i2p/stat/StatLogSplitter.java deleted file mode 100644 index 4e4c53a47ad50203d688df7359919d9415e70e92..0000000000000000000000000000000000000000 --- a/core/java/test/junit/net/i2p/stat/StatLogSplitter.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.i2p.stat; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - - -/** - * Simple CLI to splot the stat logs into per-stat files containing - * #seconds since beginning and the value (ready for loading into your - * favorite plotting tool) - */ -public class StatLogSplitter { - private static final String DATE_FORMAT = "yyyyMMdd HH:mm:ss.SSS"; - private static SimpleDateFormat _fmt = new SimpleDateFormat(DATE_FORMAT); - public static void main(String args[]) { - if (args.length != 1) { - System.err.println("Usage: StatLogSplitter filename"); - return; - } - splitLog(args[0]); - } - - private static void splitLog(String filename) { - Map<String, FileWriter> outputFiles = new HashMap<String, FileWriter>(4); - try { - BufferedReader in = new BufferedReader(new FileReader(filename)); - String line; - long first = 0; - while ( (line = in.readLine()) != null) { - String date = line.substring(0, DATE_FORMAT.length()).trim(); - int endGroup = line.indexOf(' ', DATE_FORMAT.length()+1); - int endStat = line.indexOf(' ', endGroup+1); - int endValue = line.indexOf(' ', endStat+1); - String group = line.substring(DATE_FORMAT.length()+1, endGroup).trim(); - String stat = line.substring(endGroup, endStat).trim(); - String value = line.substring(endStat, endValue).trim(); - String duration = line.substring(endValue).trim(); - //System.out.println(date + " " + group + " " + stat + " " + value + " " + duration); - - try { - Date when = _fmt.parse(date); - if (first <= 0) first = when.getTime(); - long val = Long.parseLong(value); - long time = Long.parseLong(duration); - if (!outputFiles.containsKey(stat)) { - outputFiles.put(stat, new FileWriter(stat + ".dat")); - System.out.println("Including data to " + stat + ".dat"); - } - FileWriter out = (FileWriter)outputFiles.get(stat); - double s = (when.getTime()-first)/1000.0; - //long s = when.getTime(); - out.write(s + " " + val + " [" + line + "]\n"); - out.flush(); - } catch (ParseException pe) { - continue; - } catch (NumberFormatException nfe){ - continue; - } - } - } catch (IOException ioe) { - ioe.printStackTrace(); - } - for (Iterator<FileWriter> iter = outputFiles.values().iterator(); iter.hasNext(); ) { - FileWriter out = iter.next(); - try { out.close(); } catch (IOException ioe) {} - } - } -} diff --git a/router/java/src/net/i2p/router/Blocklist.java b/router/java/src/net/i2p/router/Blocklist.java index 4c3b8407b48188984d2bc0f714f19ae71e4c203e..9e711016dacb8b0555104cb3e870bf4ab581c248 100644 --- a/router/java/src/net/i2p/router/Blocklist.java +++ b/router/java/src/net/i2p/router/Blocklist.java @@ -137,8 +137,7 @@ public class Blocklist { return; } } - for (Iterator<Hash> iter = _peerBlocklist.keySet().iterator(); iter.hasNext(); ) { - Hash peer = iter.next(); + for (Hash peer : _peerBlocklist.keySet()) { String reason; String comment = _peerBlocklist.get(peer); if (comment != null) @@ -215,10 +214,10 @@ public class Blocklist { int badcount = 0; int peercount = 0; long ipcount = 0; - FileInputStream in = null; + BufferedReader br = null; try { - in = new FileInputStream(BLFile); - BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); + br = new BufferedReader(new InputStreamReader( + new FileInputStream(BLFile), "UTF-8")); String buf = null; while ((buf = br.readLine()) != null && count < maxSize) { Entry e = parse(buf, true); @@ -247,7 +246,7 @@ public class Blocklist { _log.log(Log.CRIT, "OOM reading the blocklist"); return; } finally { - if (in != null) try { in.close(); } catch (IOException ioe) {} + if (br != null) try { br.close(); } catch (IOException ioe) {} } if (_wrapSave != null) { @@ -405,10 +404,10 @@ public class Blocklist { private int getSize(File BLFile) { if ( (!BLFile.exists()) || (BLFile.length() <= 0) ) return 0; int lines = 0; - FileInputStream in = null; + BufferedReader br = null; try { - in = new FileInputStream(BLFile); - BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); + br = new BufferedReader(new InputStreamReader( + new FileInputStream(BLFile), "ISO-8859-1")); while (br.readLine() != null) { lines++; } @@ -417,7 +416,7 @@ public class Blocklist { _log.warn("Error reading the BLFile", ioe); return 0; } finally { - if (in != null) try { in.close(); } catch (IOException ioe) {} + if (br != null) try { br.close(); } catch (IOException ioe) {} } return lines; } @@ -770,10 +769,10 @@ public class Blocklist { for (Iterator<byte[]> iter = ips.iterator(); iter.hasNext(); ) { byte ip[] = iter.next(); int ipint = toInt(ip); - FileInputStream in = null; + BufferedReader br = null; try { - in = new FileInputStream(BLFile); - BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); + br = new BufferedReader(new InputStreamReader( + new FileInputStream(BLFile), "UTF-8")); String buf = null; // assume the file is unsorted, so go through the whole thing while ((buf = br.readLine()) != null) { @@ -782,7 +781,7 @@ public class Blocklist { continue; } if (match(ipint, toEntry(e.ip1, e.ip2))) { - try { in.close(); } catch (IOException ioe) {} + try { br.close(); } catch (IOException ioe) {} String reason = _x("IP banned by blocklist.txt entry {0}"); // only one translate parameter for now //for (int i = 0; i < 4; i++) { @@ -801,7 +800,7 @@ public class Blocklist { if (_log.shouldLog(Log.WARN)) _log.warn("Error reading the BLFile", ioe); } finally { - if (in != null) try { in.close(); } catch (IOException ioe) {} + if (br != null) try { br.close(); } catch (IOException ioe) {} } } // We already banlisted in banlist(peer), that's good enough diff --git a/router/java/src/net/i2p/router/ClientTunnelSettings.java b/router/java/src/net/i2p/router/ClientTunnelSettings.java index ac8139ebe0750ac56e434e682a87704c475e6646..110e2e94a5088f865ceca641c6c6388e7b9ccd8f 100644 --- a/router/java/src/net/i2p/router/ClientTunnelSettings.java +++ b/router/java/src/net/i2p/router/ClientTunnelSettings.java @@ -8,7 +8,7 @@ package net.i2p.router; * */ -import java.util.Iterator; +import java.util.Map; import java.util.Properties; import net.i2p.data.Hash; @@ -49,9 +49,9 @@ public class ClientTunnelSettings { writeToProperties(p); buf.append("Client tunnel settings:\n"); buf.append("====================================\n"); - for (Iterator iter = p.keySet().iterator(); iter.hasNext(); ) { - String name = (String)iter.next(); - String val = p.getProperty(name); + for (Map.Entry<Object, Object> entry : p.entrySet()) { + String name = (String) entry.getKey(); + String val = (String) entry.getValue(); buf.append(name).append(" = [").append(val).append("]\n"); } buf.append("====================================\n"); diff --git a/router/java/src/net/i2p/router/JobQueue.java b/router/java/src/net/i2p/router/JobQueue.java index ffe74725afb617f855f77fce670b688cef0784ed..f5578cc179a11bdc217919fc64af6fb8501a958a 100644 --- a/router/java/src/net/i2p/router/JobQueue.java +++ b/router/java/src/net/i2p/router/JobQueue.java @@ -277,7 +277,7 @@ public class JobQueue { if (_maxWaitingJobs <= 0) return false; // dont ever drop jobs if (!_allowParallelOperation) return false; // dont drop during startup [duh] if (numReady > _maxWaitingJobs) { - Class cls = job.getClass(); + Class<? extends Job> cls = job.getClass(); // lets not try to drop too many tunnel messages... //if (cls == HandleTunnelMessageJob.class) // return true; diff --git a/router/java/src/net/i2p/router/MultiRouter.java b/router/java/src/net/i2p/router/MultiRouter.java index 8d5f381eac7081ab926b014bd41d23c11821dbd3..6e4346807397289b1ba03ba7f2912d7cd2ced4de 100644 --- a/router/java/src/net/i2p/router/MultiRouter.java +++ b/router/java/src/net/i2p/router/MultiRouter.java @@ -67,13 +67,16 @@ public class MultiRouter { Scanner scan = new Scanner(args[0]); if (!scan.hasNextInt()) { usage(); + scan.close(); return; } nbrRouters = scan.nextInt(); if (nbrRouters < 0) { usage(); + scan.close(); return; } + scan.close(); _out = System.out; diff --git a/router/java/src/net/i2p/router/OutNetMessage.java b/router/java/src/net/i2p/router/OutNetMessage.java index eb9815c5a4684fef6c6bdb3015c035914ec0c82e..25149b1f35ecfba42eba4e3a97121b066c781ddd 100644 --- a/router/java/src/net/i2p/router/OutNetMessage.java +++ b/router/java/src/net/i2p/router/OutNetMessage.java @@ -151,7 +151,7 @@ public class OutNetMessage implements CDPQEntry { if (_log.shouldLog(Log.INFO)) { synchronized (this) { locked_initTimestamps(); - return (Map<String, Long>)_timestamps.clone(); + return new HashMap<String, Long>(_timestamps); } } return Collections.emptyMap(); diff --git a/router/java/src/net/i2p/router/PersistentKeyRing.java b/router/java/src/net/i2p/router/PersistentKeyRing.java index 1a8ec464cfd0028a4f997ab2260edbcabce36e1d..771d204e356ac7311819aea13bb41880f7268b76 100644 --- a/router/java/src/net/i2p/router/PersistentKeyRing.java +++ b/router/java/src/net/i2p/router/PersistentKeyRing.java @@ -3,8 +3,6 @@ package net.i2p.router; import java.io.IOException; import java.io.Writer; -import java.util.Iterator; - import net.i2p.data.DataFormatException; import net.i2p.data.Destination; import net.i2p.data.Hash; @@ -43,8 +41,7 @@ public class PersistentKeyRing extends KeyRing { } private void addFromProperties() { - for (Iterator iter = _ctx.getPropertyNames().iterator(); iter.hasNext(); ) { - String prop = (String) iter.next(); + for (String prop : _ctx.getPropertyNames()) { if (!prop.startsWith(PROP_PFX)) continue; String key = _ctx.getProperty(prop); diff --git a/router/java/src/net/i2p/router/TunnelPoolSettings.java b/router/java/src/net/i2p/router/TunnelPoolSettings.java index 1c52e3f7086cd45c0d4cb32451b9e2d0c83a00d6..48a2f1d00687487c761ed16235bcb843123d6ce7 100644 --- a/router/java/src/net/i2p/router/TunnelPoolSettings.java +++ b/router/java/src/net/i2p/router/TunnelPoolSettings.java @@ -201,7 +201,7 @@ public class TunnelPoolSettings { * @param prefix non-null */ public void readFromProperties(String prefix, Map<Object, Object> props) { - for (Map.Entry e : props.entrySet()) { + for (Map.Entry<Object, Object> e : props.entrySet()) { String name = (String) e.getKey(); String value = (String) e.getValue(); if (name.startsWith(prefix)) { @@ -250,7 +250,7 @@ public class TunnelPoolSettings { props.setProperty(prefix + PROP_IP_RESTRICTION, ""+_IPRestriction); if (!_isInbound) props.setProperty(prefix + PROP_PRIORITY, Integer.toString(_priority)); - for (Map.Entry e : _unknownOptions.entrySet()) { + for (Map.Entry<Object, Object> e : _unknownOptions.entrySet()) { String name = (String) e.getKey(); String val = (String) e.getValue(); props.setProperty(prefix + name, val); @@ -264,7 +264,7 @@ public class TunnelPoolSettings { writeToProperties("", p); buf.append("Tunnel pool settings:\n"); buf.append("====================================\n"); - for (Map.Entry e : p.entrySet()) { + for (Map.Entry<Object, Object> e : p.entrySet()) { String name = (String) e.getKey(); String val = (String) e.getValue(); buf.append(name).append(" = [").append(val).append("]\n"); diff --git a/router/java/src/net/i2p/router/client/ClientManager.java b/router/java/src/net/i2p/router/client/ClientManager.java index 5ad45279568389151f0906458b900f4a04459014..02b60d3e3b97900f91305005ab4da83f7ebdcffb 100644 --- a/router/java/src/net/i2p/router/client/ClientManager.java +++ b/router/java/src/net/i2p/router/client/ClientManager.java @@ -12,7 +12,6 @@ import java.io.IOException; import java.io.Writer; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.concurrent.LinkedBlockingQueue; @@ -125,19 +124,16 @@ class ClientManager { _listener.stopListening(); Set<ClientConnectionRunner> runners = new HashSet<ClientConnectionRunner>(); synchronized (_runners) { - for (Iterator<ClientConnectionRunner> iter = _runners.values().iterator(); iter.hasNext();) { - ClientConnectionRunner runner = iter.next(); + for (ClientConnectionRunner runner : _runners.values()) { runners.add(runner); } } synchronized (_pendingRunners) { - for (Iterator<ClientConnectionRunner> iter = _pendingRunners.iterator(); iter.hasNext();) { - ClientConnectionRunner runner = iter.next(); + for (ClientConnectionRunner runner : _pendingRunners) { runners.add(runner); } } - for (Iterator<ClientConnectionRunner> iter = runners.iterator(); iter.hasNext(); ) { - ClientConnectionRunner runner = iter.next(); + for (ClientConnectionRunner runner : runners) { runner.disconnectClient(msg, Log.WARN); } _runnersByHash.clear(); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java index c07f3de9be505e84a0cb4c307b1767f49ad8cdf3..9f730d72d3e661c70c770bf7f4c9c99733a86829 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java @@ -3,7 +3,6 @@ package net.i2p.router.networkdb.kademlia; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import net.i2p.data.Hash; @@ -216,8 +215,8 @@ class FloodOnlySearchJob extends FloodSearchJob { _log.info(getJobId() + ": Floodfill search for " + _key + " failed with " + timeRemaining + " remaining after " + time); } synchronized(_unheardFrom) { - for (Iterator<Hash> iter = _unheardFrom.iterator(); iter.hasNext(); ) - getContext().profileManager().dbLookupFailed(iter.next()); + for (Hash h : _unheardFrom) + getContext().profileManager().dbLookupFailed(h); } _facade.complete(_key); getContext().statManager().addRateData("netDb.failedTime", time, 0); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java index 868f0d0b880a9d2818566fe055b42a3db3e75bcb..f6cc0b1d5ab74f7101d13b9412c7ab57e2e470a8 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java @@ -383,8 +383,8 @@ class IterativeSearchJob extends FloodSearchJob { synchronized(this) { tries = _unheardFrom.size() + _failedPeers.size(); // blame the unheard-from (others already blamed in failed() above) - for (Iterator<Hash> iter = _unheardFrom.iterator(); iter.hasNext(); ) - getContext().profileManager().dbLookupFailed(iter.next()); + for (Hash h : _unheardFrom) + getContext().profileManager().dbLookupFailed(h); } long time = System.currentTimeMillis() - _created; if (_log.shouldLog(Log.INFO)) { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java b/router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java index 9a4f99c43b725819b3a8bd696e16af029216ebb8..b48b3320cdc8c5725e553b089a6395a657d54035 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java @@ -44,12 +44,12 @@ class SearchState { public Hash getTarget() { return _searchKey; } public Set<Hash> getPending() { synchronized (_pendingPeers) { - return (Set<Hash>)_pendingPeers.clone(); + return new HashSet<Hash>(_pendingPeers); } } public Set<Hash> getAttempted() { synchronized (_attemptedPeers) { - return (Set<Hash>)_attemptedPeers.clone(); + return new HashSet<Hash>(_attemptedPeers); } } public Set<Hash> getClosestAttempted(int max) { @@ -78,12 +78,12 @@ class SearchState { } public Set<Hash> getSuccessful() { synchronized (_successfulPeers) { - return (Set<Hash>)_successfulPeers.clone(); + return new HashSet<Hash>(_successfulPeers); } } public Set<Hash> getFailed() { synchronized (_failedPeers) { - return (Set<Hash>)_failedPeers.clone(); + return new HashSet<Hash>(_failedPeers); } } public boolean completed() { return _completed != -1; } @@ -155,7 +155,7 @@ class SearchState { } } - public Set<Hash> getRepliedPeers() { synchronized (_repliedPeers) { return (Set<Hash>)_repliedPeers.clone(); } } + public Set<Hash> getRepliedPeers() { synchronized (_repliedPeers) { return new HashSet<Hash>(_repliedPeers); } } public void replyTimeout(Hash peer) { synchronized (_pendingPeers) { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java index 72f6315aef4f5d5856048505ca64003a23753fa4..e4647b23e4219dbc66ad81997caa8274b80273c9 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java @@ -9,7 +9,6 @@ package net.i2p.router.networkdb.kademlia; */ import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -157,8 +156,7 @@ class StoreJob extends JobImpl { //_state.addPending(closestHashes); if (_log.shouldLog(Log.INFO)) _log.info(getJobId() + ": Continue sending key " + _state.getTarget() + " after " + _state.getAttempted().size() + " tries to " + closestHashes); - for (Iterator<Hash> iter = closestHashes.iterator(); iter.hasNext(); ) { - Hash peer = iter.next(); + for (Hash peer : closestHashes) { DatabaseEntry ds = _facade.getDataStore().get(peer); if ( (ds == null) || !(ds.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) ) { if (_log.shouldLog(Log.INFO)) diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/StoreState.java b/router/java/src/net/i2p/router/networkdb/kademlia/StoreState.java index b599186127e5bc50a69c58203c15de22fa7e62bd..cbe5037a81b26de322cd6003af17eb569fe272af 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/StoreState.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/StoreState.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -58,17 +57,17 @@ class StoreState { public DatabaseEntry getData() { return _data; } public Set<Hash> getPending() { synchronized (_pendingPeers) { - return (Set<Hash>)_pendingPeers.clone(); + return new HashSet<Hash>(_pendingPeers); } } public Set<Hash> getAttempted() { synchronized (_attemptedPeers) { - return (Set<Hash>)_attemptedPeers.clone(); + return new HashSet<Hash>(_attemptedPeers); } } public Set<Hash> getSuccessful() { synchronized (_successfulPeers) { - return (Set<Hash>)_successfulPeers.clone(); + return new HashSet<Hash>(_successfulPeers); } } /** unused */ @@ -82,7 +81,7 @@ class StoreState { public Set<Hash> getFailed() { synchronized (_failedPeers) { - return (Set<Hash>)_failedPeers.clone(); + return new HashSet<Hash>(_failedPeers); } } public boolean completed() { return _completed != -1; } @@ -124,8 +123,8 @@ class StoreState { public void addPending(Collection<Hash> pending) { synchronized (_pendingPeers) { _pendingPeers.addAll(pending); - for (Iterator<Hash> iter = pending.iterator(); iter.hasNext(); ) - _pendingPeerTimes.put(iter.next(), Long.valueOf(_context.clock().now())); + for (Hash peer : pending) + _pendingPeerTimes.put(peer, Long.valueOf(_context.clock().now())); } synchronized (_attemptedPeers) { _attemptedPeers.addAll(pending); @@ -191,32 +190,28 @@ class StoreState { buf.append(" Attempted: "); synchronized (_attemptedPeers) { buf.append(_attemptedPeers.size()).append(' '); - for (Iterator<Hash> iter = _attemptedPeers.iterator(); iter.hasNext(); ) { - Hash peer = iter.next(); + for (Hash peer : _attemptedPeers) { buf.append(peer.toBase64()).append(" "); } } buf.append(" Pending: "); synchronized (_pendingPeers) { buf.append(_pendingPeers.size()).append(' '); - for (Iterator<Hash> iter = _pendingPeers.iterator(); iter.hasNext(); ) { - Hash peer = iter.next(); + for (Hash peer : _pendingPeers) { buf.append(peer.toBase64()).append(" "); } } buf.append(" Failed: "); synchronized (_failedPeers) { buf.append(_failedPeers.size()).append(' '); - for (Iterator<Hash> iter = _failedPeers.iterator(); iter.hasNext(); ) { - Hash peer = iter.next(); + for (Hash peer : _failedPeers) { buf.append(peer.toBase64()).append(" "); } } buf.append(" Successful: "); synchronized (_successfulPeers) { buf.append(_successfulPeers.size()).append(' '); - for (Iterator<Hash> iter = _successfulPeers.iterator(); iter.hasNext(); ) { - Hash peer = iter.next(); + for (Hash peer : _successfulPeers) { buf.append(peer.toBase64()).append(" "); } } diff --git a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java index 4d5a6548c1656cc9156ba77ca445c4616dc435c9..1edfbe45d1b326561c18edfdcd9dfc0b279c0d8f 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java +++ b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java @@ -236,15 +236,13 @@ public class ProfileOrganizer { getReadLock(); try { - for (Iterator<PeerProfile> iter = _failingPeers.values().iterator(); iter.hasNext(); ) { - PeerProfile profile = iter.next(); + for (PeerProfile profile : _failingPeers.values()) { if (profile.getLastSendSuccessful() >= hideBefore) activePeers++; else if (profile.getLastHeardFrom() >= hideBefore) activePeers++; } - for (Iterator<PeerProfile> iter = _notFailingPeers.values().iterator(); iter.hasNext(); ) { - PeerProfile profile = iter.next(); + for (PeerProfile profile : _notFailingPeers.values()) { if (profile.getLastSendSuccessful() >= hideBefore) activePeers++; else if (profile.getLastHeardFrom() >= hideBefore) @@ -539,8 +537,7 @@ public class ProfileOrganizer { if (matches.size() < howMany) { getReadLock(); try { - for (Iterator<Hash> iter = _notFailingPeers.keySet().iterator(); iter.hasNext(); ) { - Hash peer = iter.next(); + for (Hash peer : _notFailingPeers.keySet()) { if (!_context.commSystem().isEstablished(peer)) exclude.add(peer); } @@ -567,8 +564,7 @@ public class ProfileOrganizer { Map<Hash, PeerProfile> activePeers = new HashMap<Hash, PeerProfile>(); getReadLock(); try { - for (Iterator<Map.Entry<Hash, PeerProfile>> iter = _notFailingPeers.entrySet().iterator(); iter.hasNext(); ) { - Map.Entry<Hash, PeerProfile> e = iter.next(); + for (Map.Entry<Hash, PeerProfile> e : _notFailingPeers.entrySet()) { if (_context.commSystem().isEstablished(e.getKey())) activePeers.put(e.getKey(), e.getValue()); } @@ -666,8 +662,7 @@ public class ProfileOrganizer { n = new ArrayList<Hash>(_notFailingPeers.keySet()); } finally { releaseReadLock(); } List<Hash> l = new ArrayList<Hash>(count / 4); - for (Iterator<Hash> iter = n.iterator(); iter.hasNext(); ) { - Hash peer = iter.next(); + for (Hash peer : n) { if (_context.commSystem().wasUnreachable(peer)) l.add(peer); else { @@ -717,8 +712,7 @@ public class ProfileOrganizer { long cutoff = _context.clock().now() - (20*1000); int count = _notFailingPeers.size(); List<Hash> l = new ArrayList<Hash>(count / 128); - for (Iterator<PeerProfile> iter = _notFailingPeers.values().iterator(); iter.hasNext(); ) { - PeerProfile prof = iter.next(); + for (PeerProfile prof : _notFailingPeers.values()) { if (prof.getTunnelHistory().getLastRejectedBandwidth() > cutoff) l.add(prof.getPeer()); } @@ -779,8 +773,7 @@ public class ProfileOrganizer { if (shouldCoalesce) { getReadLock(); try { - for (Iterator<PeerProfile> iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) { - PeerProfile prof = iter.next(); + for (PeerProfile prof : _strictCapacityOrder) { if ( (expireOlderThan > 0) && (prof.getLastSendSuccessful() <= expireOlderThan) ) { continue; } @@ -887,8 +880,7 @@ public class ProfileOrganizer { if (numToPromote > 0) { if (_log.shouldLog(Log.INFO)) _log.info("Need to explicitly promote " + numToPromote + " peers to the fast group"); - for (Iterator<PeerProfile> iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) { - PeerProfile cur = iter.next(); + for (PeerProfile cur : _strictCapacityOrder) { if ( (!_fastPeers.containsKey(cur.getPeer())) && (!cur.getIsFailing()) ) { if (!isSelectable(cur.getPeer())) { // skip peers we dont have in the netDb @@ -990,8 +982,7 @@ public class ProfileOrganizer { int needToUnfail = MIN_NOT_FAILING_ACTIVE - notFailingActive; if (needToUnfail > 0) { int unfailed = 0; - for (Iterator<PeerProfile> iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) { - PeerProfile best = iter.next(); + for (PeerProfile best : _strictCapacityOrder) { if ( (best.getIsActive()) && (best.getIsFailing()) ) { if (_log.shouldLog(Log.WARN)) _log.warn("All peers were failing, so we have overridden the failing flag for one of the most reliable active peers (" + best.getPeer().toBase64() + ")"); @@ -1022,9 +1013,7 @@ public class ProfileOrganizer { double totalCapacity = 0; double totalIntegration = 0; Set<PeerProfile> reordered = new TreeSet<PeerProfile>(_comp); - for (Iterator<PeerProfile> iter = allPeers.iterator(); iter.hasNext(); ) { - PeerProfile profile = iter.next(); - + for (PeerProfile profile : allPeers) { if (_us.equals(profile.getPeer())) continue; // only take into account active peers that aren't failing @@ -1072,8 +1061,7 @@ public class ProfileOrganizer { double thresholdAtMinHighCap = 0; double thresholdAtLowest = CapacityCalculator.GROWTH_FACTOR; int cur = 0; - for (Iterator<PeerProfile> iter = reordered.iterator(); iter.hasNext(); ) { - PeerProfile profile = iter.next(); + for (PeerProfile profile : reordered) { double val = profile.getCapacityValue(); if (val > meanCapacity) numExceedingMean++; @@ -1164,8 +1152,7 @@ public class ProfileOrganizer { private void locked_calculateSpeedThresholdMean(Set<PeerProfile> reordered) { double total = 0; int count = 0; - for (Iterator<PeerProfile> iter = reordered.iterator(); iter.hasNext(); ) { - PeerProfile profile = iter.next(); + for (PeerProfile profile : reordered) { if (profile.getCapacityValue() >= _thresholdCapacityValue) { // duplicates being clobbered is fine by us total += profile.getSpeedValue(); @@ -1524,8 +1511,7 @@ public class ProfileOrganizer { DecimalFormat fmt = new DecimalFormat("0,000.0"); fmt.setPositivePrefix("+"); - for (Iterator<Hash> iter = organizer.selectAllPeers().iterator(); iter.hasNext(); ) { - Hash peer = iter.next(); + for (Hash peer : organizer.selectAllPeers()) { PeerProfile profile = organizer.getProfile(peer); if (!profile.getIsActive()) { System.out.println("Peer " + profile.getPeer().toBase64().substring(0,4) diff --git a/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java b/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java index e34a71173ac06ac9095f9862ff6f3d866273fc3a..2cd538fe16ff0d9d8db684e3206170d400b70cb5 100644 --- a/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java +++ b/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java @@ -197,7 +197,7 @@ public class LoadClientAppsJob extends JobImpl { log.info("Loading up the client application " + clientName + ": " + className + " " + Arrays.toString(args)); if (args == null) args = new String[0]; - Class cls = Class.forName(className, true, cl); + Class<?> cls = Class.forName(className, true, cl); Method method = cls.getMethod("main", new Class[] { String[].class }); method.invoke(cls, new Object[] { args }); } @@ -264,15 +264,15 @@ public class LoadClientAppsJob extends JobImpl { public void run() { try { - Class cls = Class.forName(_className, true, _cl); + Class<?> cls = Class.forName(_className, true, _cl); if (isRouterApp(cls)) { - Constructor con = cls.getConstructor(RouterContext.class, ClientAppManager.class, String[].class); + Constructor<?> con = cls.getConstructor(RouterContext.class, ClientAppManager.class, String[].class); RouterAppManager mgr = _ctx.clientAppManager(); Object[] conArgs = new Object[] {_ctx, _ctx.clientAppManager(), _args}; RouterApp app = (RouterApp) con.newInstance(conArgs); mgr.addAndStart(app, _args); } else if (isClientApp(cls)) { - Constructor con = cls.getConstructor(I2PAppContext.class, ClientAppManager.class, String[].class); + Constructor<?> con = cls.getConstructor(I2PAppContext.class, ClientAppManager.class, String[].class); RouterAppManager mgr = _ctx.clientAppManager(); Object[] conArgs = new Object[] {_ctx, _ctx.clientAppManager(), _args}; ClientApp app = (ClientApp) con.newInstance(conArgs); @@ -288,17 +288,17 @@ public class LoadClientAppsJob extends JobImpl { _log.info("Done running client application " + _appName); } - private static boolean isRouterApp(Class cls) { + private static boolean isRouterApp(Class<?> cls) { return isInterface(cls, RouterApp.class); } - private static boolean isClientApp(Class cls) { + private static boolean isClientApp(Class<?> cls) { return isInterface(cls, ClientApp.class); } - private static boolean isInterface(Class cls, Class intfc) { + private static boolean isInterface(Class<?> cls, Class<?> intfc) { try { - Class[] intfcs = cls.getInterfaces(); + Class<?>[] intfcs = cls.getInterfaces(); for (int i = 0; i < intfcs.length; i++) { if (intfcs[i] == intfc) return true; diff --git a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java index 88ad248d7a5b3b1dc8ceef18ec48f33ccabf39a5..c99535548707b135d3e8bca87cd7b38511aafb8d 100644 --- a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java +++ b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java @@ -12,7 +12,6 @@ import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Vector; @@ -233,8 +232,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade { */ private class QueueAll implements SimpleTimer.TimedEvent { public void timeReached() { - for (Iterator<Hash> iter = _context.netDb().getAllRouters().iterator(); iter.hasNext(); ) { - RouterInfo ri = _context.netDb().lookupRouterInfoLocally(iter.next()); + for (Hash h : _context.netDb().getAllRouters()) { + RouterInfo ri = _context.netDb().lookupRouterInfoLocally(h); if (ri == null) continue; byte[] ip = getIP(ri); diff --git a/router/java/src/net/i2p/router/transport/GeoIP.java b/router/java/src/net/i2p/router/transport/GeoIP.java index cad3654c0298dcd309502e26dee25a56f14c2799..3f0990dd3bdfdf2bdebfe2094643ae75420777bd 100644 --- a/router/java/src/net/i2p/router/transport/GeoIP.java +++ b/router/java/src/net/i2p/router/transport/GeoIP.java @@ -194,10 +194,10 @@ class GeoIP { _log.warn("Country file not found: " + geoFile.getAbsolutePath()); return; } - FileInputStream in = null; + BufferedReader br = null; try { - in = new FileInputStream(geoFile); - BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); + br = new BufferedReader(new InputStreamReader( + new FileInputStream(geoFile), "UTF-8")); String line = null; while ( (line = br.readLine()) != null) { try { @@ -215,7 +215,7 @@ class GeoIP { if (_log.shouldLog(Log.ERROR)) _log.error("Error reading the Country File", ioe); } finally { - if (in != null) try { in.close(); } catch (IOException ioe) {} + if (br != null) try { br.close(); } catch (IOException ioe) {} } } @@ -256,11 +256,11 @@ class GeoIP { String[] rv = new String[search.length]; int idx = 0; long start = _context.clock().now(); - FileInputStream in = null; + BufferedReader br = null; try { - in = new FileInputStream(geoFile); String buf = null; - BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); + br = new BufferedReader(new InputStreamReader( + new FileInputStream(geoFile), "ISO-8859-1")); while ((buf = br.readLine()) != null && idx < search.length) { try { if (buf.charAt(0) == '#') { @@ -288,7 +288,7 @@ class GeoIP { if (_log.shouldLog(Log.ERROR)) _log.error("Error reading the geoFile", ioe); } finally { - if (in != null) try { in.close(); } catch (IOException ioe) {} + if (br != null) try { br.close(); } catch (IOException ioe) {} } if (_log.shouldLog(Log.INFO)) { diff --git a/router/java/src/net/i2p/router/transport/GeoIPv6.java b/router/java/src/net/i2p/router/transport/GeoIPv6.java index f26e33a7eb2042709c0e0c53991241b697b5fc27..b93e3f004f9536c471811a90cd553ea353c51c9d 100644 --- a/router/java/src/net/i2p/router/transport/GeoIPv6.java +++ b/router/java/src/net/i2p/router/transport/GeoIPv6.java @@ -158,12 +158,13 @@ class GeoIPv6 { for (File geoFile : inFiles) { int count = 0; InputStream in = null; + BufferedReader br = null; try { in = new BufferedInputStream(new FileInputStream(geoFile)); if (geoFile.getName().endsWith(".gz")) in = new GZIPInputStream(in); String buf = null; - BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); + br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); while ((buf = br.readLine()) != null) { try { if (buf.charAt(0) == '#') { @@ -191,6 +192,7 @@ class GeoIPv6 { return false; } finally { if (in != null) try { in.close(); } catch (IOException ioe) {} + if (br != null) try { br.close(); } catch (IOException ioe) {} } } Collections.sort(entries); diff --git a/router/java/src/net/i2p/router/transport/UPnP.java b/router/java/src/net/i2p/router/transport/UPnP.java index 3c69e4d2a45ce6fca63cd001deaafcda9bbe4595..582f92272500c5f3c7a352a223100a2f6e052b1a 100644 --- a/router/java/src/net/i2p/router/transport/UPnP.java +++ b/router/java/src/net/i2p/router/transport/UPnP.java @@ -280,8 +280,7 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener { */ private void discoverService() { synchronized (lock) { - for (Iterator iter = _router.getDeviceList().iterator();iter.hasNext();) { - Device current = (Device)iter.next(); + for (Device current : _router.getDeviceList()) { if (!current.getDeviceType().equals(WAN_DEVICE)) continue; diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPSendFinisher.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPSendFinisher.java index cdaec194784224811710b0822c074e4a076b90cb..d8441cbe701eed94a0da02bdb320dee88c9fa14a 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/NTCPSendFinisher.java +++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPSendFinisher.java @@ -69,7 +69,7 @@ class NTCPSendFinisher { public CustomThreadPoolExecutor(int num) { // use unbounded queue, so maximumPoolSize and keepAliveTime have no effect super(num, num, 1000, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue(), new CustomThreadFactory()); + new LinkedBlockingQueue<Runnable>(), new CustomThreadFactory()); } } diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java index 062e756861219e99a72ce27cdae83ca2129b1a96..63e9042dd348bf66d26e4559863b5fb53967931c 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java @@ -2114,8 +2114,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority public int countActivePeers() { long now = _context.clock().now(); int active = 0; - for (Iterator<PeerState> iter = _peersByIdent.values().iterator(); iter.hasNext(); ) { - PeerState peer = iter.next(); + for (PeerState peer : _peersByIdent.values()) { if (now-peer.getLastReceiveTime() <= 5*60*1000) active++; } @@ -2126,8 +2125,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority public int countActiveSendPeers() { long now = _context.clock().now(); int active = 0; - for (Iterator<PeerState> iter = _peersByIdent.values().iterator(); iter.hasNext(); ) { - PeerState peer = iter.next(); + for (PeerState peer : _peersByIdent.values()) { if (now-peer.getLastSendFullyTime() <= 1*60*1000) active++; } diff --git a/router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java b/router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java index 2564ce3d795a4ec5f449ea20eacdd63e1d7fb946..e0581c884347698dde0c87a80fd355ec4c128af7 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java +++ b/router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java @@ -24,7 +24,7 @@ class ExploratoryPeerSelector extends TunnelPeerSelector { super(context); } - public List<Hash> selectPeers(TunnelPoolSettings settings) { + public List<Hash> selectPeers(TunnelPoolSettings settings) { Log l = ctx.logManager().getLog(getClass()); int length = getLength(settings); if (length < 0) { @@ -34,7 +34,7 @@ class ExploratoryPeerSelector extends TunnelPeerSelector { } if (false && shouldSelectExplicit(settings)) { - List rv = selectExplicit(settings, length); + List<Hash> rv = selectExplicit(settings, length); if (l.shouldLog(Log.DEBUG)) l.debug("Explicit peers selected: " + rv); return rv; diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java index 92e19dbebee6f9685d362c77180cb86d2b4e25a2..38a7e1253a8f9dab5d75619c831f87a7ba98e62f 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java @@ -6,7 +6,7 @@ import java.util.Comparator; import java.util.Date; import java.util.Iterator; import java.util.List; -import java.util.Map; +import java.util.Properties; import java.util.TreeSet; import net.i2p.data.Hash; @@ -123,7 +123,8 @@ public class TunnelPool { return; // don't override client specified settings } else { if (_settings.isExploratory()) { - Map props = _context.router().getConfigMap(); + Properties props = new Properties(); + props.putAll(_context.router().getConfigMap()); if (_settings.isInbound()) _settings.readFromProperties(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY, props); else diff --git a/router/java/src/net/i2p/router/util/EventLog.java b/router/java/src/net/i2p/router/util/EventLog.java index 1f07f7f7d689176bed8ca86f0c5922213a01a57d..1e6f166f8beccbafb41823b1062da6ccec895c76 100644 --- a/router/java/src/net/i2p/router/util/EventLog.java +++ b/router/java/src/net/i2p/router/util/EventLog.java @@ -3,7 +3,6 @@ package net.i2p.router.util; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.IOException; import java.io.OutputStream; @@ -116,10 +115,10 @@ public class EventLog { } } rv = new TreeMap<Long, String>(); - InputStream in = null; + BufferedReader br = null; try { - in = new FileInputStream(_file); - BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); + br = new BufferedReader(new InputStreamReader( + new FileInputStream(_file), "UTF-8")); String line = null; while ( (line = br.readLine()) != null) { try { @@ -141,7 +140,7 @@ public class EventLog { _cacheTime.put(event, Long.valueOf(since)); } catch (IOException ioe) { } finally { - if (in != null) try { in.close(); } catch (IOException ioe) {} + if (br != null) try { br.close(); } catch (IOException ioe) {} } return rv; } diff --git a/router/java/src/net/i2p/router/util/PriBlockingQueue.java b/router/java/src/net/i2p/router/util/PriBlockingQueue.java index 0aae2d3d40478eb0b7e8197943870b67957d710d..baf69814f8ba185ce8c749a39a4e3cfa17c4ab8f 100644 --- a/router/java/src/net/i2p/router/util/PriBlockingQueue.java +++ b/router/java/src/net/i2p/router/util/PriBlockingQueue.java @@ -34,7 +34,7 @@ public class PriBlockingQueue<E extends PQEntry> extends PriorityBlockingQueue<E * except when using put(), which is unbounded. */ public PriBlockingQueue(I2PAppContext ctx, String name, int initialCapacity) { - super(initialCapacity, new PriorityComparator()); + super(initialCapacity, new PriorityComparator<E>()); _context = ctx; _log = ctx.logManager().getLog(PriorityBlockingQueue.class); _name = name;