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:com.quinsoft.zeidon.standardoe.JavaObjectEngine.java

/**
 * @param logger/*from   ww  w . j  a  va 2  s .co m*/
 */
private static String getClassPath(ZeidonLogger logger) {
    try {
        StringBuilder classpath = new StringBuilder();
        ClassLoader classLoader = classpath.getClass().getClassLoader();
        if (classLoader == null)
            classLoader = ClassLoader.getSystemClassLoader();

        URL[] urls = ((URLClassLoader) classLoader).getURLs();
        for (URL url : urls)
            classpath.append(url.getFile()).append("\n");

        return classpath.toString();
    } catch (Exception e) {
        if (logger != null)
            logger.error("Error trying to log classpath", e, (Object[]) null);

        return "<Error retrieving classpath>";
    }
}

From source file:org.apache.hadoop.gateway.AmbariServiceDefinitionTest.java

public static void setupGateway() throws Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();/*from www .jav a2 s.co  m*/

    config = new GatewayTestConfig();
    config.setGatewayHomeDir(gatewayDir.getAbsolutePath());

    URL svcsFileUrl = TestUtils.getResourceUrl(DAT, "test-svcs/readme.txt");
    File svcsFile = new File(svcsFileUrl.getFile());
    File svcsDir = svcsFile.getParentFile();
    config.setGatewayServicesDir(svcsDir.getAbsolutePath());

    String pathToStacksSource = "gateway-service-definitions/src/main/resources/services";
    File stacksSourceDir = new File(targetDir.getParent(), pathToStacksSource);
    if (!stacksSourceDir.exists()) {
        stacksSourceDir = new File(targetDir.getParentFile().getParent(), pathToStacksSource);
    }
    if (stacksSourceDir.exists()) {
        FileUtils.copyDirectoryToDirectory(stacksSourceDir, svcsDir);
    }

    File topoDir = new File(config.getGatewayTopologyDir());
    topoDir.mkdirs();

    File deployDir = new File(config.getGatewayDeploymentDir());
    deployDir.mkdirs();

    setupMockServers();
    startGatewayServer();
}

From source file:net.daporkchop.porkselfbot.util.HTTPUtils.java

/**
 * Concatenates the given {@link java.net.URL} and query.
 *
 * @param url URL to base off//from   w  w w. j  a v  a2s.c o m
 * @param query Query to append to URL
 * @return URL constructed
 */
public static URL concatenateURL(final URL url, final String query) {
    try {
        if (url.getQuery() != null && url.getQuery().length() > 0) {
            return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "&" + query);
        } else {
            return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "?" + query);
        }
    } catch (final MalformedURLException ex) {
        throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex);
    }
}

From source file:eu.planets_project.tb.impl.services.ServiceRegistryManager.java

/**
 * As the wsdlcontent is not well-formed we're not able to use DOM here.
 * Parse through the xml manually to return a list of given ServiceEndpointAddresses
 * @param xhtml//from   w w  w.java2s  . com
 * @return
 * @throws Exception
 */
@Deprecated
private static Set<URI> extractEndpointsFromWebPage(String xhtml) {
    Set<URI> ret = new HashSet<URI>();

    // Pull out all matching URLs:
    Matcher matcher = urlpattern.matcher(xhtml);
    while (matcher.find()) {
        //log.info("Found match: "+matcher.group());
        try {
            URL wsdlUrl = new URL(matcher.group());
            // Switch the authority for the 'proper' one:
            wsdlUrl = new URL(wsdlUrl.getProtocol(), PlanetsServerConfig.getHostname(),
                    PlanetsServerConfig.getPort(), wsdlUrl.getFile());
            //log.info("Got matching URL: "+wsdlUrl);
            try {
                ret.add(wsdlUrl.toURI());
            } catch (URISyntaxException e) {
            }
        } catch (MalformedURLException e) {
            log.warn("Could not parse URL from " + matcher.group());
        }
    }

    return ret;
}

From source file:com.t3.persistence.FileUtil.java

public static String getNameWithoutExtension(URL url) {
    return getNameWithoutExtension(new File(url.getFile()));
}

From source file:org.fcrepo.localservices.saxon.SaxonServlet.java

/**
 * Return a URL string in which the port is always specified.
 *//*from w w w . j  av a  2 s.co m*/
private static String normalizeURL(String urlString) throws MalformedURLException {
    URL url = new URL(urlString);
    if (url.getPort() == -1) {
        return url.getProtocol() + "://" + url.getHost() + ":" + url.getDefaultPort() + url.getFile()
                + (url.getRef() != null ? "#" + url.getRef() : "");
    } else {
        return urlString;
    }
}

From source file:ViewImageTest.java

/**
 * @param args/*from ww w . ja  va  2  s  . c om*/
 *            main parameters. first item may contain input file or folder
 *            URL
 * @return file or folder to be used : specified as first in args or default
 *         one
 */
private static File getInputURL(String args[]) {
    String fileURL;
    if (args != null && args.length > 0) {
        fileURL = args[0];
    } else {
        URL defaultURL = ViewImageTest.class.getResource(DEFAULT_IMG_RESOURCES);
        if (defaultURL == null) {
            throw new IllegalArgumentException("File not found : " + DEFAULT_IMG_RESOURCES);
        }
        fileURL = defaultURL.getFile();
    }
    return new File(fileURL);
}

From source file:org.paxml.core.ResourceLocator.java

/**
 * Make an Spring resource string from relative path which contains
 * wildcards.//from  w  ww  . ja  va  2s.c o  m
 * 
 * @param base
 *            the base Spring resource
 * @param relative
 *            the relative path
 * @return the absolute spring resource path
 */
public static String getRelativeResource(final Resource base, final String relative) {
    String result;
    // find from both class path and file system
    final boolean root = relative.startsWith("/") || relative.startsWith("\\");

    try {
        URL url = base.getURL();

        if (root) {
            result = url.getProtocol() + ":" + relative;
        } else {
            String path = FilenameUtils.getFullPathNoEndSeparator(url.getFile());
            result = url.getProtocol() + ":" + path + "/" + relative;
        }

    } catch (IOException e) {
        throw new PaxmlRuntimeException("Cannot get the relative path for plan file: " + base, e);
    }
    return result;
}

From source file:com.revo.deployr.rbroker.example.util.DeployRUtil.java

public static void retrieveFileUrls(List<URL> files, String type, String typeFilter, Logger log) {

    try {/*from   w  w w. j  a  v a 2s .co  m*/

        for (URL file : files) {

            String fileName = file.getFile().substring(file.getFile().lastIndexOf("/") + 1);

            /*
             * If present, strip jsessionid off repository
             * file names.
             */
            if (fileName.indexOf(";") != -1) {
                fileName = fileName.substring(0, fileName.indexOf(";"));
            }

            if (typeFilter == null || fileName.endsWith(typeFilter)) {
                log.info("[  TASK OUTPUT   ] Retrieved " + type + " output " + fileName + " [ URL ]");
                InputStream fis = null;
                try {
                    fis = file.openStream();
                    IOUtils.toByteArray(fis);
                } catch (Exception ex) {
                    log.warn("Working directory binary file " + ex);
                } finally {
                    IOUtils.closeQuietly(fis);
                }
            }
        }

    } catch (Exception ex) {
        log.warn("retrieveFileUrls: ex=" + ex);
    }
}

From source file:com.asual.summer.core.util.ResourceUtils.java

public static String getManifestAttribute(String key) {
    try {/*from   w w  w. ja  v  a2s.  c  o m*/
        if (!attributes.containsKey(key)) {
            String path = "META-INF/MANIFEST.MF";
            Manifest mf = new Manifest();
            URL resource = RequestUtils.getServletContext().getResource("/" + path);
            if (resource == null) {
                resource = getClasspathResources(path, false).get(0);
            }
            mf.read(new FileInputStream(resource.getFile()));
            attributes.put(key, mf.getMainAttributes().getValue(key));
        }
        return attributes.get(key);
    } catch (Exception e) {
        return "";
    }
}