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.stratio.ingestion.morphline.commons.ReadXmlTest.java

@Before
public void setUp() throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder;//from   w  w w .j  av  a  2 s.  c  om
    docBuilder = factory.newDocumentBuilder();

    URL url = getClass().getResource(XML_FILE);
    File file = new File(url.getPath());

    doc = docBuilder.parse(file);
    doc.getDocumentElement().normalize();

    config = parse(MORPH_CONF_FILE).getConfigList("commands").get(0).getConfig("readXml");
    configAll = parse(MORPH_CONFALL_FILE).getConfigList("commands").get(0).getConfig("readXml");
    configHeader = parse(MORPH_CONFHEADER_FILE).getConfigList("commands").get(0).getConfig("readXml");
    configError = parse(MORPH_CONFERROR_FILE).getConfigList("commands").get(0).getConfig("readXml");
}

From source file:com.frostwire.ImageCache.java

private File getCacheFile(URL url) {
    String host = url.getHost();//from ww  w  . java2 s .  c om
    String path = url.getPath();
    if (host == null || host.length() == 0) { // dealing with local resource images, not perfect
        host = "localhost";
        path = new File(path).getName();
    }

    return new File(SharingSettings.getImageCacheDirectory(), File.separator + host + File.separator + path);
}

From source file:com.homesoft.component.report.pdf.XhtmlPdfGenerator.java

public String getResourcePath() {
    String resourcePath = null;// w  w w  .ja v a 2 s.c  o  m
    URL url = Thread.currentThread().getContextClassLoader().getResource("/");
    if (url != null) {
        resourcePath = url.getPath();
    } else {
        url = Thread.currentThread().getClass().getResource("/");
    }
    resourcePath = url.getPath();
    return resourcePath;
}

From source file:ch.kostceco.tools.siardval.service.impl.ConfigurationServiceImpl.java

private XMLConfiguration getConfig() {
    if (this.config == null) {
        try {/*  www .j  a  va 2 s.  c o m*/
            String path = "configuration/SIARDVal.conf.xml";
            URL locationOfJar = SIARDVal.class.getProtectionDomain().getCodeSource().getLocation();
            String locationOfJarPath = locationOfJar.getPath();
            if (locationOfJarPath.endsWith(".jar")) {
                File file = new File(locationOfJarPath);
                String fileParent = file.getParent();
                path = fileParent + "/" + path;
            }
            config = new XMLConfiguration(path);
        } catch (ConfigurationException e) {
            LOGGER.logInfo(getTextResourceService().getText(MESSAGE_CONFIGURATION_ERROR_1));
            // Das Konfigurations-File konnte nicht gelesen werden.
            LOGGER.logInfo(getTextResourceService().getText(MESSAGE_CONFIGURATION_ERROR_2));
            // Im gleichen Verzeichnis wie das ".jar"-File muss sich ein
            // Ordner namens "configuration" befinden.
            LOGGER.logInfo(getTextResourceService().getText(MESSAGE_CONFIGURATION_ERROR_3));
            // Im configuration-Ordner wiederum muss die Konfigurationsdatei
            // "SIARDVal.conf.xml" liegen.
            System.exit(1);
        }
    }
    return config;
}

From source file:com.datatorrent.contrib.enrichment.FileEnrichmentTest.java

@Test
public void testEnrichmentOperator() throws IOException, InterruptedException {
    URL origUrl = this.getClass().getResource("/productmapping.txt");

    URL fileUrl = new URL(this.getClass().getResource("/").toString() + "productmapping1.txt");
    FileUtils.deleteQuietly(new File(fileUrl.getPath()));
    FileUtils.copyFile(new File(origUrl.getPath()), new File(fileUrl.getPath()));

    MapEnrichmentOperator oper = new MapEnrichmentOperator();
    FSLoader store = new FSLoader();
    store.setFileName(fileUrl.toString());
    oper.setLookupFieldsStr("productId");
    oper.setStore(store);/*from   w w w.j  a v a  2s  .c  om*/

    oper.setup(null);

    /* File contains 6 entries, but operator one entry is duplicate,
     * so cache should contains only 5 entries after scanning input file.
     */
    //Assert.assertEquals("Number of mappings ", 7, oper.cache.size());

    CollectorTestSink<Map<String, Object>> sink = new CollectorTestSink<Map<String, Object>>();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    CollectorTestSink<Object> tmp = (CollectorTestSink) sink;
    oper.output.setSink(tmp);

    oper.beginWindow(0);
    Map<String, Object> tuple = Maps.newHashMap();
    tuple.put("productId", 3);
    tuple.put("channelId", 4);
    tuple.put("amount", 10.0);

    Kryo kryo = new Kryo();
    oper.input.process(kryo.copy(tuple));

    oper.endWindow();

    /* Number of tuple, emitted */
    Assert.assertEquals("Number of tuple emitted ", 1, sink.collectedTuples.size());
    Map<String, Object> emitted = sink.collectedTuples.iterator().next();

    /* The fields present in original event is kept as it is */
    Assert.assertEquals("Number of fields in emitted tuple", 4, emitted.size());
    Assert.assertEquals("value of productId is 3", tuple.get("productId"), emitted.get("productId"));
    Assert.assertEquals("value of channelId is 4", tuple.get("channelId"), emitted.get("channelId"));
    Assert.assertEquals("value of amount is 10.0", tuple.get("amount"), emitted.get("amount"));

    /* Check if productCategory is added to the event */
    Assert.assertEquals("productCategory is part of tuple", true, emitted.containsKey("productCategory"));
    Assert.assertEquals("value of product category is 1", 5, emitted.get("productCategory"));

}

From source file:com.samsung.sjs.SJSTest.java

protected String getInputScriptPath() {
    URL url = this.getClass().getResource("/testinput/" + getTestDir());
    String path = url.getPath();
    String inputScript = path + getName().substring(getName().indexOf('_') + 1) + ".js";
    return inputScript;
}

From source file:com.textuality.keybase.lib.prover.Coinbase.java

@Override
public boolean fetchProofData() {

    try {/* w w  w .  j ava2s  .  com*/
        JSONObject sigJSON = readSig(mProof.getSigId());

        String proofUrl = mProof.getProofUrl();

        // fetch the post
        Fetch fetch = new Fetch(proofUrl);
        String problem = fetch.problem();
        if (problem != null) {
            mLog.add(problem);
            return false;
        }

        // Paranoid Interlude:
        // Lets make sure the URL is of the form https://coinbase.com/<nametag>/public-key
        //  and the actual host after redirects is coinbase
        //
        URL url = new URL(proofUrl);
        if (!(url.getProtocol().equals("https") && url.getHost().equals("coinbase.com")
                && url.getPath().equals("/" + mProof.getHandle() + "/public-key"))) {
            mLog.add("Bogus Coinbase proof URL: " + proofUrl);
            return false;
        }
        url = new URL(fetch.getActualUrl());
        if (!url.getHost().equals("coinbase.com")) {
            mLog.add("Coinbase proof doesnt come from coinbase.com: " + fetch.getActualUrl());
            return false;
        }

        // verify that message appears in body, which coinbase messes up with \rs
        String body = fetch.getBody().replace("\r", "");
        if (!body.contains(mPgpMessage)) {
            mLog.add("Coinbase proof doesnt contain signed PGP message");
            return false;
        }

        return true;

    } catch (KeybaseException e) {
        mLog.add("Keybase API problem: " + e.getLocalizedMessage());
    } catch (JSONException e) {
        mLog.add("Broken JSON message: " + e.getLocalizedMessage());
    } catch (MalformedURLException e) {
        mLog.add("Malformed Coinbase proof URL");
    }
    return false;
}

From source file:net.hillsdon.reviki.wiki.renderer.creole.CreoleLinkContentsSplitter.java

/**
 * Splits links of the form target or text|target where target is
 * /*from   w w  w. j a  va  2s .c  o m*/
 * PageName wiki:PageName PageName#fragment wiki:PageName#fragment
 * A String representing an absolute URI scheme://valid/absolute/uri
 * Any character not in the `unreserved`, `punct`, `escaped`, or `other` categories (RFC 2396),
 * and not equal '/' or '@', is %-encoded. 
 * 
 * @param in The String to split
 * @return The split LinkParts
 */
LinkParts split(final String in) {
    String target = StringUtils.trimToEmpty(StringUtils.substringBefore(in, "|"));
    String text = StringUtils.trimToNull(StringUtils.substringAfter(in, "|"));
    if (target == null) {
        target = "";
    }
    if (text == null) {
        text = target;
    }
    // Link target can be PageName, wiki:PageName or a URL.
    URI uri = null;
    try {
        URL url = new URL(target);

        uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        if (uri.getPath() == null || !uri.isAbsolute()) {
            uri = null;
        }
    } catch (URISyntaxException e) {
        // uri remains null
    } catch (MalformedURLException e) {
        // uri remains null
    }

    if (uri != null) {
        return new LinkParts(text, uri);
    } else {
        // Split into wiki:pageName
        String[] parts = target.split(":", 2);
        String wiki = null;
        String pageName = target;
        if (parts.length == 2) {
            wiki = parts[0];
            pageName = parts[1];
        }

        // Split into pageName#fragment
        parts = pageName.split("#", 2);
        String fragment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            fragment = parts[1];
        }

        // Split into pageName/attachment
        parts = pageName.split("/", 2);
        String attachment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            attachment = parts[1];
        }

        return new LinkParts(text, wiki, pageName, fragment, attachment);
    }
}

From source file:com.collective.celos.JettyServer.java

private void startServer() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("WEB-INF");
    URIBuilder uriBuilder = new URIBuilder(url.toURI());
    uriBuilder.setPath(Paths.get(url.getPath()).getParent().toString());

    context = new WebAppContext(uriBuilder.toString() + "/", "/");
    context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

    context.setExtractWAR(false);/* w w  w. ja  va  2  s. c  om*/

    server.setHandler(context);
    server.start();
}

From source file:com.ericsson.eiffel.remrem.generate.EiffelRemremControllerIntegrationTest.java

private String loadEventBody(final String fileName) throws IOException {
    URL url = getClass().getClassLoader().getResource(fileName);
    assert url != null;
    String path = url.getPath().replace("%20", " ");
    File file = new File(path);
    final byte[] bytes = Files.readAllBytes(file.toPath());
    return new String(bytes);
}