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:Main.java

public static String restoreAvatarUrl(String stringUrl) {
    try {//from  w  w  w. j av  a2  s  . c  o m
        StringBuilder sb = new StringBuilder();
        URL url = new URL(stringUrl);
        sb.append(url.getProtocol()).append("://").append(url.getHost()).append(url.getPath());
        return sb.toString();
    } catch (MalformedURLException e) {
        return stringUrl;
    }
}

From source file:Main.java

public static String getNoQueryUrl(String source) {
    String dest = null;/*from  ww  w  .  ja v  a2  s. c o m*/
    try {
        URL sUrl = new URL(source);
        URL dUrl = new URL(sUrl.getProtocol(), sUrl.getHost(), sUrl.getPort(), sUrl.getPath());
        dest = dUrl.toString();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return dest;
}

From source file:edu.wustl.cab2b.common.authentication.GTSSynchronizer.java

private static void copyCACertificates(URL inFileURL) {
    int index = inFileURL.getPath().lastIndexOf('/');
    if (index > -1) {
        String fileName = inFileURL.getPath().substring(index + 1).trim();
        File destination = new File(
                gov.nih.nci.cagrid.common.Utils.getTrustedCerificatesDirectory() + File.separator + fileName);

        try {//from  w w  w  .j a v a  2  s. c  om
            FileUtils.copyURLToFile(inFileURL, destination);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            throw new AuthenticationException(
                    "Unable to copy CA certificates to [user.home]/.globus: " + e.getMessage(), e,
                    ErrorCodeConstants.CDS_003);
        }
    }
}

From source file:Main.java

/**
 * Translates a WebDAV URL, such as would be returned by the PUT method,
 * into a resource URI relative to the DAV root which can be passed to the
 * SOAP methods.//w  w w .  j a  v a 2s .  com
 * <p>
 * This is the inverse of makeDAVURL.
 * 
 * @param endpoint full URL of LNI Soap endpoint, as used with SOAP.
 * @param davurl the davurl
 * 
 * @return the string
 * 
 * @throws MalformedURLException the malformed URL exception
 */
public static String makeLNIURI(String endpoint, String davurl) throws MalformedURLException {
    URL emptyUrl = makeDAVURL(endpoint, null, null);
    URL url = new URL(davurl);
    return url.getPath().substring(emptyUrl.getPath().length());
}

From source file:com.contentful.vault.compiler.lib.TestUtils.java

public static String readTestResource(String fileName) throws IOException {
    URL resource = TestUtils.class.getClassLoader().getResource(fileName);
    return FileUtils.readFileToString(new File(resource.getPath()));
}

From source file:Main.java

/**
 * Compute the root directory of this maven project. This will result in the
 * same directory no matter if executed from Eclipse, this maven project root or
 * any parent maven pom directory. //w  w w. j  a  v a 2  s  .  c  om
 * 
 * @param anyTestClass Any test class *local* to the maven project, i.e that 
 * only exist in this maven project.
 * 
 * @param child The file that should be 
 * @return The root directory of this maven project.
 */
public static File computeMavenProjectRoot(Class<?> anyTestClass) {
    final String clsUri = anyTestClass.getName().replace('.', '/') + ".class";
    final URL url = anyTestClass.getClassLoader().getResource(clsUri);
    final String clsPath = url.getPath();
    // located in ./target/test-classes or ./eclipse-out/target
    final File target_test_classes = new File(clsPath.substring(0, clsPath.length() - clsUri.length()));
    // get parent's parent
    return target_test_classes.getParentFile().getParentFile();
}

From source file:Main.java

private static String escapeUrlString(String urlString) throws MalformedURLException, URISyntaxException {
    URL url = new URL(urlString);
    URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
            url.getQuery(), url.getRef());
    return uri.toURL().toString();
}

From source file:com.metadave.eql.parser.EQLParserTest.java

public static String loadResource(String name) throws Exception {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL url = loader.getResource(name);
    File f = new File(url.getPath());
    return org.apache.commons.io.FileUtils.readFileToString(f, "UTF-8");
}

From source file:Main.java

public static String getApplicationPath(Class cls) {
    if (cls == null)
        throw new java.lang.IllegalArgumentException("parameter is not null !");
    ClassLoader loader = cls.getClassLoader();
    String clsName = cls.getName() + ".class";
    Package pack = cls.getPackage();
    System.out.println("package name is : " + (pack == null));
    String path = "";
    if (pack != null) {
        String packName = pack.getName();
        if (packName.startsWith("java.") || packName.startsWith("javax."))
            throw new java.lang.IllegalArgumentException("This is system class");
        clsName = clsName.substring(packName.length() + 1);
        if (packName.indexOf(".") < 0)
            path = packName + "/";
        else {/*from  ww w  .ja va  2 s.co  m*/
            int start = 0, end = 0;
            end = packName.indexOf(".");
            while (end != -1) {
                path = path + packName.substring(start, end) + "/";
                start = end + 1;
                end = packName.indexOf(".", start);
            }
            path = path + packName.substring(start) + "/";
        }
    }
    java.net.URL url = loader.getResource(path + clsName);
    String realPath = url.getPath();
    int pos = realPath.indexOf("file:");
    if (pos > -1)
        realPath = realPath.substring(pos + 5);
    pos = realPath.indexOf(path + clsName);
    realPath = realPath.substring(0, pos - 1);
    if (realPath.endsWith("!"))
        realPath = realPath.substring(0, realPath.lastIndexOf("/"));
    try {
        realPath = java.net.URLDecoder.decode(realPath, "utf-8");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return realPath;
}

From source file:Main.java

public static String encodeDocumentUrl(String urlString) {
    try {//from   w w  w.  j  a  v  a 2 s .  co m

        URL url = new URL(urlString);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());

        return uri.toASCIIString();

    } catch (MalformedURLException e) {
        return null;
    } catch (URISyntaxException e) {
        return null;
    }

}