private static double[] readDoubleArray(DataInputStream stream) throws IOException {
    int length = stream.readInt();
    assert length > 0;
    byte[] bytes = new byte[length * Double.BYTES];
    double[] array = new double[length];
    stream.readFully(bytes);
    DoubleBuffer buffer = ByteBuffer.wrap(bytes)
      .order(ByteOrder.BIG_ENDIAN)
      .asDoubleBuffer();
    buffer.get(array);
    return array;
  }
private static double[] readDoubleArray(DataInputStream stream)