本文整理了Java中java.net.URI.toURL()
方法的一些代码示例,展示了URI.toURL()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URI.toURL()
方法的具体详情如下:
包路径:java.net.URI
类名称:URI
方法名:toURL
[英]Converts this URI instance to a URL.
[中]将此URI实例转换为URL。
代码示例来源:origin: spring-projects/spring-framework
/**
* This implementation returns a URL for the underlying file.
* @see java.io.File#toURI()
*/
@Override
public URL getURL() throws IOException {
return (this.file != null ? this.file.toURI().toURL() : this.filePath.toUri().toURL());
}
代码示例来源:origin: google/guava
/**
* Returns the absolute uri of the Class-Path entry value as specified in <a
* href="http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Main_Attributes">JAR
* File Specification</a>. Even though the specification only talks about relative urls,
* absolute urls are actually supported too (for example, in Maven surefire plugin).
*/
@VisibleForTesting
static URL getClassPathEntry(File jarFile, String path) throws MalformedURLException {
return new URL(jarFile.toURI().toURL(), path);
}
}
代码示例来源:origin: redisson/redisson
public URL find(String classname) {
char sep = File.separatorChar;
String filename = directory + sep
+ classname.replace('.', sep) + ".class";
File f = new File(filename);
if (f.exists())
try {
return f.getCanonicalFile().toURI().toURL();
}
catch (MalformedURLException e) {}
catch (IOException e) {}
return null;
}
代码示例来源:origin: jenkinsci/jenkins
public void addPathFiles( Collection<File> paths )
throws IOException
{
for ( File f : paths )
{
urls.add( f.toURI().toURL() );
addPathFile( f );
}
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
public static URL parseURL(String input) {
try {
switch (parseProtocol(input)) {
case NO_PROTOCOL:
return new File(input).toURI().toURL();
default:
return URI.create(input).toURL();
}
} catch (MalformedURLException e) {
throw new IllegalArgumentException(String.format("Unable to parse source: %s", input), e);
}
}
代码示例来源:origin: pmd/pmd
@Override
public FileVisitResult visitFile(final Path file,
final BasicFileAttributes attrs) throws IOException {
if (!attrs.isSymbolicLink()) { // Broken link that can't be followed
entries.add(file.toUri().toURL());
}
return FileVisitResult.CONTINUE;
}
};
代码示例来源:origin: jenkinsci/jenkins
private @CheckForNull VersionNumber getPluginVersion(@Nonnull File pluginFile) {
if (!pluginFile.exists()) {
return null;
}
try {
return getPluginVersion(pluginFile.toURI().toURL());
} catch (MalformedURLException e) {
return null;
}
}
代码示例来源:origin: stackoverflow.com
String urlStr = "http://abc.dev.domain.com/0007AC/ads/800x480 15sec h.264.mp4";
URL url = new URL(urlStr);
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
url = uri.toURL();
代码示例来源:origin: apache/hive
public static void addJarToContextLoader(File jar) throws MalformedURLException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader instanceof MutableURLClassLoader) {
((MutableURLClassLoader) loader).addURL(jar.toURI().toURL());
} else {
URLClassLoader newLoader =
new URLClassLoader(new URL[]{jar.toURI().toURL()}, loader);
Thread.currentThread().setContextClassLoader(newLoader);
}
}
代码示例来源:origin: google/guava
/**
* Returns the URLs in the class path specified by the {@code java.class.path} {@linkplain
* System#getProperty system property}.
*/
@VisibleForTesting // TODO(b/65488446): Make this a public API.
static ImmutableList<URL> parseJavaClassPath() {
ImmutableList.Builder<URL> urls = ImmutableList.builder();
for (String entry : Splitter.on(PATH_SEPARATOR.value()).split(JAVA_CLASS_PATH.value())) {
try {
try {
urls.add(new File(entry).toURI().toURL());
} catch (SecurityException e) { // File.toURI checks to see if the file is a directory
urls.add(new URL("file", null, new File(entry).getAbsolutePath()));
}
} catch (MalformedURLException e) {
logger.log(WARNING, "malformed classpath entry: " + entry, e);
}
}
return urls.build();
}
代码示例来源:origin: pmd/pmd
private static URL[] fileToURL(List<File> files) throws IOException {
List<URL> urlList = new ArrayList<>();
for (File f : files) {
urlList.add(f.toURI().toURL());
}
return urlList.toArray(new URL[0]);
}
代码示例来源:origin: redisson/redisson
JarClassPath(String pathname) throws NotFoundException {
try {
jarfile = new JarFile(pathname);
jarfileURL = new File(pathname).getCanonicalFile()
.toURI().toURL().toString();
return;
}
catch (IOException e) {}
throw new NotFoundException(pathname);
}
代码示例来源:origin: apache/hive
private static URL checkConfigFile(File f) {
try {
return (f.exists() && f.isFile()) ? f.toURI().toURL() : null;
} catch (Throwable e) {
LOG.warn("Error looking for config " + f, e);
return null;
}
}
代码示例来源:origin: google/j2objc
/**
* Returns the absolute uri of the Class-Path entry value as specified in <a
* href="http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Main_Attributes">JAR
* File Specification</a>. Even though the specification only talks about relative urls,
* absolute urls are actually supported too (for example, in Maven surefire plugin).
*/
@VisibleForTesting
static URL getClassPathEntry(File jarFile, String path) throws MalformedURLException {
return new URL(jarFile.toURI().toURL(), path);
}
}
代码示例来源:origin: commons-io/commons-io
private void testToString_URL(final String encoding) throws Exception {
final URL url = m_testFile.toURI().toURL();
final String out = IOUtils.toString(url, encoding);
assertNotNull(out);
assertEquals("Wrong output size", FILE_SIZE, out.length());
}
代码示例来源:origin: apache/flink
private static URLClassLoader createClassLoader(File root) throws MalformedURLException {
return new URLClassLoader(
new URL[]{root.toURI().toURL()},
Thread.currentThread().getContextClassLoader());
}
代码示例来源:origin: eclipse-vertx/vert.x
/**
* Creates a classloader respecting the classpath option.
*
* @return the classloader.
*/
protected synchronized ClassLoader createClassloader() {
URL[] urls = classpath.stream().map(path -> {
File file = new File(path);
try {
return file.toURI().toURL();
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
}).toArray(URL[]::new);
return new URLClassLoader(urls, this.getClass().getClassLoader());
}
代码示例来源:origin: apache/flink
/**
* Returns all provided libraries needed to run the program.
*/
public List<URL> getAllLibraries() {
List<URL> libs = new ArrayList<URL>(this.extractedTempLibraries.size() + 1);
if (jarFile != null) {
libs.add(jarFile);
}
for (File tmpLib : this.extractedTempLibraries) {
try {
libs.add(tmpLib.getAbsoluteFile().toURI().toURL());
}
catch (MalformedURLException e) {
throw new RuntimeException("URL is invalid. This should not happen.", e);
}
}
return libs;
}
代码示例来源:origin: gocd/gocd
private URL expandJarAndReturnURL(JarInputStream jarStream, JarEntry entry) throws IOException {
File nestedJarFile = new File(jarDir, entry.getName());
nestedJarFile.getParentFile().mkdirs();
try (FileOutputStream out = new FileOutputStream(nestedJarFile)) {
IOUtils.copy(jarStream, out);
}
LOGGER.info("Exploded Entry {} from to {}", entry.getName(), nestedJarFile);
return nestedJarFile.toURI().toURL();
}
代码示例来源:origin: ninjaframework/ninja
private URL getUrlForFile(File possibleFileInSrc) {
if (possibleFileInSrc.exists() && !possibleFileInSrc.isDirectory()) {
try {
return possibleFileInSrc.toURI().toURL();
} catch(MalformedURLException malformedURLException) {
logger.error("Error in dev mode while streaming files from src dir. ", malformedURLException);
}
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!