当前位置: 首页>>代码示例>>Java>>正文


Java URI.toURL方法代码示例

本文整理汇总了Java中java.net.URI.toURL方法的典型用法代码示例。如果您正苦于以下问题:Java URI.toURL方法的具体用法?Java URI.toURL怎么用?Java URI.toURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.URI的用法示例。


在下文中一共展示了URI.toURL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findResource

import java.net.URI; //导入方法依赖的package包/类
/**
 * Returns the URL to a resource in a module or {@code null} if not found.
 */
private URL findResource(ModuleReference mref, String name) throws IOException {
    URI u;
    if (System.getSecurityManager() == null) {
        u = moduleReaderFor(mref).find(name).orElse(null);
    } else {
        try {
            u = AccessController.doPrivileged(new PrivilegedExceptionAction<> () {
                @Override
                public URI run() throws IOException {
                    return moduleReaderFor(mref).find(name).orElse(null);
                }
            });
        } catch (PrivilegedActionException pae) {
            throw (IOException) pae.getCause();
        }
    }
    if (u != null) {
        try {
            return u.toURL();
        } catch (MalformedURLException | IllegalArgumentException e) { }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:BuiltinClassLoader.java

示例2: getResource

import java.net.URI; //导入方法依赖的package包/类
URL getResource(String location) throws IllegalArgumentException
{
    try
    {
        URI uri = new URI(location);
        URL url;

        if (uri.getScheme() == null)
        {
            url = Thread.currentThread().getContextClassLoader().getResource(location);
        }
        else
        {
            url = uri.toURL();
        }

        return url;
    }
    catch (Exception x)
    {
        throw new IllegalArgumentException(x);
    }
}
 
开发者ID:JetBrains,项目名称:intellij-deps-ini4j,代码行数:24,代码来源:IniPreferencesFactory.java

示例3: call

import java.net.URI; //导入方法依赖的package包/类
@Override protected String call() throws Exception {
    System.out.println("---- FetchDocListTask  docsUrl = "+docsDirUrl);
    StringBuilder builder = new StringBuilder();
    try {
        URI uri = new URI(docsDirUrl + "allclasses-frame.html");
        URL url = uri.toURL();
        URLConnection urlConnection = url.openConnection();
        urlConnection.setConnectTimeout(5000); //set timeout to 5 secs
        InputStream in = urlConnection.getInputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);
            builder.append('\n');
        }
        reader.close();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return builder.toString();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:FetchDocListTask.java

示例4: toURL

import java.net.URI; //导入方法依赖的package包/类
@CheckForNull
private static URL toURL(@NullAllowed final URI uri) {
    try {
        return uri == null ?
            null :
            uri.toURL();
    } catch (MalformedURLException ex) {
        LOGGER.log(
            Level.FINE,
            "Cannot convert URI to URL",    //NOI18N
            ex);
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:JavaTypeProvider.java

示例5: put

import java.net.URI; //导入方法依赖的package包/类
public synchronized CacheRequest put(URI uri, URLConnection conn)
throws IOException {
    System.out.println("put: " + uri);
    Thread.currentThread().dumpStack();
    URL url = uri.toURL();
    return new DeployCacheRequest(url, conn);

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TestCache.java

示例6: isValidURL

import java.net.URI; //导入方法依赖的package包/类
/**
 * Checks the given string is valid url conforming to rfc3986.
 *
 * @param url url string
 * @return <code>true</code> if it conforming to the standard,
 * else return <code>false</code>
 */
public static boolean isValidURL(String url) {
    try {
        URI uri = new URI(url);
        uri.toURL();
        return true;
    } catch (Exception e) {
        logger.warn(url + " is not a valid url, error: " + e.getMessage());
        return false;
    }
}
 
开发者ID:oneops,项目名称:oneops,代码行数:18,代码来源:URLUtil.java

示例7: getOwner

import java.net.URI; //导入方法依赖的package包/类
/**
 * Find the project, if any, which "owns" the given URI.
 * @param uri the URI to the file (generally on disk); must be absolute and not opaque (though {@code jar}-protocol URIs are unwrapped as a convenience)
 * @return a project which contains it, or null if there is no known project containing it
 * @throws IllegalArgumentException if the URI is relative or opaque
 */
public static Project getOwner(URI uri) {
    try {
        URL url = uri.toURL();
        if (FileUtil.isArchiveArtifact(url)) {
            url = FileUtil.getArchiveFile(url);
            if (url != null) {
                uri = url.toURI();
            }
        }
    } catch (MalformedURLException | URISyntaxException e) {
        LOG.log(Level.INFO, null, e);
    }
    if (!uri.isAbsolute() || uri.isOpaque()) {
        throw new IllegalArgumentException("Bad URI: " + uri); // NOI18N
    }
    for (FileOwnerQueryImplementation q : getInstances()) {
        Project p = q.getOwner(uri);
        if (p != null) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE, "getOwner({0}) -> {1} from {2}", new Object[] {uri, p, q});
            }
            return p == UNOWNED ? null : p;
        }
    }
    LOG.log(Level.FINE, "getOwner({0}) -> nil", uri);
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:FileOwnerQuery.java

示例8: toURLs

import java.net.URI; //导入方法依赖的package包/类
private static Collection<URL> toURLs(Collection<URI> libs)  {
    URL[] urls = new URL[libs.size()];
    int index = 0;
    for (URI u : libs) {
        try {
            urls[index++] = u.toURL();
        } catch (MalformedURLException ex) {
            return Collections.emptyList();
        }
    }
    return Arrays.asList(urls);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ProjectClassPathModifier.java

示例9: setUp

import java.net.URI; //导入方法依赖的package包/类
@Before
public void setUp() throws IOException {
  // Chart is arbitrary, but it does have subcharts in it, which exercise some tricky logic
  final URI uri = URI.create("https://kubernetes-charts.storage.googleapis.com/wordpress-0.6.6.tgz");
  assertNotNull(uri);
  final URL url = uri.toURL();
  assertNotNull(url);
  final URLConnection connection = url.openConnection();
  assertNotNull(connection);
  connection.addRequestProperty("Accept-Encoding", "gzip");
  connection.connect();
  assertEquals("application/x-tar", connection.getContentType());
  this.remoteUrl = url;
}
 
开发者ID:microbean,项目名称:microbean-helm,代码行数:15,代码来源:TestURLChartLoader.java

示例10: setData

import java.net.URI; //导入方法依赖的package包/类
/**
 * Creates a mapping of data needed during code generation.  All domain
 * models passed in will be mapped
 * to their table names.  All fields for each domain model will be mapped
 * to their column names.
 *
 * @param dataSet the set of xml files to create the data mapping from
 */
public void setData(List<File> dataSet)
        throws IOException, PatternGeneratorException, SAXException,
               ParserConfigurationException {
    for (File file : dataSet) {

        // get the root object
        URI uri = file.toURI();
        URL url = uri.toURL();
        DatabaseTableInformation tableData = extractModelData(url);

        // get all values in upper case
        String domainObject = tableData.getDomainModelName().toUpperCase();
        String tableName = tableData.getTableName().toUpperCase();
        tableNames.put(domainObject, tableName);

        // add each field column in this domain object
        if (!columnNames.containsKey(domainObject)) {
            columnNames.put(domainObject, new HashMap<String, String>());
        }
        for (Map.Entry<String, String> entry : tableData.getFieldToColumnName().entrySet()) {
            String fieldName = entry.getKey().toUpperCase();
            String columnName = entry.getValue().toUpperCase();
            columnNames.get(domainObject).put(fieldName, columnName);
        }
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:35,代码来源:PatternGenerator.java

示例11: unredirect

import java.net.URI; //导入方法依赖的package包/类
public static URI unredirect(URI uri) throws IOException {
    if (!REDIRECTOR_DOMAINS.contains(uri.getHost())) {
        return uri;
    }
    URL url = uri.toURL();
    HttpURLConnection connection = safelyOpenConnection(url);
    connection.setInstanceFollowRedirects(false);
    connection.setDoInput(false);
    connection.setRequestMethod("HEAD");
    connection.setRequestProperty("User-Agent", "ZXing (Android)");
    try {
        int responseCode = safelyConnect(connection);
        switch (responseCode) {
            case HttpURLConnection.HTTP_MULT_CHOICE:
            case HttpURLConnection.HTTP_MOVED_PERM:
            case HttpURLConnection.HTTP_MOVED_TEMP:
            case HttpURLConnection.HTTP_SEE_OTHER:
            case 307: // No constant for 307 Temporary Redirect ?
                String location = connection.getHeaderField("Location");
                if (location != null) {
                    try {
                        return new URI(location);
                    } catch (URISyntaxException e) {
                        // nevermind
                    }
                }
        }
        return uri;
    } finally {
        connection.disconnect();
    }
}
 
开发者ID:xiong-it,项目名称:ZXingAndroidExt,代码行数:33,代码来源:HttpHelper.java

示例12: readService

import java.net.URI; //导入方法依赖的package包/类
private DialService readService(XmlPullParser parser) throws DialException, IOException, XmlPullParserException {
    DialService service;
    String name = null;
    DialService.State state = null;
    URL absoluteLink = null;
    AdditionalData additionalData = null;

    parser.require(XmlPullParser.START_TAG, "urn:dial-multiscreen-org:schemas:dial", TAG_SERVICE);
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String tag = parser.getName();
        if (tag.equals(TAG_ADDITIONAL_DATA)) {
            additionalData = readAdditionalData(parser);
        } else if (tag.equals(TAG_NAME)) {
            name = DialParserUtils.readTextValue(parser, TAG_NAME, null);
        } else if (tag.equals(TAG_STATE)) {
            state = readState(parser);
        } else if (tag.equals(TAG_LINK)) {
            URI link = readLink(parser);
            if(link != null && link.isAbsolute()) {
                absoluteLink = link.toURL();
            } else {
                try {
                    // not confident about this being the right way to do it
                    absoluteLink = new URI(baseUrl.toString() + "/").resolve(link).toURL();
                } catch (URISyntaxException e) {
                    throw new DialException(e);
                }
            }
        } else {
            DialParserUtils.skip(parser);
        }
    }

    service = new DialService(baseUrl, name, state, absoluteLink, additionalData);
    checkService(service);
    return service;
}
 
开发者ID:Orange-OpenSource,项目名称:OCast-Java,代码行数:41,代码来源:DialServiceParser.java

示例13: setUp

import java.net.URI; //导入方法依赖的package包/类
@Before
public void setUp() throws IOException {
  final URI uri = URI.create("https://kubernetes-charts.storage.googleapis.com/redis-0.10.1.tgz");
  assertNotNull(uri);
  final URL url = uri.toURL();
  assertNotNull(url);
  final URLConnection connection = url.openConnection();
  assertNotNull(connection);
  connection.addRequestProperty("Accept-Encoding", "gzip");
  connection.connect();
  assertEquals("application/x-tar", connection.getContentType());
  this.redisUrl = url;
}
 
开发者ID:microbean,项目名称:microbean-helm,代码行数:14,代码来源:TestCharts.java

示例14: getHttpAddress

import java.net.URI; //导入方法依赖的package包/类
private URL getHttpAddress(Configuration conf) throws IOException {
  final String scheme = DFSUtil.getHttpClientScheme(conf);
  String defaultHost = NameNode.getServiceAddress(conf, true).getHostName();
  URI addr = DFSUtil.getInfoServerWithDefaultHost(defaultHost, conf, scheme);
  return addr.toURL();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:7,代码来源:StandbyCheckpointer.java

示例15: testFileUrls

import java.net.URI; //导入方法依赖的package包/类
/**
 * Test opening and reading from an InputStream through a file:// URL.
 * 
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void testFileUrls() throws IOException, URISyntaxException {
  // URLStreamHandler is already set in JVM by testDfsUrls() 
  Configuration conf = new HdfsConfiguration();

  // Locate the test temporary directory.
  if (!TEST_ROOT_DIR.exists()) {
    if (!TEST_ROOT_DIR.mkdirs())
      throw new IOException("Cannot create temporary directory: " + TEST_ROOT_DIR);
  }

  File tmpFile = new File(TEST_ROOT_DIR, "thefile");
  URI uri = tmpFile.toURI();

  FileSystem fs = FileSystem.get(uri, conf);

  try {
    byte[] fileContent = new byte[1024];
    for (int i = 0; i < fileContent.length; ++i)
      fileContent[i] = (byte) i;

    // First create the file through the FileSystem API
    OutputStream os = fs.create(new Path(uri.getPath()));
    os.write(fileContent);
    os.close();

    // Second, open and read the file content through the URL API.
    URL fileURL = uri.toURL();

    InputStream is = fileURL.openStream();
    assertNotNull(is);

    byte[] bytes = new byte[4096];
    assertEquals(1024, is.read(bytes));
    is.close();

    for (int i = 0; i < fileContent.length; ++i)
      assertEquals(fileContent[i], bytes[i]);

    // Cleanup: delete the file
    fs.delete(new Path(uri.getPath()), false);

  } finally {
    fs.close();
  }

}
 
开发者ID:naver,项目名称:hadoop,代码行数:54,代码来源:TestUrlStreamHandler.java


注:本文中的java.net.URI.toURL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。