private static <T> ArrayList<T> readArrayList(DataInputStream stream, Function<? super DataInputStream, ? extends T> readElement)
    throws IOException {
    int size = stream.readInt();
    assert size > 0;
    ArrayList<T> list = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
      T element = readElement.apply(stream);
      list.add(element);
    }
    return list;
  }
private static <T> ArrayList<T> readArrayList(DataInputStream stream, Function<? super DataInputStream, ? extends T> readElement)