code: public static String extractAccessURL(String publicURL, String scheme) throws IOException {
      if (publicURL != null && !publicURL.startsWith("http")) {
        String startScheme = scheme + "://";
        int end = publicURL.length();
        if (publicURL.indexOf("/", startScheme.length()) >= 0) {
          end = publicURL.indexOf("/", startScheme.length());
        }
        return publicURL.substring(0, end);
      }
      try {
        String hostName = new URI(publicURL).getAuthority();
        int  start = publicURL.indexOf("//") + 2 + hostName.length() + 1;
        for (int i = 0; i < 2; i++) {
          start = publicURL.indexOf("/", start) + 1;
        }
        String authURL = publicURL.substring(0, start);
        if (authURL.endsWith("/")) {
          authURL = authURL.substring(0, authURL.length() - 1);
        }
        return authURL;
      } catch (URISyntaxException e) {
        throw new IOException("Public URL: " + publicURL + " is not valid");
      }
    }
docs: Transform http://hostname/v1/auth_id/container/object to
  http://hostname/v1/auth_id
  
  @param publicURL public url
  @param scheme URL scheme
  @return accessURL access url
  @throws IOException if path is malformed