public static String urlSanitize(String string) {
      StringBuilder sanitized = new StringBuilder();

      for (char c : string.toCharArray()) {
         sanitized.append(ALLOWED_CHARS_SET.contains(c) ? c : REPLACE_CHAR);
      }

      return sanitized.toString();
   }
@Test
   void testUrlSanitize() {
      String url = Sanitizer.urlSanitize("weird|~url.json");
      assertEquals("weird--url.json", url);
   }