code: public static String encodePath(String path) {
          URI tmp;
  
          try {
              tmp = new URI("foo", "host", "/" + path, null);
          } catch (URISyntaxException e) {
              throw new IllegalStateException(e);
          }
          return tmp.getRawPath().substring(1);
      }
docs: TODO: is there a better way ... ?