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


Java URL.getPath方法代码示例

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


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

示例1: openConnection

import java.net.URL; //导入方法依赖的package包/类
@Override
protected URLConnection openConnection(URL u) throws IOException {
    String path = u.getPath();

    // Thread context class loader first
    URL classpathUrl = Thread.currentThread().getContextClassLoader().getResource(path);
    if (classpathUrl == null) {
        // This class's class loader if no joy with the tccl
        classpathUrl = ClasspathURLStreamHandler.class.getResource(path);
    }

    if (classpathUrl == null) {
        throw new FileNotFoundException(sm.getString("classpathUrlStreamHandler.notFound", u));
    }

    return classpathUrl.openConnection();
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:18,代码来源:ClasspathURLStreamHandler.java

示例2: requestPodcasts

import java.net.URL; //导入方法依赖的package包/类
private Podcasts requestPodcasts(String spec) throws IOException, HttpException {
    URL url = new URL(spec);
    HttpRequest request = new BasicHttpRequest("GET", url.getPath(), HttpVersion.HTTP_1_1);
    request.setHeader(HttpHeaders.ACCEPT, "text/html,*/*");
    request.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip, deflate");
    request.setHeader(HttpHeaders.HOST, url.getAuthority());
    // If-Modified-Since: Thu, 24 Nov 2016 10:13:10 GMT
    try (HttpClientConnection connection = DefaultHttpClientConnectionFactory.INSTANCE.openConnection(url)) {
        HttpResponse response = getEntityResponse(connection, request);
        if (response == null) {
            return null;
        }
        try (InputStream input = HttpUtils.getContent(response.getEntity())) {
            return parser.parse(IOUtils.buffer(input), HttpUtils.getCharset(response), url.toString());
        }
    }
}
 
开发者ID:kalikov,项目名称:lighthouse,代码行数:18,代码来源:PodcastsLoader.java

示例3: requestPage

import java.net.URL; //导入方法依赖的package包/类
private RecordsPaginator requestPage(Context context, long id, long nextPage) throws IOException, HttpException {
    String spec = String.format(PAGE_URL, String.valueOf(id), String.valueOf(nextPage));
    URL url = new URL(spec);
    HttpRequest request = new BasicHttpRequest("GET", url.getPath(), HttpVersion.HTTP_1_1);
    request.setHeader(HttpHeaders.ACCEPT, "application/json");
    request.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip, deflate");
    request.setHeader(HttpHeaders.HOST, url.getAuthority());
    // If-Modified-Since: Thu, 24 Nov 2016 10:13:10 GMT
    try (HttpClientConnection connection = DefaultHttpClientConnectionFactory.INSTANCE.openConnection(url)) {
        connection.setSocketTimeout(NetworkUtils.getRequestTimeout());
        connection.sendRequestHeader(request);
        connection.flush();
        HttpResponse response = connection.receiveResponseHeader();
        int status = response.getStatusLine().getStatusCode();
        if (status < 200 || status >= 400) {
            return null;
        }
        connection.receiveResponseEntity(response);
        if (response.getEntity() == null || response.getEntity().getContentLength() == 0) {
            return null;
        }
        try (InputStream stream = HttpUtils.getContent(response.getEntity())) {
            return handlePageResponse(context, id, stream, NetworkUtils.toOptURI(spec));
        }
    }
}
 
开发者ID:kalikov,项目名称:lighthouse,代码行数:27,代码来源:OnlineRecordsPaginator.java

示例4: defineFinderClass

import java.net.URL; //导入方法依赖的package包/类
private Class<?> defineFinderClass(String name)
    throws ClassNotFoundException {
    final Object obj = getClassLoadingLock(name);
    synchronized(obj) {
        if (finderClass != null) return finderClass;

        URL url = this.getClass().getProtectionDomain().getCodeSource().getLocation();
        File file = new File(url.getPath(), name+".class");
        if (file.canRead()) {
            try {
                byte[] b = Files.readAllBytes(file.toPath());
                Permissions perms = new Permissions();
                perms.add(new AllPermission());
                finderClass = defineClass(
                        name, b, 0, b.length, new ProtectionDomain(
                        this.getClass().getProtectionDomain().getCodeSource(),
                        perms));
                System.out.println("Loaded " + name);
                return finderClass;
            } catch (Throwable ex) {
                ex.printStackTrace();
                throw new ClassNotFoundException(name, ex);
            }
        } else {
            throw new ClassNotFoundException(name,
                    new IOException(file.toPath() + ": can't read"));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:CustomSystemClassLoader.java

示例5: load

import java.net.URL; //导入方法依赖的package包/类
/**
 * Load/initialize a word sense classifier from a provided {@link URL}.
 *
 * @param path path to classifier model
 * @return initialized word sense classifier
 */
public static WordSenseClassifier load(URL path) {
    try (ObjectInputStream objectInputStream = new ObjectInputStream(path.openStream())) {
        return new WordSenseClassifier(objectInputStream);
    } catch (IOException e) {
        throw new RuntimeException("Unable to load classifier model at " + path.getPath() + ": " + e.getMessage(), e);
    }
}
 
开发者ID:clearwsd,项目名称:clearwsd,代码行数:14,代码来源:WordSenseClassifier.java

示例6: getJarFile

import java.net.URL; //导入方法依赖的package包/类
/**
 * Returns the JarFile instance corresponding to the JAR containing the
 * specified class.
 */
public static JarFile getJarFile(Class klass) {
    try {
        CodeSource src = klass.getProtectionDomain().getCodeSource();
        if (src != null) {
            URL jarUrl = src.getLocation();
            return new JarFile(new File(jarUrl.getPath()));
        } else {
            return null;
        }
    } catch (IOException ex1) {
        return null;
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:18,代码来源:JarUtil.java

示例7: checkAccess

import java.net.URL; //导入方法依赖的package包/类
/**
 * Check the protocol used in the systemId against allowed protocols
 *
 * @param systemId the Id of the URI
 * @param allowedProtocols a list of allowed protocols separated by comma
 * @param accessAny keyword to indicate allowing any protocol
 * @return the name of the protocol if rejected, null otherwise
 */
public static String checkAccess(String systemId, String allowedProtocols, String accessAny) throws IOException {
    if (systemId == null || (allowedProtocols != null &&
            allowedProtocols.equalsIgnoreCase(accessAny))) {
        return null;
    }

    String protocol;
    if (systemId.indexOf(":")==-1) {
        protocol = "file";
    } else {
        URL url = new URL(systemId);
        protocol = url.getProtocol();
        if (protocol.equalsIgnoreCase("jar")) {
            String path = url.getPath();
            protocol = path.substring(0, path.indexOf(":"));
        } else if (protocol.equalsIgnoreCase("jrt")) {
            // if the systemId is "jrt" then allow access if "file" allowed
            protocol = "file";
        }
    }

    if (isProtocolAllowed(protocol, allowedProtocols)) {
        //access allowed
        return null;
    } else {
        return protocol;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:SecuritySupport.java

示例8: Config

import java.net.URL; //导入方法依赖的package包/类
public Config() throws URISyntaxException, ClassNotFoundException{
	ResourceConfig rc = new ResourceConfig();
	
	//rc.packages() not working properly atm..., add all classes manually here
	//rc.registerClasses(Status.class /*, AnotherResource.class, ...*/);
	
	String[] packages = {"com.demo.app.restapi.impl"};
	ClassLoader cl = getClass().getClassLoader();
	boolean recur = false;
   	OsgiRegistry reg = ReflectionHelper.getOsgiRegistryInstance();
       logger.info("Created! OSGI runtime? " + (reg == null? "No" : "Yes"));
       
       //CompositeResourceFinder finder = new CompositeResourceFinder();
       //BundleSchemeResourceFinderFactory f = new BundleSchemeResourceFinderFactory(); until it is made public...
       
       for(String p: packages){
       	p = p.replace('.', '/');
       	Enumeration<URL> list = reg.getPackageResources(p, cl, recur);
           while(list.hasMoreElements()){
           	URL url = list.nextElement();
           	String path = url.getPath();
           	String cls = (OsgiRegistry.bundleEntryPathToClassName(path, "") + "class").replace(".class", "");
           	logger.info("Found(" + url.toURI().getScheme() + "):" + path + "-->" + cls);
           	
           	rc.registerClasses(reg.classForNameWithException(cls));
           	//finder.push(f.create(url.toURI(), recur));
           }
       }
       //rc.registerFinder(finder);

	//rc.registerFinder(new PackageNamesScanner(cl, packages, false)); !bundleentry is not bundle...
       //INFO: Found(bundleentry):/com/demo/app/restapi/impl/Status.class-->com.demo.app.restapi.impl.Status.
	
       //////////////////////////////////////////////////////////////////////////
	this.sc = new ServletContainer(rc);
}
 
开发者ID:bluekvirus,项目名称:osgi-starterkit,代码行数:37,代码来源:Config.java

示例9: setupActiveMqLibForTesting

import java.net.URL; //导入方法依赖的package包/类
static String setupActiveMqLibForTesting(boolean clean) {
    String[] urlsStrings = new String[]{
            "http://central.maven.org/maven2/org/apache/activemq/activemq-client/5.13.0/activemq-client-5.13.0.jar",
            "http://central.maven.org/maven2/org/apache/activemq/activemq-broker/5.13.0/activemq-broker-5.13.0.jar",
            "http://central.maven.org/maven2/org/apache/geronimo/specs/geronimo-j2ee-management_1.0_spec/1.0.1/geronimo-j2ee-management_1.0_spec-1.0.1.jar",
            "http://central.maven.org/maven2/org/fusesource/hawtbuf/hawtbuf/1.11/hawtbuf-1.11.jar" };

    try {
        File activeMqLib = new File("target/active-mq-lib");
        if (activeMqLib.exists() && clean) {
            FileUtils.deleteDirectory(activeMqLib);
        }
        activeMqLib.mkdirs();
        for (String urlString : urlsStrings) {
            URL url = new URL(urlString);
            String path = url.getPath();
            path = path.substring(path.lastIndexOf("/") + 1);
            logger.info("Downloading: " + path);
            ReadableByteChannel rbc = Channels.newChannel(url.openStream());
            try (FileOutputStream fos = new FileOutputStream(new File(activeMqLib, path))) {
                fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
                fos.close();
            }
        }
        return activeMqLib.getAbsolutePath();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to download ActiveMQ libraries.", e);
    }
}
 
开发者ID:SolaceLabs,项目名称:solace-integration-guides,代码行数:30,代码来源:TestUtils.java

示例10: merge_files

import java.net.URL; //导入方法依赖的package包/类
@Test
public void merge_files() throws IOException {
	// Given
	URL url = Thread.currentThread().getContextClassLoader().getResource("example_merge");
	File example = new File(url.getPath());
	Path resources = temp.newFolder().toPath();
	FileUtils.copyDirectory(example, resources.toFile());
	ResourcesManager manager = new ResourcesManager(resources, null);
	List<CarnotzetModule> modules = Arrays.asList(
			CarnotzetModule.builder().name("service3").serviceId("service3").build(),
			CarnotzetModule.builder().name("service2").serviceId("service2").build(),
			CarnotzetModule.builder().name("service1").serviceId("service1").build()
	);

	// When
	manager.resolveResources(modules);

	// Then
	Properties service3config = new Properties();
	service3config.load(Files.newInputStream(resources.resolve("resolved/service3/files/config.properties")));
	assertThat(service3config.getProperty("overridden.from.service2"), is("service2value"));
	assertThat(service3config.getProperty("overridden.from.service1"), is("service1value"));
	assertThat(service3config.getProperty("added.from.service3"), is("service3value"));
	assertThat(service3config.getProperty("added.from.service2"), is("service2value"));
	assertThat(service3config.getProperty("added.from.service1"), is("service1value"));
	assertThat(service3config.getProperty("added.from.service2.and.overridden.from.service1"), is("service1value"));

	Properties service3carnotzet = new Properties();
	service3carnotzet.load(Files.newInputStream(resources.resolve("resolved/service3/carnotzet.properties")));
	assertThat(service3carnotzet.getProperty("docker.image"), is("service3"));
	assertThat(service3carnotzet.getProperty("network.aliases"), is("my-service3"));

	Properties service3carnotzet2 = new Properties();
	service3carnotzet2.load(Files.newInputStream(resources.resolve("resolved/service3/files/injected/from/service1/injected.properties")));
	assertThat(service3carnotzet2.getProperty("injected.from.service1"), is("service1value"));
}
 
开发者ID:swissquote,项目名称:carnotzet,代码行数:37,代码来源:ResourcesManagerTest.java

示例11: URLtoSocketPermission

import java.net.URL; //导入方法依赖的package包/类
/**
 *  if the caller has a URLPermission for connecting to the
 *  given URL, then return a SocketPermission which permits
 *  access to that destination. Return null otherwise. The permission
 *  is cached in a field (which can only be changed by redirects)
 */
SocketPermission URLtoSocketPermission(URL url) throws IOException {

    if (socketPermission != null) {
        return socketPermission;
    }

    SecurityManager sm = System.getSecurityManager();

    if (sm == null) {
        return null;
    }

    // the permission, which we might grant

    SocketPermission newPerm = new SocketPermission(
        getHostAndPort(url), "connect"
    );

    String actions = getRequestMethod()+":" +
            getUserSetHeaders().getHeaderNamesInList();

    String urlstring = url.getProtocol() + "://" + url.getAuthority()
            + url.getPath();

    URLPermission p = new URLPermission(urlstring, actions);
    try {
        sm.checkPermission(p);
        socketPermission = newPerm;
        return socketPermission;
    } catch (SecurityException e) {
        // fall thru
    }
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:HttpURLConnection.java

示例12: checkAccess

import java.net.URL; //导入方法依赖的package包/类
/**
 * Check the protocol used in the systemId against allowed protocols
 *
 * @param systemId the Id of the URI
 * @param allowedProtocols a list of allowed protocols separated by comma
 * @param accessAny keyword to indicate allowing any protocol
 * @return the name of the protocol if rejected, null otherwise
 * @throws java.io.IOException
 */
public static String checkAccess(String systemId, String allowedProtocols, String accessAny) throws IOException {
    if (systemId == null || (allowedProtocols != null &&
            allowedProtocols.equalsIgnoreCase(accessAny))) {
        return null;
    }

    String protocol;
    if (!systemId.contains(":")) {
        protocol = "file";
    } else {
        URL url = new URL(systemId);
        protocol = url.getProtocol();
        if (protocol.equalsIgnoreCase("jar")) {
            String path = url.getPath();
            protocol = path.substring(0, path.indexOf(":"));
        } else if (protocol.equalsIgnoreCase("jrt")) {
            // if the systemId is "jrt" then allow access if "file" allowed
            protocol = "file";
        }
    }

    if (isProtocolAllowed(protocol, allowedProtocols)) {
        //access allowed
        return null;
    } else {
        return protocol;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:SecuritySupport.java

示例13: extractPath

import java.net.URL; //导入方法依赖的package包/类
@Override
protected String extractPath() {
  String result = "";
  try {
    URL urlObject = new URL(url);
    result = urlObject.getPath();
  } catch (MalformedURLException e) {
    throw new DataValidationException("the URL is malformed, core.db.command.url: " + url);
  }
  return result;
}
 
开发者ID:edgexfoundry,项目名称:core-command-client,代码行数:12,代码来源:CmdClientImpl.java

示例14: testNamespaces

import java.net.URL; //导入方法依赖的package包/类
@Test
public void testNamespaces() throws Exception {
    final URL res = Namespaces.class.getResource(nsDoc);
    final CuratorFramework zk = newClient(curator.getConnectString(), new RetryNTimes(10, 1000));
    zk.start();
    final TreeCache cache = new TreeCache(zk, ZNODE_NAMESPACES);
    cache.start();

    final NamespaceService svc1 = new Namespaces(zk, cache, res.getPath() + randomFilename());

    assertEquals(0, svc1.getNamespaces().size());

    final NamespaceService svc2 = new Namespaces(zk, cache, res.getPath());

    assertEquals(2, svc2.getNamespaces().size());
    assertEquals(LDP.URI, svc2.getNamespace("ldp").get());
    assertEquals("ldp", svc2.getPrefix(LDP.URI).get());

    assertFalse(svc2.getNamespace("jsonld").isPresent());
    assertFalse(svc2.getPrefix(JSONLD.URI).isPresent());
    assertTrue(svc2.setPrefix("jsonld", JSONLD.URI));
    assertEquals(3, svc2.getNamespaces().size());
    assertEquals(JSONLD.URI, svc2.getNamespace("jsonld").get());
    assertEquals("jsonld", svc2.getPrefix(JSONLD.URI).get());

    final Namespaces svc3 = new Namespaces(zk, cache);
    await().atMost(5, SECONDS).until(() -> 3 == svc3.getNamespaces().size());
    assertEquals(JSONLD.URI, svc3.getNamespace("jsonld").get());
    assertFalse(svc3.setPrefix("jsonld", JSONLD.URI));
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:31,代码来源:NamespacesTest.java

示例15: checkParams

import java.net.URL; //导入方法依赖的package包/类
private boolean checkParams(String url, String url2) {
    try {
        URL fullUrl = new URL(url2);
        String baseUrl = fullUrl.getProtocol() + "://" + fullUrl.getHost() + fullUrl.getPath();
        Log.d("BASEURL", "checkParams: " + baseUrl);

        if (!url.contains(baseUrl)) {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }


    try {
        UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(url);
        UrlQuerySanitizer sanitizer2 = new UrlQuerySanitizer(url2);
        String paymentId = sanitizer.getValue("paymentId");
        String paymentId2 = sanitizer2.getValue("paymentId");
        String referenceId = sanitizer.getValue("referenceId");
        String referenceId2 = sanitizer2.getValue("referenceId");

        if (paymentId.equalsIgnoreCase(paymentId2) && referenceId.equalsIgnoreCase(referenceId2)) {
            return true;
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return false;
}
 
开发者ID:paparateam,项目名称:papara-android,代码行数:34,代码来源:PaparaWebViewActivity.java


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