@Override public void writeExternal(Object subject, ObjectOutput output) throws IOException { externalizer.writeObject(output, subject); }
public static <E> void writeCollection(Collection<E> col, Externalizer<E> valueExternalizer, ObjectOutput output) throws IOException { if (col == null) { output.writeByte(0); } else { output.writeByte(1); // Copy the collection as it can be updated concurrently Collection<E> copy = new LinkedList<>(col); output.writeInt(copy.size()); for (E entry : copy) { valueExternalizer.writeObject(output, entry); } } }
public static <K, V> void writeMap(Map<K, V> map, Externalizer<K> keyExternalizer, Externalizer<V> valueExternalizer, ObjectOutput output) throws IOException { if (map == null) { output.writeByte(0); } else { output.writeByte(1); // Copy the map as it can be updated concurrently Map<K, V> copy = new HashMap<>(map); //Map<K, V> copy = map; output.writeInt(copy.size()); for (Map.Entry<K, V> entry : copy.entrySet()) { keyExternalizer.writeObject(output, entry.getKey()); valueExternalizer.writeObject(output, entry.getValue()); } } }