code: public static String getURLParentDirectory(String urlString) throws IllegalArgumentException {
          URL url = null;
          try {
              url = new URL(urlString);
          } catch (MalformedURLException e) {
              throw Exceptions.IllegalArgument("Malformed URL: %s", url);
          }
  
          String path = url.getPath();
          int lastSlashIndex = path.lastIndexOf("/");
          String directory = lastSlashIndex == -1 ? "" : path.substring(0, lastSlashIndex);
          return String.format("%s://%s%s%s%s", url.getProtocol(),
                  url.getUserInfo() == null ? "" : url.getUserInfo() + "@",
                  url.getHost(),
                  url.getPort() == -1 ? "" : ":" + Integer.toString(url.getPort()),
                  directory);
      }
docs: Returns the directory of the URL.
  
  @param urlString URL of the file.
  @return The directory string.
  @throws IllegalArgumentException if URL is malformed