java.net.URL.toExternalForm()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(344)

本文整理了Java中java.net.URL.toExternalForm()方法的一些代码示例,展示了URL.toExternalForm()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URL.toExternalForm()方法的具体详情如下:
包路径:java.net.URL
类名称:URL
方法名:toExternalForm

URL.toExternalForm介绍

[英]Returns a string containing a concise, human-readable representation of this URL.
[中]返回一个字符串,该字符串包含此URL的简明易读表示形式。

代码示例

代码示例来源:origin: gocd/gocd

public String urlFor(String pathAfterContext) {
    try {
      return new URL(protocol, host, port, contextPath + pathAfterContext).toExternalForm();
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: org.freemarker/freemarker

public String getXmlSystemId() throws IOException {
  return file.toURI().toURL().toExternalForm();
}

代码示例来源:origin: ffay/lanproxy

private InputStream jksDatastore(String jksPath) throws FileNotFoundException {
    URL jksUrl = getClass().getClassLoader().getResource(jksPath);
    if (jksUrl != null) {
      logger.info("Starting with jks at {}, jks normal {}", jksUrl.toExternalForm(), jksUrl);
      return getClass().getClassLoader().getResourceAsStream(jksPath);
    }

    logger.warn("No keystore has been found in the bundled resources. Scanning filesystem...");
    File jksFile = new File(jksPath);
    if (jksFile.exists()) {
      logger.info("Loading external keystore. Url = {}.", jksFile.getAbsolutePath());
      return new FileInputStream(jksFile);
    }

    logger.warn("The keystore file does not exist. Url = {}.", jksFile.getAbsolutePath());
    return null;
  }
}

代码示例来源:origin: apache/hive

private void addJarLRByClass(Class<?> clazz, final Map<String, LocalResource> lrMap) throws IOException,
  LoginException {
 final File jar =
   new File(Utilities.jarFinderGetJar(clazz));
 final String localJarPath = jar.toURI().toURL().toExternalForm();
 final LocalResource jarLr = createJarLocalResource(localJarPath);
 lrMap.put(DagUtils.getBaseName(jarLr), jarLr);
}

代码示例来源:origin: RaiMan/SikuliX2

uFolder = new URL(uFolder.toExternalForm().replaceAll(" ", "%20"));
} catch (Exception ex) {
 fFolder = new File(uFolder.toURI());
 log.debug("resourceList: having folder:\n%s", fFolder);
 String sFolder = normalizeAbsolute(fFolder.getPath(), false);
  sFolder = sFolder.substring(1);
 files.add(sFolder);
 files = doResourceListFolder(new File(sFolder), files, filter);
 files.remove(0);
 return files;
} catch (Exception ex) {
 if (!"jar".equals(uFolder.getProtocol())) {
  log.debug("resourceList:\n%s", folder);
  log.error("resourceList: URL neither folder nor jar:\n%s", ex);

代码示例来源:origin: eclipse-vertx/vert.x

private static List<JavaFileObject> browseJar(URL packageFolderURL) {
  List<JavaFileObject> result = new ArrayList<>();
  try {
   String jarUri = packageFolderURL.toExternalForm().split("!")[0];
   JarURLConnection jarConn = (JarURLConnection) packageFolderURL.openConnection();
   String rootEntryName = jarConn.getEntryName();
   int rootEnd = rootEntryName.length() + 1;

   Enumeration<JarEntry> entryEnum = jarConn.getJarFile().entries();
   while (entryEnum.hasMoreElements()) {
    JarEntry jarEntry = entryEnum.nextElement();
    String name = jarEntry.getName();
    if (name.startsWith(rootEntryName) && name.indexOf('/', rootEnd) == -1 && name.endsWith(CLASS_FILE)) {
     String binaryName = name.replaceAll("/", ".").replaceAll(CLASS_FILE + "$", "");
     result.add(new CustomJavaFileObject(URI.create(jarUri + "!/" + name), JavaFileObject.Kind.CLASS, binaryName));
    }
   }
  } catch (Exception e) {
   throw new RuntimeException(packageFolderURL + " is not a JAR file", e);
  }
  return result;
 }
}

代码示例来源:origin: Atmosphere/atmosphere

final boolean isVfs = url.getProtocol() != null && url.getProtocol().startsWith("vfs");
if ("file".equals(url.getProtocol()) || isVfs) {
  final File dir = toFile(url);
  if (dir.isDirectory()) {
    if (idx > -1) {
      jarPath = jarPath.substring(0, idx + 4);
      final File jarFile = new File(jarPath);
      if (jarFile.isFile() && jarFile.exists()) {
        files.add(jarFile);
        print("Add jar file from VFS: '%s'", jarFile);
    loadJarContent((JarURLConnection) url.openConnection(), packageName, streams);
  } catch (ClassCastException cce) {
    throw new AssertionError("Not a File: " + url.toExternalForm());
    try {
      String u = url.toExternalForm();
      if (u.startsWith("zip:")) {
        u = u.substring(4);
      jarFile = toFile(new URL(u));
    } catch (Exception ex) {
      throw new AssertionError("Not a File: " + url.toExternalForm());

代码示例来源:origin: Dreampie/Resty

rootPath = new File(classPath).getParentFile().getParentFile().getCanonicalFile().getAbsolutePath() + "/";
File webappDir = new File(rootPath + resourceBase);
if (!webappDir.exists() || !webappDir.isDirectory()) {
 throw new IllegalArgumentException("Could not found webapp directory or it is not directory.");
resourceUrls.add(webappUrl);
while (staticUrls.hasMoreElements()) {
 staticURL = staticUrls.nextElement();
 if (staticURL != null) {
  resourceUrls.add(staticURL.toExternalForm());

代码示例来源:origin: ronmamo/reflections

while (urls.hasMoreElements()) {
  final URL url = urls.nextElement();
  int index = url.toExternalForm().lastIndexOf(resourceName);
  if (index != -1) {
    result.add(new URL(url, url.toExternalForm().substring(0, index)));
  } else {
    result.add(url);

代码示例来源:origin: RipMeApp/ripme

@Override
public List<String> getURLsFromPage(Document doc) {
  List<String> result = new ArrayList<>();
  List<String> urlsToGrab = new ArrayList<>();
  if (url.toExternalForm().contains("/manga/")) {
    for (Element el : doc.select("div.chapter-list > div.row > span > a")) {
      urlsToGrab.add(el.attr("href"));
    }
    Collections.reverse(urlsToGrab);
    for (String url : urlsToGrab) {
      result.addAll(getURLsFromChap(url));
    }
  } else if (url.toExternalForm().contains("/chapter/")) {
    result.addAll(getURLsFromChap(doc));
  }
  return result;
}

代码示例来源:origin: RipMeApp/ripme

private void handleURL(String theUrl, String id, String title) {
  URL originalURL;
  try {
    originalURL = new URL(theUrl);
  } catch (MalformedURLException e) {
    return;
    String url = urls.get(0).toExternalForm();
    Pattern p = Pattern.compile("https?://i.reddituploads.com/([a-zA-Z0-9]+)\\?.*");
    Matcher m = p.matcher(url);
      addURLToDownload(urls.get(0), new File(savePath));
      URL urlToDownload = parseRedditVideoMPD(urls.get(0).toExternalForm());
      if (urlToDownload != null) {
        LOGGER.info("url: " + urlToDownload + " file: " + savePath);
        addURLToDownload(urlToDownload, new File(savePath));

代码示例来源:origin: webx/citrus

private InputSource(Object source, String systemId) {
  assertNotNull(source, "source");
  if (source instanceof URL) {
    try {
      this.source = new File(((URL) source).toURI().normalize()); // convert URL to File
    } catch (Exception e) {
      this.source = source;
    }
  } else if (source instanceof File) {
    this.source = new File(((File) source).toURI().normalize()); // remove ../
  } else {
    this.source = source;
  }
  if (this.source instanceof URL) {
    this.systemId = ((URL) this.source).toExternalForm();
  } else if (this.source instanceof File) {
    this.systemId = ((File) this.source).toURI().toString();
  } else {
    this.systemId = trimToNull(systemId);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

String protocol = url.getProtocol();
      return new URL(jarPath);
        new Object[] {
          mue.getMessage(),
          url.toExternalForm(),
          jarPath
        });

代码示例来源:origin: stackoverflow.com

webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
webapp.setServer(server);
webapp.setWar(location.toExternalForm());
webapp.setTempDirectory(new File("/path/to/webapp-directory"));

代码示例来源:origin: javax.xml.bind/jaxb-api

xml=new URI((String)xml);
} catch (URISyntaxException e) {
  xml=new File((String)xml);
xml=uri.toURL();
return new StreamSource(url.toExternalForm());

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

wasDir = entry.isDirectory();
  LOG.finest("urlForArchiveOrDir:toURI:entry");   //NOI18N
  u = Utilities.toURI(entry).toURL();
  isDir = entry.isDirectory();
} while (wasDir ^ isDir);
  return getArchiveRoot(u);
} else if (isDir) {
  assert u.toExternalForm().endsWith("/");    //NOI18N
  return u;
} else if (!entry.exists()) {
  if (!u.toString().endsWith("/")) {  //NOI18N
    u = new URL(u + "/"); // NOI18N

代码示例来源:origin: cucumber/cucumber-jvm

private URLOutputStream(URL url, String method, Map<String, String> headers, int expectedResponseCode) throws IOException {
  this.url = url;
  this.method = method;
  this.expectedResponseCode = expectedResponseCode;
  if (url.getProtocol().equals("file")) {
    File file = new File(url.getFile());
    ensureParentDirExists(file);
    out = new FileOutputStream(file);
    urlConnection = null;
  } else if (url.getProtocol().startsWith("http")) {
    urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setRequestMethod(method);
    urlConnection.setDoOutput(true);
    for (Map.Entry<String, String> header : headers.entrySet()) {
      urlConnection.setRequestProperty(header.getKey(), header.getValue());
    }
    out = urlConnection.getOutputStream();
  } else {
    throw new IllegalArgumentException("URL Scheme must be one of file,http,https. " + url.toExternalForm());
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

private static URL toURL(File fFile, FileObject fo) throws MalformedURLException {
  URL retVal = Utilities.toURI(fFile).toURL();
  if (retVal != null && fo.isFolder()) {
    // #155742,160333 - URL for folder must always end with slash
    final String urlDef = retVal.toExternalForm();
    final String pathSeparator = "/";//NOI18N
    if (!urlDef.endsWith(pathSeparator)) {
      retVal = new URL(urlDef + pathSeparator);
    }
  }
  return retVal;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

if ("file".equalsIgnoreCase(url.getProtocol())) {
  if (url.getHost() == null || "".equals(url.getHost())) {
    return path.toUri().toURL();
} else if ("jar".equals(url.getProtocol())) {
  String file = url.getFile();
  int pos = file.indexOf("!/");
  URL internalUrl = new URL(filePath);
  URL normalizedUrl = resolveRepoURL(internalUrl);
  if (normalizedUrl == null) {
    return null;
  return new URL("jar", "", normalizedUrl.toExternalForm() + jarTail);
} else {

代码示例来源:origin: cucumber/cucumber-jvm

static String filePath(URL fileUrl) {
  if (!"file".equals(fileUrl.getProtocol())) {
    throw new CucumberException("Expected a file URL:" + fileUrl.toExternalForm());
  }
  try {
    return fileUrl.toURI().getSchemeSpecificPart();
  } catch (URISyntaxException e) {
    throw new CucumberException(e);
  }
}

相关文章