import java.io.*;

public class ReadSizes {
  private static int[] tileSizes = new int[72 * 36];

  protected static String baseNameForTile(int tileIndex) {
    int lon = (tileIndex % 72) * 5 - 180;
    int lat = (tileIndex / 72) * 5 - 90;
    String slon = lon < 0 ? "W" + (-lon) : "E" + lon;
    String slat = lat < 0 ? "S" + (-lat) : "N" + lat;
    return slon + "_" + slat;
  }

  private static int tileForBaseName(String basename) {
    String uname = basename.toUpperCase();
    int idx = uname.indexOf("_");
    if (idx < 0) return -1;
    String slon = uname.substring(0, idx);
    String slat = uname.substring(idx + 1);
    int ilon = slon.charAt(0) == 'W' ? -Integer.valueOf(slon.substring(1)) :
      (slon.charAt(0) == 'E' ? Integer.valueOf(slon.substring(1)) : -1);
    int ilat = slat.charAt(0) == 'S' ? -Integer.valueOf(slat.substring(1)) :
      (slat.charAt(0) == 'N' ? Integer.valueOf(slat.substring(1)) : -1);
    if (ilon < -180 || ilon >= 180 || ilon % 5 != 0) return -1;
    if (ilat < -90 || ilat >= 90 || ilat % 5 != 0) return -1;
    return (ilon + 180) / 5 + 72 * ((ilat + 90) / 5);
  }


  private static void scanExistingFiles(File dir) {
    String[] fileNames = dir.list();
    if (fileNames == null) return;
    String suffix = ".rd5";
    for (String fileName : fileNames) {
      if (fileName.endsWith(suffix)) {
        String basename = fileName.substring(0, fileName.length() - suffix.length());
        int tidx = tileForBaseName(basename);
        tileSizes[tidx] = (int) new File(dir, fileName).length();
      }
    }
  }


  public static void main(String[] args) {
    scanExistingFiles(new File(args[0]));
    StringBuilder sb = new StringBuilder();
    for (int tidx = 0; tidx < tileSizes.length; tidx++) {
      if ((tidx % 12) == 0) sb.append("\n        ");
      sb.append(tileSizes[tidx]).append(',');
    }
    System.out.println(sb);
  }

} 

@@ -10,16 +10,35 @@
 va.io.*;
+%0Aimport java.net.*;
 %0A%0Apublic
@@ -1581,52 +1581,1644 @@
  %7D%0A%0A
-%0A  public static void main(String%5B%5D args) %7B%0A
+  // Extract segment information from directory listing on https://brouter.de/brouter/segments4/%0A  private static void scanTilesIndex(String tilesUrl) %7B%0A    try %7B%0A      URL url = new URL(tilesUrl);%0A      HttpURLConnection con = (HttpURLConnection) url.openConnection();%0A      con.setRequestMethod(%22GET%22);%0A      BufferedReader in = new BufferedReader(%0A        new InputStreamReader(con.getInputStream()));%0A      String inputLine;%0A      while ((inputLine = in.readLine()) != null) %7B%0A        parseAndUpdateTileSize(inputLine);%0A      %7D%0A      in.close();%0A    %7D catch (MalformedURLException e) %7B%0A      System.out.println(%22Invalid URL%22);%0A    %7D catch (ProtocolException e) %7B%0A      System.out.println(%22Unable to download segment index%22);%0A    %7D catch (IOException e) %7B%0A      System.out.println(%22Unable to download segment index%22);%0A    %7D%0A  %7D%0A%0A  // Extract filename and size from each line in directory listing%0A  // Example (stripped multiple spaces): %22%3Ca href=%22E0_N10.rd5%22%3EE0_N10.rd5%3C/a%3E 17-Oct-2021 01:03 9648604%22%0A  private static void parseAndUpdateTileSize(String indexLine) %7B%0A    String suffix = %22.rd5%22;%0A%0A    if (!indexLine.contains(suffix)) %7B%0A      return;%0A    %7D%0A%0A    String fileName = indexLine.substring(indexLine.indexOf('%22') + 1, indexLine.lastIndexOf('%22'));%0A    int fileSize = Integer.parseInt(indexLine.substring(indexLine.lastIndexOf(%22 %22) + 1));%0A%0A    String basename = fileName.substring(0, fileName.length() - suffix.length());%0A    int tidx = tileForBaseName(basename);%0A    tileSizes%5Btidx%5D = fileSize;%0A  %7D%0A%0A  public static void main(String%5B%5D args) %7B%0A    if (args%5B0%5D.startsWith(%22http%22)) %7B%0A      scanTilesIndex(args%5B0%5D);%0A    %7D else %7B%0A  
     
@@ -3251,24 +3251,30 @@
 (args%5B0%5D));%0A
+    %7D%0A
     StringBu

Extend ReadSizes to get sizes from server index