Example usage for java.net URL toString

List of usage examples for java.net URL toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:com.webautomation.ScreenCaptureHtmlUnitDriver.java

String downloadCss(WebClient webClient, WebWindow window, URL resourceUrl) throws Exception {
    if (cssjsCache.get(resourceUrl.toString()) == null) {
        cssjsCache.put(resourceUrl.toString(),
                webClient.getPage(window, new WebRequest(resourceUrl)).getWebResponse().getContentAsString());

    }// ww w  .  j  ava2s. c o  m
    return cssjsCache.get(resourceUrl.toString());
}

From source file:com.webautomation.ScreenCaptureHtmlUnitDriver.java

byte[] downloadImage(WebClient webClient, WebWindow window, URL resourceUrl) throws Exception {
    if (imagesCache.get(resourceUrl.toString()) == null) {
        imagesCache.put(resourceUrl.toString(), IOUtils.toByteArray(
                webClient.getPage(window, new WebRequest(resourceUrl)).getWebResponse().getContentAsStream()));
    }//from   w  w  w  . j  a v  a  2 s.c  o  m
    return imagesCache.get(resourceUrl.toString());
}

From source file:net.sourceforge.jaulp.lang.ClassUtilsTest.java

@Test
public void testGetURL() {
    URL actual = ClassUtils.getURL(Object.class);
    AssertJUnit.assertTrue(actual.toString().startsWith("jar:file:"));
    AssertJUnit.assertTrue(actual.toString().endsWith("/java/lang/Object.class"));
}

From source file:com.mengge.service.local.AppiumDriverLocalService.java

private void ping(long time, TimeUnit timeUnit) throws UrlChecker.TimeoutException {
    URL url = getUrl();
    try {/*from ww w.jav a2 s  .  co m*/
        URL status = new URL(url.toString() + "/status");
        new UrlChecker().waitUntilAvailable(time, timeUnit, status);
    } catch (MalformedURLException e) {
        throw new RuntimeException("URL " + url.toString().toString() + "/status");
    }
}

From source file:sagan.projects.support.VersionBadgeService.java

/**
 * Create a version badge for a given {@link Project} and {@link ProjectRelease}. The badge uses SVG and is returned as byte
 * array./*from   w  w w  . j  a va 2s  .  co  m*/
 *
 * @param project must not be {@literal null}.
 * @param projectRelease must not be {@literal null}.
 * @return
 * @throws IOException
 */
public byte[] createSvgBadge(Project project, ProjectRelease projectRelease) throws IOException {

    Assert.notNull(project, "Project must not be null!");
    Assert.notNull(projectRelease, "ProjectRelease must not be null!");

    URL template = getTemplate(projectRelease.getReleaseStatus());

    BadgeSvg svgDocument = xbProjector.io().url(template.toString()).read(BadgeSvg.class);

    List<Path> paths = svgDocument.getPaths();

    String label = project.getName();
    String version = projectRelease.getVersion();

    return createSvgBadge(svgDocument, paths, label, version);
}

From source file:org.apache.usergrid.chop.stack.StackTest.java

@Test
public void testCombo() throws Exception {
    stack.setName("UG-2.0").setId(uuid).setDataCenter("es-east-1c").setRuleSetName("UG-Chop-Rules")
            .addInboundRule(new BasicIpRule().withFromPort(80).withToPort(8080).withIpRanges("0.0.0.0/32")
                    .withIpProtocol("tcp"))
            .addInboundRule(new BasicIpRule().withFromPort(443).withToPort(8443).withIpRanges("0.0.0.0/32")
                    .withIpProtocol("tcp"))
            .add(new BasicCluster().setName("ElasticSearch").setSize(6).setInstanceSpec(
                    new BasicInstanceSpec().setKeyName("TestKeyPair").setImageId("ami-c56152ac")
                            .setScriptEnvProperty("ES_PATH", "/var/lib/elastic_search")
                            .setScriptEnvProperty("JAVA_HOME", "/user/lib/jvm/default").setType("m1.large")
                            .addSetupScript(new URL("file://./install_es.sh"))
                            .addSetupScript(new URL("file://./setup_cassandra.sh"))))
            .add(new BasicCluster().setName("Cassandra").setSize(6)
                    .setInstanceSpec(new BasicInstanceSpec().setKeyName("TestKeyPair")
                            .setImageId("ami-c56152ac")
                            .setScriptEnvProperty("CASSANDRA_PATH", "/var/lib/cassandra")
                            .setScriptEnvProperty("JAVA_HOME", "/user/lib/jvm/default").setType("m1.xlarge")
                            .addSetupScript(new URL("file://./install_cassandra.sh"))
                            .addSetupScript(new URL("file://./setup_cassandra.sh"))));

    ObjectMapper mapper = new ObjectMapper();
    String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(stack);
    LOG.info(json);//from  w  w  w  . j ava2  s. c  o  m
    LOG.info("---------");

    BasicStack foo = mapper.readValue(new StringReader(json), BasicStack.class);
    assertEquals("UG-2.0", foo.getName());
    assertEquals(uuid.toString(), foo.getId().toString());
    assertNotNull(foo.getClusters().get(0));
    assertEquals("ElasticSearch", foo.getClusters().get(0).getName());

    Cluster cluster = foo.getClusters().get(0);
    InstanceSpec spec = cluster.getInstanceSpec();
    assertEquals("file://./install_es.sh", spec.getSetupScripts().get(0).toString());
    //        URL script = spec.getSetupScripts().get( 0 );
    URL script = new URL("file://./install_es.sh");
    LOG.info("setup script path = {}", script.getPath());

    LOG.info("script modified = {}", script.getPath().substring(1));
    URL reloaded = getClass().getClassLoader().getResource(script.getPath().substring(1));
    LOG.info("reloaded form CL script path = {}", reloaded.toString());
}

From source file:com.netflix.dyno.contrib.ElasticConnectionPoolConfigurationPublisher.java

/**
 * Get library version by iterating through the classloader jar list and obtain the name from the jar filename.
 * This will not open the library jar files.
 * <p>/*from  w ww  .  j a  v  a 2  s.  c  o  m*/
 * This function assumes the conventional jar naming format and relies on the dash character to separate the
 * name of the jar from the version. For example, foo-bar-baz-1.0.12-CANDIDATE.
 *
 * @param libraryNames unique list of library names, i.e. "dyno-core"
 * @param classLoadedWithURLClassLoader For this to work, must have a URL based classloader
 *        This has been tested to be the case in Tomcat (WebAppClassLoader) and basic J2SE classloader
 * @return the version of the library (everything between library name, dash, and .jar)
 */
Map<String, String> getLibraryVersion(Class<?> classLoadedWithURLClassLoader, Set<String> libraryNames) {
    ClassLoader cl = classLoadedWithURLClassLoader.getClassLoader();
    Map<String, String> libraryVersionMapping = new HashMap<String, String>();

    if (cl instanceof URLClassLoader) {
        @SuppressWarnings("resource")
        URLClassLoader uCl = (URLClassLoader) cl;
        URL urls[] = uCl.getURLs();

        for (URL url : urls) {
            String fullNameWithVersion = url.toString().substring(url.toString().lastIndexOf('/'));
            if (fullNameWithVersion.length() > 4) { // all entries we attempt to parse must end in ".jar"
                String nameWithVersion = fullNameWithVersion.substring(1, fullNameWithVersion.length() - 4);
                int idx = findVersionStartIndex(nameWithVersion);
                if (idx > 0) {
                    String name = nameWithVersion.substring(0, idx - 1);
                    if (libraryNames.contains(name)) {
                        libraryVersionMapping.put(name, nameWithVersion.substring(idx));
                    }
                }
            }
        }
    }

    return libraryVersionMapping;
}

From source file:com.mycompany.crawlertest.GrabManager.java

/**
 *///from w ww .  j  a  v  a  2s.co m
private boolean shouldVisit(URL url, int depth) {
    if (masterList.contains(url)) {
        return false;
    }
    if (!url.toString().startsWith(urlBase)) {
        return false;
    }
    if (url.toString().endsWith(".pdf")) {
        return false;
    }
    if (depth > maxDepth) {
        return false;
    }
    if (masterList.size() >= maxUrls) {
        return false;
    }
    return true;
}

From source file:eu.artist.methodology.mpt.webapp.config.ListFileHandlerBean.java

public void save() throws IOException {

    String path_to_properties_file = getMptProperties().getProperty("path_to_reports") + "\\"
            + CurrentSession.getUserName() + "\\mpt" + CurrentSession.getUserName() + ".properties";

    checkPropertiesFile(path_to_properties_file);

    logger.debug("Path to properties file is " + path_to_properties_file);

    try {/*from w w  w  . j a va 2  s. c  om*/

        File f = new File(path_to_properties_file);

        URL url = f.toURI().toURL();

        logger.debug("File URL is " + url.toString());

        logger.info("Configuration saved");
        logger.debug("Selected file is " + selectedFile);
        PropertiesConfiguration config = new PropertiesConfiguration(url);

        String chosenButton = CurrentSession.getExternalContext().getRequestParameterMap().get("button");
        String propertyToSet = null;

        if ("mat".equalsIgnoreCase(chosenButton)) {
            propertyToSet = "mat_report";
        } else if ("tft".equalsIgnoreCase(chosenButton)) {
            propertyToSet = "tft_report";
        } else if ("bft".equalsIgnoreCase(chosenButton)) {
            propertyToSet = "bft_report";
        } else if ("mig".equalsIgnoreCase(chosenButton)) {
            propertyToSet = "mig_report";
        }

        config.setProperty(propertyToSet, "\\" + selectedFile);
        config.save();

        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Configuration saved"));

    } catch (Exception e) {

        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Configuration failed"));

        logger.error("Configuration not saved");

        e.printStackTrace();

    }
}

From source file:com.samebug.clients.search.api.client.SamebugClient.java

public @NotNull ClientResponse<SearchResults> searchSolutions(@NotNull final String stacktrace) {
    final URL url = urlBuilder.search();
    HttpPost post = new HttpPost(url.toString());
    post.setEntity(new UrlEncodedFormEntity(
            Collections.singletonList(new BasicNameValuePair("exception", stacktrace)), Consts.UTF_8));

    return rawClient.execute(post, new HandleAuthenticatedJsonRequest<SearchResults>(SearchResults.class));
}