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.github.kutschkem.Qgen.QuestionRankerByParseProbability.java

/**
 * Load the parser from the given location within the classpath.
 * /*from  ww w .  j av  a  2 s. c  om*/
 * @param aUrl
 *            URL of the parser file.
 */
// copied from DKPro's StanfordParser
private LexicalizedParser getParserDataFromSerializedFile(URL aUrl) throws IOException {
    ObjectInputStream in;
    InputStream is = null;
    try {
        is = aUrl.openStream();

        if (aUrl.toString().endsWith(".gz")) {
            // it's faster to do the buffering _outside_ the gzipping as
            // here
            in = new ObjectInputStream(new BufferedInputStream(new GZIPInputStream(is)));
        } else {
            in = new ObjectInputStream(new BufferedInputStream(is));
        }
        LexicalizedParser pd = LexicalizedParser.loadModel(in);
        // Numberer.setNumberers(pd.numbs); // will happen later in
        // makeParsers()
        in.close();
        return pd;
    } finally {
        closeQuietly(is);
    }
}

From source file:org.wikimedia.analytics.kraken.pageview.PageviewCanonical.java

/**
 *
 * @param url/*ww  w  . j a v  a2  s. co m*/
 * @return
 * @throws MalformedURLException
 */
private URL fixApacheHttpComponentBug(final URL url) throws MalformedURLException {
    return new URL(url.toString().replace(";", "&"));
}

From source file:net.scriptability.core.url.DefaultURLResolver.java

/**
 * Resolves a URL and returns an input stream to its resource.
 *
 * @param url url to resolve//from  w  ww . j av a 2 s.  c  om
 * @return input stream to the resource addressed by the received URL
 * @throws URLResolutionException if the URL cannot be resolved
 */
@Override
public InputStream resolve(final URL url) throws URLResolutionException {
    Preconditions.checkNotNull(url, "URL cannot be null.");

    LOG.debug("Resolving URL: [{}].", url.toString());

    return openURLStream(url);
}

From source file:com.example.app.model.DemoUserProfileDAO.java

/**
 * Convert a URL to a string if possible or return null.
 *
 * @param link the link./*from w  w w.j  a v  a  2  s . c  om*/
 * @return the link as a String or null.
 */
@Nullable
@Contract("null->null;!null->!null")
public String toString(@Nullable URL link) {
    return link == null ? null : link.toString();
}

From source file:org.jboss.as.test.clustering.single.web.SimpleWebTestCase.java

@Test
@OperateOnDeployment("deployment-single")
public void test(@ArquillianResource(SimpleServlet.class) URL baseURL)
        throws ClientProtocolException, IOException {
    DefaultHttpClient client = new DefaultHttpClient();

    String url = baseURL.toString() + "simple";

    try {//  w  w  w.j av a2  s .c o  m
        HttpResponse response = client.execute(new HttpGet(url));
        Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
        Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader("value").getValue()));
        Assert.assertFalse(Boolean.valueOf(response.getFirstHeader("serialized").getValue()));
        response.getEntity().getContent().close();

        response = client.execute(new HttpGet(url));
        Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
        Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader("value").getValue()));
        // This won't be true unless we have somewhere to which to replicate or session persistence is configured (current default)
        Assert.assertFalse(Boolean.valueOf(response.getFirstHeader("serialized").getValue()));
        response.getEntity().getContent().close();
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:com.norconex.commons.lang.url.QueryString.java

/**
 * Apply this url QueryString on the given URL. If a query string already
 * exists, it is replaced by this one./*ww  w .  j  a  v  a2  s .  c o m*/
 * @param url the URL to apply this query string.
 * @return url with query string added
 */
public URL applyOnURL(URL url) {
    if (url == null) {
        return url;
    }
    try {
        return new URL(applyOnURL(url.toString()));
    } catch (MalformedURLException e) {
        throw new URLException("Cannot applyl query string to: " + url, e);
    }
}

From source file:com.cyclopsgroup.waterview.utils.TagSupportBase.java

/**
 * Overwrite or implement method doTag()
 *
 * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
 *///from   w w  w  .  ja  va  2s .c o m
public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
    try {
        processTag(output);
    } catch (Exception e) {
        JellyTagException ex = null;
        if (e instanceof JellyTagException) {
            ex = (JellyTagException) e;
        } else {
            ex = new JellyTagException(e);
        }
        URL[] scriptResources = getScriptResources();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < scriptResources.length; i++) {
            URL url = scriptResources[i];
            sb.append(">").append(url.toString());
        }
        ex.setFileName(sb.toString());
        throw ex;
    }
}

From source file:com.jaeksoft.searchlib.web.controller.crawler.web.UrlFilterController.java

@Command
@NotifyChange("testResult")
public void onTest() throws SearchLibException, MalformedURLException {
    Client client = getClient();/*w ww.j a v a2s. com*/
    if (client == null)
        return;
    if (StringUtils.isEmpty(testUrl))
        throw new SearchLibException("Please enter an URL.");
    testResult = null;
    URL u = new URL(testUrl);
    testResult = UrlFilterList.doReplace(u.getHost(), u.toString(), client.getUrlFilterList().getArray());
}

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

public void go(URL start) throws InterruptedException, IOException {
    // stay within same site
    urlBase = start.toString().replaceAll("(.*//.*/).*", "$1");
    StopWatch stopWatch = new StopWatch();

    stopWatch.start();/*from w w  w . j  av a  2  s . c o  m*/

    submitNewURL(start, 0);

    while (checkPageGrabs())
        ;
    stopWatch.stop();

    System.out.println("Found " + masterList.size() + " urls");
    System.out.println("in " + stopWatch.getTime() / 1000 + " seconds");

    for (String url : Uttils.URLS) {
        System.out.println(url);

        if (!url.contains("http")) {
            url = start.getProtocol() + "://" + start.getHost() + url;
            //System.out.println("com.mycompany.crawlertest.GrabManager.go() : " + );
        }
        try {
            Document document = Jsoup.parse(new URL(url), TIMEOUT);

            if (document.getElementsByTag("h1") != null && document.getElementsByTag("h1").size() != 0) {
                Elements videoTag = document.getElementsByTag("iframe");
                if (videoTag != null && videoTag.size() != 0) {
                    if (videoTag.get(0).hasAttr("allowfullscreen")) {
                        String tag = videoTag.get(0).toString();
                        System.out.println(document.getElementsByTag("h1").get(0).text() + " ___  " + tag);
                    }
                }
            }
        } catch (Exception EX) {
            System.out.println("ERROR : " + EX.getMessage());
        }
        //processHeaders(document.select("h1"));
    }
}