當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。