Example usage for java.net URL toURI

List of usage examples for java.net URL toURI

Introduction

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

Prototype

public URI toURI() throws URISyntaxException 

Source Link

Document

Returns a java.net.URI equivalent to this URL.

Usage

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

public static File getRootApplicationContentPath() {
    URLClassLoader sysloader = (URLClassLoader) JarUtils.class.getClassLoader();
    URL[] urls = sysloader.getURLs();
    String classesPath = "WEB-INF/classes/";
    if (urls != null) {
        for (URL url : urls) {
            try {
                if (url.getPath().endsWith(classesPath)) {
                    return new File(url.toURI()).getParentFile().getParentFile();
                }/*from  w w w .  j ava2  s .  co m*/
            } catch (Exception e) {
                logger.error(e);
            }
        }
    }
    return null;
}

From source file:edu.caltech.ipac.firefly.server.network.HttpServices.java

public static int getDataViaUrl(URL url, OutputStream results) {
    GetMethod getter = null;//from  w ww . jav a2  s . c o  m
    try {
        getter = new GetMethod(url.toURI().toString());
        executeMethod(getter);
        readBody(results, getter.getResponseBodyAsStream());
        return getter.getStatusLine().getStatusCode();
    } catch (Exception e) {
        LOG.error(e);
    } finally {
        if (getter != null) {
            getter.releaseConnection();
        }
    }
    return 500;
}

From source file:com.qwazr.compiler.JavaCompiler.java

private final static String buildClassPath(File[] classPathArray, Collection<URL> urlCollection)
        throws MalformedURLException, URISyntaxException {
    final List<String> classPathes = new ArrayList<>();

    URLClassLoader classLoader = (URLClassLoader) URLClassLoader.getSystemClassLoader();
    if (classLoader != null && classLoader.getURLs() != null) {
        for (URL url : classLoader.getURLs()) {
            String path = new File(url.toURI()).getAbsolutePath();
            classPathes.add(path);/*from   w w w .j  ava  2s  .  c o m*/
            urlCollection.add(url);
        }
    }

    if (classPathArray != null) {
        for (File classPathFile : classPathArray) {
            if (classPathFile.isDirectory()) {
                for (File f : classPathFile.listFiles((FileFilter) FileFileFilter.FILE)) {
                    classPathes.add(f.getAbsolutePath());
                    urlCollection.add(f.toURI().toURL());
                }
            } else if (classPathFile.isFile()) {
                classPathes.add(classPathFile.getAbsolutePath());
                urlCollection.add(classPathFile.toURI().toURL());
            }
        }
    }
    if (classPathes.isEmpty())
        return null;
    return StringUtils.join(classPathes, File.pathSeparator);
}

From source file:functionaltests.RestFuncTHelper.java

private static String toPath(URL url) throws Exception {
    return (new File(url.toURI())).getCanonicalPath();
}

From source file:eu.planets_project.services.datatypes.Content.java

/**
 * Create content by reference.//from w ww.  ja v a 2 s. com
 * @param reference The URL reference to the actual content
 * @return A content instance referencing the given location
 */
public static DigitalObjectContent byReference(final URL reference) {
    URI uriReference = null;
    /* we do not really expect a URI syntax exception on conversion from URL ... */
    try {
        uriReference = reference.toURI();
    } catch (URISyntaxException use) {
        System.out.println(use.getClass().getName() + ": " + use.getMessage());
    }
    return new ImmutableContent(uriReference);
}

From source file:com.splunk.shuttl.testutil.TUtilsBucket.java

private static Bucket copyBucketWithUrl(URL bucketUrl) {
    try {// w ww.j a va 2s.  c o m
        return createTempCopyOfBucketFromDirectory(new File(bucketUrl.toURI()));
    } catch (Exception e) {
        TUtilsTestNG.failForException("Could not create bucket", e);
        return null;
    }
}

From source file:io.specto.hoverfly.junit.HoverflyRuleUtils.java

static URI findResourceOnClasspath(String resourceName) throws URISyntaxException {
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final URL resource = classLoader.getResource(resourceName);
    if (resource == null) {
        throw new IllegalArgumentException("Resource not found with name: " + resourceName);
    }//w  w w  .  j a  v a  2  s .  c o m
    return resource.toURI();
}

From source file:it.geosolutions.geobatch.opensdi.csvingest.utils.CSVSchemaHandler.java

/**
 * Search and load for a properties file called as the entity. 
 *  /*from   w w  w .j  a v a 2  s  . co  m*/
 * @param entityNames
 */
public static Map<String, String> loadEntityProperties(String entityName) {
    if (entityName == null || entityName.isEmpty()) {
        throw new IllegalArgumentException("entityName is null or empty... this should never happen...");
    }
    URL fileURL = searchpropertiesFile(entityName);
    File propFile;
    try {
        propFile = new File(fileURL.toURI());
    } catch (URISyntaxException e1) {
        throw new IllegalArgumentException("Unable to find property file for this CSV Processor...");
    }
    return loadProperties(propFile);
}

From source file:com.feilong.core.net.URLUtil.java

/**
 *  {@link URL}? {@link URI}.//from  ww  w. ja  va 2s. c om
 *
 * @param url
 *            the url
 * @return  <code>url</code> null, {@link NullPointerException}<br>
 * @see "org.springframework.util.ResourceUtils#toURI(URL)"
 * @see java.net.URL#toURI()
 * @since 1.2.2
 */
public static URI toURI(URL url) {
    Validate.notNull(url, "url can't be null!");
    try {
        return url.toURI();
    } catch (URISyntaxException e) {
        throw new URIParseException(e);
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.ObjectsTest.java

private static List<String> getObjects(final BrowserVersion browserVersion) throws Exception {
    final URL url = ObjectsTest.class.getClassLoader()
            .getResource("objects/objects." + browserVersion.getNickname() + ".txt");
    return FileUtils.readLines(new File(url.toURI()));
}