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.ms.commons.test.classloader.IntlTestURLClassPath.java

private static List<URL> adjustJarIndex(List<URL> urlList) {
    int indexOfJ2EE = findJarIndex(urlList, ".*[\\W]j2ee[^\\\\/]*\\.jar");
    int indexOfMail = findJarIndex(urlList, ".*[\\W]mail[^\\\\/]*\\.jar");
    int indexOfActivation = findJarIndex(urlList, ".*[\\W]activation.*\\.jar");

    int indexMaxMailOrActivation = Math.max(indexOfMail, indexOfActivation);
    if ((indexOfJ2EE == -1) || (indexMaxMailOrActivation == -1)) {
        System.err.println("Cannot find j2ee or mail|activation, do not adj. index.");
    } else {/*  ww  w.  ja v  a 2  s .c om*/
        if (indexOfJ2EE > indexMaxMailOrActivation) {
            System.err.println("J2ee is after mail|activation, do not adj. index.");
        } else {
            URL j2eeUrl = urlList.remove(indexOfJ2EE);
            urlList.add(j2eeUrl);
            System.err.println("Classpath url order has been adjusted:" + urlList);
        }
    }

    // adjust classes and classes.test
    try {
        if (urlList.size() >= 2) {
            URL url1 = urlList.get(0);
            URL url2 = urlList.get(1);
            if (url1.toString().contains("/target/classes/")
                    && url2.toString().contains("/target/classes.test/")) {
                urlList.add(0, urlList.remove(1));
            }
        }
    } catch (Exception e) {
        System.err.println("Adjust classes and classes.test failed.");
        e.printStackTrace();
    }

    return urlList;
}

From source file:com.dmsl.anyplace.utils.NetworkUtils.java

public static String encodeURL(String urlStr) throws URISyntaxException, MalformedURLException {
    URL url = new URL(urlStr);
    URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
            url.getQuery(), url.getRef());
    url = uri.toURL();//from   w  ww  . j av a2  s.c  om
    return url.toString();
}

From source file:ie.wombat.rt.fireeagle.CookieConsumer.java

/**
 * Get a fresh access token from the service provider.
 * @throws IOException /*  w  w  w.j a va2s.c  om*/
 * @throws URISyntaxException 
 * 
 * @throws RedirectException
 *             to obtain authorization
 */
private static void getAccessToken(HttpServletRequest request, CookieMap cookies, OAuthAccessor accessor)
        throws OAuthException, IOException, URISyntaxException {
    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:dynamicrefactoring.util.io.FileManager.java

/**
 * Copia un directorio empaquetado en el plugin en un directorio del sistema
 * de ficheros./* w ww . ja  va  2  s .  co  m*/
 * 
 * @param bundleDir ruta del directorio en el bundle
 * @param fileSystemDir ruta del directorio del sistema
 * @throws IOException si ocurre algun problema al acceder a las rutas
 */
public static void copyBundleDirToFileSystem(String bundleDir, String fileSystemDir) throws IOException {
    final Bundle bundle = Platform.getBundle(RefactoringPlugin.BUNDLE_NAME);
    final Enumeration<?> entries = bundle.findEntries(FilenameUtils.separatorsToUnix(bundleDir), "*", true);
    final List<?> lista = Collections.list(entries);
    for (Object entrada : lista) {
        URL entry = (URL) entrada;
        File fichero = new File(entry.getFile());
        if (!entry.toString().endsWith("/")) {
            FileUtils.copyURLToFile(entry, new File(fileSystemDir + entry.getFile()));

        }
    }
}

From source file:eionet.cr.util.URLUtil.java

/**
 *
 * @param url// w w  w  . java  2 s.  c om
 * @return URL
 * @throws MalformedURLException
 */
public static URL escapeIRI(URL url) throws MalformedURLException {

    return url == null ? null : new URL(escapeIRI(url.toString()));
}

From source file:com.skcraft.launcher.util.HttpRequest.java

/**
 * URL may contain spaces and other nasties that will cause a failure.
 *
 * @param existing the existing URL to transform
 * @return the new URL, or old one if there was a failure
 *//*from w w w  . j  a v  a  2  s.co m*/
private static URL reformat(URL existing) {
    try {
        URL url = new URL(existing.toString());
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        url = uri.toURL();
        return url;
    } catch (MalformedURLException e) {
        return existing;
    } catch (URISyntaxException e) {
        return existing;
    }
}

From source file:com.redhat.rhn.testing.TestUtils.java

/**
 * method to find a file relative to the calling class.  primarily
 * useful when writing tests that need access to external data.
 * this lets you put the data relative to the test class file.
 *
 * @param path the path, relative to caller's location
 * @return URL a URL referencing the file
 * @throws ClassNotFoundException if the calling class can not be found
 * (i.e., should not happen)/*from   w w w .java2s .c  o  m*/
 * @throws IOException if the specified file in an archive (eg. jar) and
 * it cannot be copied to a temporary location
 */
public static URL findTestData(String path) throws ClassNotFoundException, IOException {
    Throwable t = new Throwable();
    StackTraceElement[] ste = t.getStackTrace();

    String className = ste[1].getClassName();
    Class clazz = Class.forName(className);

    URL ret = clazz.getResource(path);

    if (ret.toString().contains("!")) { // file is from an archive
        String tempPath = "/tmp/" + filePrefix + ret.hashCode();
        InputStream input = clazz.getResourceAsStream(path);

        OutputStream output = new FileOutputStream(tempPath);
        IOUtils.copy(input, output);

        return new File(tempPath).toURI().toURL();
    }

    return ret;
}

From source file:it.geosolutions.geoserver.rest.HTTPUtils.java

/**
 * Wrapper for {@link #append(String...)}
 * @param base base URL//w  w w.j av a 2 s  . c o m
 * @param str strings to append
 * @return the base URL with parameters attached
 */
public static StringBuilder append(URL base, String... str) {
    if (str == null) {
        return append(base.toString());
    }

    StringBuilder buf = new StringBuilder(base.toString());
    for (String s : str) {
        if (s != null)
            buf.append(s);
    }
    return buf;
}

From source file:$.FileUtils.java

/**
     * Read file of URL into file.//from  w  w  w . j a va2s . c om
     * @param url URL where the input file is located
     * @return Result file
     */
    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:disko.DU.java

public static UrlTextDocument makeDocument(URL url) {
    UrlTextDocument result;/*ww  w.ja va  2 s .  co  m*/
    if (url.toString().endsWith(".pdf")) {
        result = new PDFDocument(url);
        result.setSummary(getFirstNWords(result.getFullText(), 60));
    } else {
        result = new HTMLDocument(url);
        result.setSummary(getFirstNWords(((HTMLDocument) result).getPlainText(), 60));
    }
    return result;
}