@Test public void testParseDictionary() { checkParse(new TreeMap<>(), "de"); { SortedMap<String,Object> d = new TreeMap<>(); d.put("-", 404L); checkParse(d, "d1:-i404ee"); } { SortedMap<String,Object> d = new TreeMap<>(); d.put("010", "101"); d.put("yU", new LinkedList<>()); checkParse(d, "d3:0103:1012:yUlee"); } }
private Object parseDictionary() throws IOException { SortedMap<String,Object> result = new TreeMap<>(); while (true) { byte b = readByte(); if (b == 'e') break; String key = parseByteString(b); if (!result.isEmpty() && key.compareTo(result.lastKey()) <= 0) throw new IllegalArgumentException("Misordered dictionary key"); result.put(key, parseValue(readByte())); } return result; }
Bencode { private Object parseDictionary() throws IOException { SortedMap<String,Object> result = new TreeMap<>(); while (true) { byte b = readByte(); if (b == 'e') break; String key = parseByteString(b); if (!result.isEmpty() && key.compareTo(result.lastKey()) <= 0) throw new IllegalArgumentException("Misordered dictionary key"); result.put(key, parseValue(readByte())); } return result; } }
Bencode { private Object parseDictionary() throws IOException { SortedMap<String,Object> result = new TreeMap<>(); while (true) { byte b = readByte(); if (b == 'e') break; String key = parseByteString(b); if (!result.isEmpty() && key.compareTo(result.lastKey()) <= 0) throw new IllegalArgumentException("Misordered dictionary key"); result.put(key, parseValue(readByte())); } return result; } private  Bencode(InputStream in); }
Bencode { private Object parseDictionary() throws IOException { SortedMap<String,Object> result = new TreeMap<>(); while (true) { byte b = readByte(); if (b == 'e') break; String key = parseByteString(b); if (!result.isEmpty() && key.compareTo(result.lastKey()) <= 0) throw new IllegalArgumentException("Misordered dictionary key"); result.put(key, parseValue(readByte())); } return result; } private  Bencode(InputStream in); static void serialize(Object obj, OutputStream out); static Object parse(InputStream in); static byte[] byteStringToArray(String str); static String arrayToByteString(byte[] arr); }
Bencode { private Object parseDictionary() throws IOException { SortedMap<String,Object> result = new TreeMap<>(); while (true) { byte b = readByte(); if (b == 'e') break; String key = parseByteString(b); if (!result.isEmpty() && key.compareTo(result.lastKey()) <= 0) throw new IllegalArgumentException("Misordered dictionary key"); result.put(key, parseValue(readByte())); } return result; } private  Bencode(InputStream in); static void serialize(Object obj, OutputStream out); static Object parse(InputStream in); static byte[] byteStringToArray(String str); static String arrayToByteString(byte[] arr);  }