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:de.ingrid.portal.interfaces.impl.IBUSInterfaceImpl.java

private static String getResourceAsStream(String resource) throws Exception {
    String stripped = resource.startsWith("/") ? resource.substring(1) : resource;

    String stream = null;/*from   w  ww  .j a  va  2  s  .  co m*/
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader != null) {
        URL url = classLoader.getResource(stripped);
        if (url != null) {
            stream = url.toString();
        }
    }
    if (stream == null) {
        Environment.class.getResourceAsStream(resource);
    }
    if (stream == null) {
        URL url = Environment.class.getClassLoader().getResource(stripped);
        if (url != null) {
            stream = url.toString();
        }
    }
    if (stream == null) {
        throw new Exception(resource + " not found");
    }
    return stream;
}

From source file:com.sittinglittleduck.DirBuster.GenBaseCase.java

private static String getBaseCaseAgain(Manager manager, URL failurl, String failString) throws IOException {
    int failcode;
    String baseResponce = "";

    GetMethod httpget = new GetMethod(failurl.toString());
    // set the custom HTTP headers
    Vector HTTPheaders = manager.getHTTPHeaders();
    for (int a = 0; a < HTTPheaders.size(); a++) {
        HTTPHeader httpHeader = (HTTPHeader) HTTPheaders.elementAt(a);
        /*//from  ww w .  ja va2 s  .  c o m
         * Host header has to be set in a different way!
         */
        if (httpHeader.getHeader().startsWith("Host")) {
            httpget.getParams().setVirtualHost(httpHeader.getValue());
        } else {
            httpget.setRequestHeader(httpHeader.getHeader(), httpHeader.getValue());
        }
    }
    httpget.setFollowRedirects(Config.followRedirects);

    // save the http responce code for the base case
    failcode = manager.getHttpclient().executeMethod(httpget);
    manager.workDone();

    // we now need to get the content as we need a base case!
    if (failcode == 200) {
        if (Config.debug) {
            System.out.println("DEBUG GenBaseCase: base case for " + failurl.toString() + "came back as 200!");
        }

        BufferedReader input = new BufferedReader(new InputStreamReader(httpget.getResponseBodyAsStream()));
        String tempLine;
        StringBuffer buf = new StringBuffer();
        while ((tempLine = input.readLine()) != null) {
            buf.append("\r\n" + tempLine);
        }
        baseResponce = buf.toString();
        input.close();

        // HTMLparse.parseHTML();

        // HTMLparse htmlParse = new HTMLparse(baseResponce, null);
        // Thread parse  = new Thread(htmlParse);
        // parse.start();

        // clean up the base case, based on the basecase URL
        baseResponce = FilterResponce.CleanResponce(baseResponce, failurl, failString);

        httpget.releaseConnection();

        /*
         * return the cleaned responce
         */
        return baseResponce;
    } else {
        /*
         * we have a big problem here as the server has returned an other responce code, for the same request
         * TODO: think of a way to deal with this!
         */
        return null;
    }
}

From source file:eu.scape_project.pit.util.FileUtils.java

/**
 * Read file of URL into file./*  www. j a va 2s . c  o m*/
 * @param url URL where the input file is located
 * @param ext 
 * @return Result file
 * @throws IOException 
 */
public static File urlToFile(URL url, String ext) throws IOException {
    File fOut = null;

    fOut = getTmpFile("fromurl", "." + ext);

    URLConnection uc = url.openConnection();
    logger.info("ContentType: " + uc.getContentType());
    InputStream in = uc.getInputStream();
    org.apache.commons.io.FileUtils.copyInputStreamToFile(in, fOut);
    logger.info("File of length " + fOut.length() + " created from URL " + url.toString());

    in.close();

    return fOut;
}

From source file:com.mongolduu.android.ng.misc.HttpConnector.java

public static Bitmap downloadAlbumImage(long id) {
    try {/*from w  w  w  .j a va2 s. c  om*/
        URL downloadURL = new URL(
                IMongolduuConstants.ALBUMART_URL + "?" + IMongolduuConstants.SONG_ID_PARAMETER_NAME + "=" + id);
        return fetchImage(downloadURL.toString());
    } catch (MalformedURLException e) {
        Log.e(IMongolduuConstants.LOG_TAG, "exception", e);
    }
    return null;
}

From source file:jp.co.nssol.h5.test.selenium.base.H5TestCase.java

/**
 * webdrier_config.xml?testPageUrl????????????
 *
 * @param url/*from   ww  w.jav  a  2 s.  com*/
 */
protected static void show(String relativeUrl) {
    try {
        final URL url = new URL(new URL(TEST_PAGE_URL), relativeUrl);

        new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver d) {
                d.get(url.toString());
                return d.getCurrentUrl().equals(url.toString());
            }

        });
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

From source file:com.rumblefish.friendlymusic.api.RFAPI.java

public static URLRequest requestWithURL(URL url) {
    URLRequest request = new URLRequest();
    request.m_serverURL = url.toString();
    request.m_timelimit = RFAPI_TIMEOUT;
    request.m_nameValuePairs = null;//from  w ww . j  a  v a 2 s.c  o  m
    return request;
}

From source file:net.oauth.example.consumer.webapp.CookieConsumer.java

/**
 * Get a fresh access token from the service provider.
 * //from w ww.  ja  va 2 s . c  o m
 * @throws RedirectException
 *             to obtain authorization
 */
private static void getAccessToken(HttpServletRequest request, CookieMap cookies, OAuthAccessor accessor)
        throws Exception {
    CLIENT.getRequestToken(accessor);
    String consumerName = (String) accessor.consumer.getProperty("name");
    cookies.put(consumerName + ".requestToken", accessor.requestToken);
    cookies.put(consumerName + ".tokenSecret", accessor.tokenSecret);
    String authorizationURL = accessor.consumer.serviceProvider.userAuthorizationURL;
    if (authorizationURL.startsWith("/")) {
        authorizationURL = (new URL(new URL(request.getRequestURL().toString()),
                request.getContextPath() + authorizationURL)).toString();
    }
    URL callbackURL = new URL(new URL(request.getRequestURL().toString()),
            request.getContextPath() + Callback.PATH);
    throw new RedirectException(OAuth.addParameters(authorizationURL //
            , "oauth_token", accessor.requestToken //
            , "oauth_callback", OAuth.addParameters(callbackURL.toString() //
                    , "consumer", consumerName //
                    , "returnTo", getRequestPath(request) //
            )));
}

From source file:bolts.AppLinkNavigation.java

/**
 * Navigates to an {@link AppLink} for the given destination using the App Link resolution
 * strategy specified./*from w w w  .j a va  2 s .c o m*/
 *
 * @param context     the Context from which the navigation should be performed.
 * @param destination the destination URL for the App Link.
 * @param resolver    the resolver to use for fetching App Link metadata.
 * @return the {@link NavigationResult} performed by navigating.
 */
public static Task<NavigationResult> navigateInBackground(Context context, URL destination,
        AppLinkResolver resolver) {
    return navigateInBackground(context, Uri.parse(destination.toString()), resolver);
}

From source file:org.terasology.telemetry.TelemetryEmitter.java

private static HttpClientAdapter getDefaultAdapter(URL url) {

    // Make a new client with custom concurrency rules
    PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();
    manager.setDefaultMaxPerRoute(50);//from   www .  j  a  v a  2 s.c  om

    // Make the client
    CloseableHttpClient client = HttpClients.custom().setConnectionManager(manager).build();

    // Build the adapter
    return ApacheHttpClientAdapter.builder().url(url.toString()).httpClient(client).build();
}

From source file:com.clank.launcher.swing.SwingHelper.java

/**
 * Opens a system web browser for the given URL.
 *
 * @param url the URL//  www .  j a  va 2 s  .  c  o m
 * @param parentComponent the component from which to show any errors
 */
public static void openURL(URL url, Component parentComponent) {
    try {
        Desktop.getDesktop().browse(url.toURI());
    } catch (IOException e) {
        showErrorDialog(parentComponent, _("errors.openUrlError", url.toString()), _("errorTitle"));
    } catch (URISyntaxException e) {
    }
}