Example usage for java.net URL getFile

List of usage examples for java.net URL getFile

Introduction

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

Prototype

public String getFile() 

Source Link

Document

Gets the file name of this URL .

Usage

From source file:net.grinder.util.AbstractGrinderClassPathProcessor.java

/**
 * Construct classPath from current classLoader.
 *
 * @param logger logger/*from  www . ja va 2  s.c  om*/
 * @return classpath optimized for grinder.
 */
public String buildClasspathBasedOnCurrentClassLoader(Logger logger) {
    URL[] urls = ((URLClassLoader) AbstractGrinderClassPathProcessor.class.getClassLoader()).getURLs();

    StringBuilder builder = new StringBuilder();
    for (URL each : urls) {
        builder.append(each.getFile()).append(File.pathSeparator);
    }
    if (builder.length() < 300) {
        // In case of the URLClassLoader is not activated, Try with system class path
        final String property = System.getProperty("java.class.path", "");
        for (String each : property.split(File.pathSeparator)) {
            builder.append(each).append(File.pathSeparator);
        }
    }
    return filterClassPath(builder.toString(), logger);
}

From source file:com.photon.maven.plugins.android.AbstractAndroidMojoTest.java

public void givenApidemosPlatformtestsApkThenPackageIsFound() throws IOException, MojoExecutionException {
    final URL resource = this.getClass().getResource("apidemos-platformtests-0.1.0-SNAPSHOT.apk");
    final String foundPackage = androidMojo.extractPackageNameFromApk(new File(resource.getFile()));
    Assert.assertEquals("com.example.android.apis.tests", foundPackage);
}

From source file:com.revo.deployr.rbroker.example.data.io.anon.discrete.task.RepoFileInGraphicsPlotOut.java

public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult) {

    if (rTaskResult.isSuccess()) {

        log.info("[  TASK RESULT   ] Discrete task " + "completed in " + rTaskResult.getTimeOnCall()
                + "ms [ RTaskResult ].");

        /*//from w  w  w.j a  va 2  s  .  co  m
         * Retrieve R graphics device plots (results) called
         * unnamedplot*.png that was generated by the execution.
         */
        List<URL> results = rTaskResult.getGeneratedPlots();

        for (URL result : results) {
            log.info("[  DATA OUTPUT   ] Retrieved graphics device " + "plot "
                    + result.getFile().substring(result.getFile().lastIndexOf("/") + 1) + " [ URL ]");
            InputStream fis = null;
            try {
                fis = result.openStream();
                IOUtils.toByteArray(fis);
            } catch (Exception ex) {
                log.warn("Graphics device plot " + ex);
            } finally {
                IOUtils.closeQuietly(fis);
            }
        }
    } else {
        log.info("[  TASK RESULT   ] Discrete task " + "failed, cause " + rTaskResult.getFailure());
    }

    /*
     * Unblock main thread so example application can release 
     * resources before exit.
     */
    latch.countDown();
}

From source file:br.gov.frameworkdemoiselle.tools.nimble.eclipse.NimbleRunner.java

private String transformToAbsolutePath(URL url) {
    String absolutePath;//from   w ww. ja  va  2  s.  c  o  m
    try {
        URL transformedUrl = FileLocator.toFileURL(url);
        File file = new File(transformedUrl.getFile());
        absolutePath = file.getAbsolutePath();
    } catch (IOException e) {
        absolutePath = "";
        e.printStackTrace();
    }
    return absolutePath;
}

From source file:com.cognifide.aet.job.common.ArtifactDAOMock.java

@Override
public Artifact getArtifact(DBKey dbKey, String objectID) {

    URL filePath = getClass().getClassLoader().getResource(mocksPath + "/" + objectID);
    Artifact result = null;/*from w ww .  j ava  2 s.  co m*/
    try {
        result = new Artifact(new FileInputStream(filePath.getFile()), StringUtils.EMPTY);
    } catch (FileNotFoundException e) {
        return null;
    }
    return result;
}

From source file:org.apache.james.container.spring.osgi.AbstractBundleTracker.java

@Override
public void bundleChanged(BundleEvent event) {
    Bundle b = event.getBundle();/* ww w .  ja  va2 s.co  m*/

    // Check if the event was fired for this class
    if (b.equals(this.context.getBundle())) {
        return;
    }

    switch (event.getType()) {
    case BundleEvent.STARTED:
        Enumeration<?> entrs = b.findEntries("/", "*.class", true);
        if (entrs != null) {

            // Loop over all the classes
            while (entrs.hasMoreElements()) {
                URL e = (URL) entrs.nextElement();
                String file = e.getFile();

                String className = file.replaceAll("/", ".").replaceAll(".class", "").replaceFirst(".", "");
                if (className.equals(configuredClass)) {
                    try {

                        BeanFactory bFactory = getBeanFactory(b.getBundleContext());
                        Class<?> clazz = getServiceClass();

                        // Create the definition and register it
                        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) bFactory;
                        BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(className)
                                .getBeanDefinition();
                        registry.registerBeanDefinition(getComponentName(), def);

                        // register the bean as service in the OSGI-Registry
                        osgiFactoryBean = new OsgiServiceFactoryBean();
                        osgiFactoryBean.setTargetBeanName(getComponentName());
                        osgiFactoryBean.setBeanFactory(bFactory);
                        osgiFactoryBean.setBundleContext(b.getBundleContext());
                        osgiFactoryBean.setInterfaces(new Class[] { clazz });
                        osgiFactoryBean.afterPropertiesSet();
                        logger.debug("Registered " + configuredClass + " in the OSGI-Registry with interface "
                                + clazz.getName());
                    } catch (Exception e1) {
                        logger.error("Unable to register " + configuredClass + " in the OSGI-Registry", e1);
                    }
                }
            }
        }
        break;
    case BundleEvent.STOPPED:
        // check if we need to destroy the OsgiFactoryBean. This also include the unregister from the OSGI-Registry
        if (osgiFactoryBean != null) {
            osgiFactoryBean.destroy();
            osgiFactoryBean = null;
            logger.debug("Unregistered " + configuredClass + " in the OSGI-Registry with interface "
                    + getServiceClass().getName());

        }
        break;
    default:
        break;
    }

}

From source file:de.ipbhalle.metfusion.utilities.chemaxon.ChemAxonUtilities.java

/**
 * The default constructor for this utility class.
 * It requires a valid filepath to a parameter XML file.
 * Default would be ecfp.xml. Alternative for FCFP generation would be fcfp.xml.
 * //  w w  w  .  j  a v  a2 s .  c om
 * @param pathConfigXML - the filepath to the configuration file
 * @param generateFCFP - indicates whether FCFP should be generated rather than
 * default ECFP
 */
public ChemAxonUtilities(String pathConfigXML) {
    File path = new File(pathConfigXML);
    if (pathConfigXML.isEmpty()) { // default to standard ecfp configuration if path is empty
        URL url = this.getClass().getResource("ecfp.xml");
        path = new File(url.getFile());
    }

    paramConfig = new ECFPParameters(path); // generate ECFP

    // read in license file if no property is given
    if (System.getProperty("chemaxon.license.url") == null) {
        //URL license = this.getClass().getResource("license.cxl");
        InputStream is = getClass().getResourceAsStream("license.cxl");
        try {
            String xml = IOUtils.toString(is, "UTF-8");
            LicenseManager.setLicense(xml);
            //LicenseManager.setLicenseFile(license.getFile());
        } catch (LicenseProcessingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.log4ic.compressor.servlet.CompressionServlet.java

protected String getRootAbsolutePath(ServletContext context) {
    String prefix = context.getRealPath("/");

    if (StringUtils.isBlank(prefix)) {
        java.net.URL url = this.getClass().getResource("/");
        prefix = url.getFile();
    }//from www.j  av  a2  s .  c om
    if (!prefix.endsWith("/")) {
        prefix += "/";
    }
    return prefix;
}

From source file:com.asual.summer.core.resource.MessageResource.java

public void setWildcardLocations(String[] locations) {

    super.setLocations(locations);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    List<Resource[]> resourceLocations = new ArrayList<Resource[]>();

    List<String> fileBasenames = new ArrayList<String>();
    List<String> jarBasenames = new ArrayList<String>();

    for (String location : locations) {
        try {/*from   w w  w.j  a  v  a2 s .c om*/
            Resource[] wildcard = (Resource[]) ArrayUtils.addAll(
                    resolver.getResources(location + "*.properties"),
                    resolver.getResources(location + "*.xml"));
            if (wildcard != null && wildcard.length > 0) {
                resourceLocations.add(wildcard);
            }
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }

    int i = 0;
    boolean entries = true;

    while (entries) {
        entries = false;
        for (Resource[] location : resourceLocations) {
            if (location.length > i) {
                try {
                    URL url = location[i].getURL();
                    boolean isJar = ResourceUtils.isJarURL(url);
                    String basename = "classpath:" + url.getFile()
                            .replaceFirst(isJar ? "^.*" + ResourceUtils.JAR_URL_SEPARATOR
                                    : "^(.*/test-classes|.*/classes|.*/resources)/", "")
                            .replaceAll("(_\\w+){0,3}\\.(properties|xml)", "");
                    if (isJar) {
                        if (!jarBasenames.contains(basename)) {
                            jarBasenames.add(basename);
                        }
                    } else {
                        if (!fileBasenames.contains(basename)) {
                            fileBasenames.add(basename);
                        }
                    }
                } catch (IOException e) {
                    logger.error(e.getMessage(), e);
                }
                entries = true;
            }
        }
        i++;
    }

    fileBasenames.addAll(jarBasenames);

    rbms.clearCache();
    rbms.setBasenames(fileBasenames.toArray(new String[fileBasenames.size()]));
}

From source file:io.liveoak.testtools.AbstractTestCase.java

@Before
public void setupUserDir() {
    String name = getClass().getName().replace(".", "/") + ".class";
    URL resource = getClass().getClassLoader().getResource(name);

    if (resource != null) {
        File current = new File(resource.getFile());

        while (current.exists()) {
            if (current.isDirectory()) {
                if (new File(current, "pom.xml").exists()) {
                    this.projectRoot = current;
                    break;
                }//from ww  w .  j  a  va2 s .  c o  m
            }

            current = current.getParentFile();
        }
    }

    if (this.projectRoot != null) {
        System.setProperty("user.dir", this.projectRoot.getAbsolutePath());
    }
}