I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 289a8e7b authored by zzz's avatar zzz
Browse files

merge of '3f93d2c09c89b5c68487c33fd700ef7c2feeeb61'

     and 'b2c58f8462ab5c08682b711436c387b421bdd0c2'
parents 0db13145 7d3aa33c
No related branches found
No related tags found
No related merge requests found
...@@ -155,7 +155,7 @@ public class BEncoder ...@@ -155,7 +155,7 @@ public class BEncoder
out.write(bs); out.write(bs);
} }
public static byte[] bencode(Map<String, Object> m) public static byte[] bencode(Map<?, ?> m)
{ {
try try
{ {
...@@ -169,23 +169,29 @@ public class BEncoder ...@@ -169,23 +169,29 @@ public class BEncoder
} }
} }
public static void bencode(Map<String, Object> m, OutputStream out) throws IOException public static void bencode(Map<?, ?> m, OutputStream out)
throws IOException, IllegalArgumentException
{ {
out.write('d'); out.write('d');
// Keys must be sorted. XXX - But is this the correct order? // Keys must be sorted. XXX - But is this the correct order?
Set<String> s = m.keySet(); Set<?> s = m.keySet();
List<String> l = new ArrayList<String>(s); List<String> l = new ArrayList<String>(s.size());
for (Object k : s) {
// Keys must be Strings.
if (String.class.isAssignableFrom(k.getClass()))
l.add((String) k);
else
throw new IllegalArgumentException("Cannot bencode map: contains non-String key of type " + k.getClass());
}
Collections.sort(l); Collections.sort(l);
Iterator<String> it = l.iterator(); Iterator<String> it = l.iterator();
while(it.hasNext()) while(it.hasNext())
{ {
// Keys must be Strings.
String key = it.next(); String key = it.next();
Object value = m.get(key);
bencode(key, out); bencode(key, out);
bencode(value, out); bencode(m.get(key), out);
} }
out.write('e'); out.write('e');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment