@Test public void testWriteNestedDictionariesAndLists() throws IOException { Map<String, Object> inner = new LinkedHashMap<>(); inner.put("bar", new byte[0]); List<Object> list = new ArrayList<>(); list.add(1); list.add(inner); Map<String, Object> outer = new LinkedHashMap<>(); outer.put("foo", list); w.writeDictionary(outer); checkContents("70" + "41" + "03" + "666F6F" + "60" + "21" + "01" + "70" + "41" + "03" + "626172" + "51" + "00" + "80" + "80" + "80"); }
@Override public void writeDictionary(Map<?, ?> m) throws IOException { out.write(DICTIONARY); for (Entry<?, ?> e : m.entrySet()) { if (!(e.getKey() instanceof String)) throw new FormatException(); writeString((String) e.getKey()); writeObject(e.getValue()); } out.write(END); }
BdfWriterImpl implements BdfWriter { @Override public void writeDictionary(Map<?, ?> m) throws IOException { out.write(DICTIONARY); for (Entry<?, ?> e : m.entrySet()) { if (!(e.getKey() instanceof String)) throw new FormatException(); writeString((String) e.getKey()); writeObject(e.getValue()); } out.write(END); } }
BdfWriterImpl implements BdfWriter { @Override public void writeDictionary(Map<?, ?> m) throws IOException { out.write(DICTIONARY); for (Entry<?, ?> e : m.entrySet()) { if (!(e.getKey() instanceof String)) throw new FormatException(); writeString((String) e.getKey()); writeObject(e.getValue()); } out.write(END); } BdfWriterImpl(OutputStream out); }
BdfWriterImpl implements BdfWriter { @Override public void writeDictionary(Map<?, ?> m) throws IOException { out.write(DICTIONARY); for (Entry<?, ?> e : m.entrySet()) { if (!(e.getKey() instanceof String)) throw new FormatException(); writeString((String) e.getKey()); writeObject(e.getValue()); } out.write(END); } BdfWriterImpl(OutputStream out); @Override void flush(); @Override void close(); @Override void writeNull(); @Override void writeBoolean(boolean b); @Override void writeLong(long i); @Override void writeDouble(double d); @Override void writeString(String s); @Override void writeRaw(byte[] b); @Override void writeList(Collection<?> c); @Override void writeListStart(); @Override void writeListEnd(); @Override void writeDictionary(Map<?, ?> m); @Override void writeDictionaryStart(); @Override void writeDictionaryEnd(); }
BdfWriterImpl implements BdfWriter { @Override public void writeDictionary(Map<?, ?> m) throws IOException { out.write(DICTIONARY); for (Entry<?, ?> e : m.entrySet()) { if (!(e.getKey() instanceof String)) throw new FormatException(); writeString((String) e.getKey()); writeObject(e.getValue()); } out.write(END); } BdfWriterImpl(OutputStream out); @Override void flush(); @Override void close(); @Override void writeNull(); @Override void writeBoolean(boolean b); @Override void writeLong(long i); @Override void writeDouble(double d); @Override void writeString(String s); @Override void writeRaw(byte[] b); @Override void writeList(Collection<?> c); @Override void writeListStart(); @Override void writeListEnd(); @Override void writeDictionary(Map<?, ?> m); @Override void writeDictionaryStart(); @Override void writeDictionaryEnd();  }