Example usage for java.net URL getPath

List of usage examples for java.net URL getPath

Introduction

In this page you can find the example usage for java.net URL getPath.

Prototype

public String getPath() 

Source Link

Document

Gets the path part of this URL .

Usage

From source file:com.katsu.dwm.reflection.JarUtils.java

/**
 * Retrieve all jar files in directoy/* www.  j av a  2s . c om*/
 * @return array of jar {@link File Files}
 */
public static List<File> getJarFiles() {
    URLClassLoader sysloader = (URLClassLoader) JarUtils.class.getClassLoader();
    URL[] urls = sysloader.getURLs();
    List<File> result = new ArrayList<File>();
    if (urls != null) {
        for (URL url : urls) {
            try {
                logger.trace("URL detected: " + url);
                if (url.getPath().toLowerCase().endsWith(".jar")) {
                    result.add(new File(url.toURI()));
                }
            } catch (Exception e) {
                logger.error(e);
            }
        }
    }
    return result;
}

From source file:com.mingsoft.weixin.http.HttpClientConnectionManager.java

/**
 * ?GET??//from  www.j a  v  a2s.  c om
 * 
 * @param url
 * @return
 */
public static HttpGet getGetMethod(String url) {
    URI uri = null;
    try {
        URL _url = new URL(url);
        uri = new URI(_url.getProtocol(), _url.getHost(), _url.getPath(), _url.getQuery(), null);

    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    HttpGet pmethod = new HttpGet(uri);
    // ??
    pmethod.addHeader("Connection", "keep-alive");
    pmethod.addHeader("Cache-Control", "max-age=0");
    pmethod.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
    pmethod.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/;q=0.8");
    return pmethod;
}

From source file:cop.raml.processor.AbstractProcessorTest.java

protected static File getResourceAsFile(String path) {
    URL url = AbstractProcessorTest.class.getClassLoader().getResource(path);

    try {//from   w w w.jav a 2s  .  com
        return url != null ? new File(url.toURI()) : null;
    } catch (URISyntaxException ignored) {
        return new File(url.getPath());
    }
}

From source file:com.mingsoft.weixin.http.HttpClientConnectionManager.java

/**
 * ?post??/*from www . j  ava 2  s  .  co m*/
 * 
 * @param url
 * @return
 */
public static HttpPost getPostMethod(String url) {

    URI uri = null;
    try {
        URL _url = new URL(url);
        uri = new URI(_url.getProtocol(), _url.getHost(), _url.getPath(), _url.getQuery(), null);

    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    HttpPost pmethod = new HttpPost(uri); // ??
    pmethod.addHeader("Connection", "keep-alive");
    pmethod.addHeader("Accept", "*/*");
    pmethod.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    pmethod.addHeader("Host", "mp.weixin.qq.com");
    pmethod.addHeader("X-Requested-With", "XMLHttpRequest");
    pmethod.addHeader("Cache-Control", "max-age=0");
    pmethod.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
    return pmethod;
}

From source file:org.jboss.as.test.integration.web.security.cert.WebSecurityCERTTestCase.java

public static HttpClient wrapClient(HttpClient base, String alias) {
    try {//from   w ww  .  j  a v  a 2  s .c  om
        SSLContext ctx = SSLContext.getInstance("TLS");
        JBossJSSESecurityDomain jsseSecurityDomain = new JBossJSSESecurityDomain("client-cert");
        jsseSecurityDomain.setKeyStorePassword("changeit");
        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        URL keystore = tccl.getResource("security/client.keystore");
        jsseSecurityDomain.setKeyStoreURL(keystore.getPath());
        jsseSecurityDomain.setClientAlias(alias);
        jsseSecurityDomain.reloadKeyAndTrustStore();
        KeyManager[] keyManagers = jsseSecurityDomain.getKeyManagers();
        TrustManager[] trustManagers = jsseSecurityDomain.getTrustManagers();
        ctx.init(keyManagers, trustManagers, null);
        X509HostnameVerifier verifier = new X509HostnameVerifier() {

            @Override
            public void verify(String s, SSLSocket sslSocket) throws IOException {
            }

            @Override
            public void verify(String s, X509Certificate x509Certificate) throws SSLException {
            }

            @Override
            public void verify(String s, String[] strings, String[] strings1) throws SSLException {
            }

            @Override
            public boolean verify(String string, SSLSession ssls) {
                return true;
            }
        };
        SSLSocketFactory ssf = new SSLSocketFactory(ctx, verifier);//SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        ClientConnectionManager ccm = base.getConnectionManager();
        SchemeRegistry sr = ccm.getSchemeRegistry();
        sr.register(new Scheme("https", 8380, ssf));
        return new DefaultHttpClient(ccm, base.getParams());
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:com.tacitknowledge.util.discovery.ClasspathUtils.java

/**
 * Get the list of classpath components//from w  w  w . j  a  v a2  s. co  m
 *
 * @param ucl url classloader
 * @return List of classpath components
 */
private static List getUrlClassLoaderClasspathComponents(URLClassLoader ucl) {
    List components = new ArrayList();

    URL[] urls = new URL[0];

    // Workaround for running on JBoss with UnifiedClassLoader3 usage
    // We need to invoke getClasspath() method instead of getURLs()
    if (ucl.getClass().getName().equals("org.jboss.mx.loading.UnifiedClassLoader3")) {
        try {
            Method classPathMethod = ucl.getClass().getMethod("getClasspath", new Class[] {});
            urls = (URL[]) classPathMethod.invoke(ucl, new Object[0]);
        } catch (Exception e) {
            LogFactory.getLog(ClasspathUtils.class)
                    .debug("Error invoking getClasspath on UnifiedClassLoader3: ", e);
        }
    } else {
        // Use regular ClassLoader method to get classpath
        urls = ucl.getURLs();
    }

    for (int i = 0; i < urls.length; i++) {
        URL url = urls[i];
        components.add(getCanonicalPath(url.getPath()));
    }

    return components;
}

From source file:net.krotscheck.util.ResourceUtil.java

/**
 * Convert a resource path to an absolute file path.
 *
 * @param resourcePath The resource-relative path to resolve.
 * @return The absolute path to this resource.
 *//* ww w.j  av a  2  s .c  o  m*/
public static String getPathForResource(final String resourcePath) {
    URL path = ResourceUtil.class.getResource(resourcePath);
    if (path == null) {
        path = ResourceUtil.class.getResource("/");
        File tmpFile = new File(path.getPath(), resourcePath);
        return tmpFile.getPath();
    }

    return path.getPath();
}

From source file:net.krotscheck.util.ResourceUtil.java

/**
 * Convert a resource path to a File object.
 *
 * @param resourcePath The resource-relative path to resolve.
 * @return A file instance representing the resource in question.
 *///w  w w. j  a  v a2 s .co  m
public static File getFileForResource(final String resourcePath) {
    URL path = ResourceUtil.class.getResource(resourcePath);
    if (path == null) {
        path = ResourceUtil.class.getResource("/");
        return new File(new File(path.getPath()), resourcePath);
    }

    return new File(path.getPath());
}

From source file:com.qwazr.utils.LinkUtils.java

public final static String urlHostPathWrapReduce(String url, int maxSize) {
    URL u;
    try {// w ww .ja va2  s  . co m
        u = new URL(url);
    } catch (MalformedURLException e) {
        return url;
    }
    String path = StringUtils.fastConcat(u.getHost(), '/', u.getPath());
    String[] frags = StringUtils.split(path, '/');
    if (frags.length < 2)
        return path;
    int startPos = 1;
    int endPos = frags.length - 2;
    StringBuilder sbStart = new StringBuilder(frags[0]);
    StringBuilder sbEnd = new StringBuilder(frags[frags.length - 1]);
    int length = sbStart.length() + sbEnd.length();
    for (;;) {
        boolean bHandled = false;
        if (startPos != -1 && startPos < endPos) {
            if (frags[startPos].length() + length < maxSize) {
                sbStart.append('/');
                sbStart.append(frags[startPos++]);
                bHandled = true;
            }
        }
        if (endPos != -1 && endPos > startPos) {
            if (frags[endPos].length() + length < maxSize) {
                sbEnd.insert(0, '/');
                sbEnd.insert(0, frags[endPos--]);
                bHandled = true;
            }
        }
        if (!bHandled)
            break;
    }
    return StringUtils.fastConcat(sbStart, "//", sbEnd);
}

From source file:Main.java

public static boolean isPlaylistUrl(String url) {
    if (url == null) {
        return false;
    }/*from   w  ww  .j  av a2s . co  m*/

    try {
        URL _url = new URL(url);
        String host = _url.getHost();
        if (host == null) {
            return false;
        }
        if (!host.contains("nicovideo.jp")) {
            return false;
        }
        String path = _url.getPath();
        if (path == null) {
            return false;
        }
        return path.startsWith("/search") || path.startsWith("/mylist");
    } catch (MalformedURLException e) {
    }

    return false;
}