code: public static String getMimeTypeForFile(URL url) {
          if (url == null) {
              //The input url is null so we can't retrieve a mimetype, therefore we return null.
              return null;
          }
          String external = url.toExternalForm();
          if (external.indexOf('.') == -1) {
              return BINARY;
          } else {
              String ext = external.substring(external.lastIndexOf('.') + 1);
              String mime = KnownMimeTypes.getMimeTypeByExtension(ext);
              if (mime == null) {
                  return BINARY;
              } else {
                  return mime;
              }
          }
      }
docs: Makes an educated guess of the mime type of the resource pointed by this url.
  It tries to extract an 'extension' part and confronts this extension to the list of known extensions.
  @param url the url
  @return the mime type, BINARY if not found.