Changeset 289a8e7


Ignore:
Timestamp:
Dec 10, 2013 11:11:08 AM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3d9d722
Parents:
0db1314 (diff), 7d3aa33 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge of '3f93d2c09c89b5c68487c33fd700ef7c2feeeb61'

and 'b2c58f8462ab5c08682b711436c387b421bdd0c2'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/bencode/BEncoder.java

    r0db1314 r289a8e7  
    156156  }
    157157
    158   public static byte[] bencode(Map<String, Object> m)
     158  public static byte[] bencode(Map<?, ?> m)
    159159  {
    160160    try
     
    170170  }
    171171
    172   public static void bencode(Map<String, Object> m, OutputStream out) throws IOException
     172  public static void bencode(Map<?, ?> m, OutputStream out)
     173    throws IOException, IllegalArgumentException
    173174  {
    174175    out.write('d');
    175176
    176177    // Keys must be sorted. XXX - But is this the correct order?
    177     Set<String> s = m.keySet();
    178     List<String> l = new ArrayList<String>(s);
     178    Set<?> s = m.keySet();
     179    List<String> l = new ArrayList<String>(s.size());
     180    for (Object k : s) {
     181      // Keys must be Strings.
     182      if (String.class.isAssignableFrom(k.getClass()))
     183        l.add((String) k);
     184      else
     185        throw new IllegalArgumentException("Cannot bencode map: contains non-String key of type " + k.getClass());
     186    }
    179187    Collections.sort(l);
    180188
     
    182190    while(it.hasNext())
    183191      {
    184         // Keys must be Strings.
    185192        String key = it.next();
    186         Object value = m.get(key);
    187193        bencode(key, out);
    188         bencode(value, out);
     194        bencode(m.get(key), out);
    189195      }
    190196
Note: See TracChangeset for help on using the changeset viewer.