Example usage for java.net URL toExternalForm

List of usage examples for java.net URL toExternalForm

Introduction

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

Prototype

public String toExternalForm() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:jshm.sh.Client.java

public static HeadMethod makeHeadRequest(URL url) throws HttpException, IOException {
    return makeHeadRequest(url.toExternalForm());
}

From source file:org.jboss.forge.shell.util.PluginUtil.java

public static void downloadFromURL(final PipeOut out, final URL url, final FileResource<?> resource)
        throws IOException {

    HttpGet httpGetManifest = new HttpGet(url.toExternalForm());
    out.print("Retrieving artifact ... ");

    HttpResponse response = new DefaultHttpClient().execute(httpGetManifest);
    switch (response.getStatusLine().getStatusCode()) {
    case 200://from   w w w  .j a v  a2s  .com
        out.println("done.");
        try {
            resource.setContents(response.getEntity().getContent());
            out.println("done.");
        } catch (IOException e) {
            out.println("failed to download: " + e.getMessage());
        }

    default:
        out.println("failed! (server returned status code: " + response.getStatusLine().getStatusCode());
    }
}

From source file:de.nava.informa.parsers.FeedParser.java

/**
 * Parser feed behind the given URL and build channel.
 *
 * @param cBuilder specific channel builder to use.
 * @param aURL     URL to use as data source.
 * @return parsed channel./*from  w ww  .j  a va  2s. c  o m*/
 * @throws IOException    if IO errors occur.
 * @throws ParseException if parsing is not possible.
 */
public static ChannelIF parse(ChannelBuilderIF cBuilder, URL aURL) throws IOException, ParseException {
    return parse(cBuilder, new InputSource(aURL.toExternalForm()), aURL);
}

From source file:esg.node.core.Resource.java

private static File urlToFile(URL res) {
    String externalForm = res.toExternalForm();
    if (externalForm.startsWith("file:")) {
        return new File(externalForm.substring(5));
    }//from   ww  w. jav  a2  s .  c o  m
    return null;
}

From source file:net.bluehornreader.misc.Utils.java

public static boolean isInJar() {
    URL url = Utils.class.getClassLoader().getResource("net/bluehornreader/model/Article.class");
    String s = url == null ? "" : url.toExternalForm();
    return !s.startsWith("file:");
}

From source file:org.echocat.jomon.net.http.HttpUtils.java

@Nonnull
public static HttpGet makeGetRequestFor(@Nonnull URL url) throws IOException {
    return new HttpGet(url.toExternalForm());
}

From source file:com.netflix.config.ClasspathPropertiesConfiguration.java

/**
 * Get the conventional name of the configuration that comes from from the
 * given URL.//from  w  w  w  .ja  va 2  s  .c  o m
 */
private static String getConfigName(Properties props, URL propertyFile) {
    String name = props.getProperty(configNameProperty);
    if (name == null) {
        name = propertyFile.toExternalForm();
        name = name.replace('\\', '/'); // Windows
        final String scheme = propertyFile.getProtocol().toLowerCase();
        if ("jar".equals(scheme) || "zip".equals(scheme)) {
            // Use the unqualified name of the jar file.
            final int bang = name.lastIndexOf("!");
            if (bang >= 0) {
                name = name.substring(0, bang);
            }
            final int slash = name.lastIndexOf("/");
            if (slash >= 0) {
                name = name.substring(slash + 1);
            }
        } else {
            // Use the URL of the enclosing directory.
            final int slash = name.lastIndexOf("/");
            if (slash >= 0) {
                name = name.substring(0, slash);
            }
        }
    }
    return name;
}

From source file:com.arcusys.liferay.vaadinplugin.util.WidgetsetUtil.java

private static void includeVaadinAddonJar(File file, List<VaadinAddonInfo> addons) {
    try {/*from  www .jav  a  2 s  .co  m*/
        URL url = new URL("file:" + file.getCanonicalPath());
        url = new URL("jar:" + url.toExternalForm() + "!/");
        JarURLConnection conn = (JarURLConnection) url.openConnection();
        JarFile jarFile = conn.getJarFile();
        if (jarFile != null) {
            Manifest manifest = jarFile.getManifest();
            if (manifest == null) {
                // No manifest so this is not a Vaadin Add-on
                return;
            }

            Attributes attrs = manifest.getMainAttributes();
            String value = attrs.getValue("Vaadin-Widgetsets");
            if (value != null) {
                String name = attrs.getValue("Implementation-Title");
                String version = attrs.getValue("Implementation-Version");
                if (name == null || version == null) {
                    // A jar file with Vaadin-Widgetsets but name or version
                    // missing. Most probably vaadin.jar itself, skipping it
                    // here
                    return;
                }

                List<String> widgetsets = new ArrayList<String>();
                String[] widgetsetNames = value.split(",");
                for (String wName : widgetsetNames) {
                    String widgetsetname = wName.trim().intern();
                    if (!widgetsetname.equals("")) {
                        widgetsets.add(widgetsetname);
                    }
                }

                if (!widgetsets.isEmpty()) {
                    addons.add(new VaadinAddonInfo(name, version, file, widgetsets));
                }
            }
        }
    } catch (Exception e) {
        log.warn("Exception trying to include Vaadin Add-ons.", e);
    }

}

From source file:com.geecko.QuickLyric.lyrics.LyricWiki.java

@Reflection
public static ArrayList<Lyrics> search(String query) {
    ArrayList<Lyrics> results = new ArrayList<>();
    query = query + " song";
    query = Normalizer.normalize(query, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+",
            "");/*  w w w  . ja  va2s  .  c  om*/
    try {
        URL queryURL = new URL(String.format(baseSearchUrl, URLEncoder.encode(query, "UTF-8")));
        Document searchpage = Jsoup.connect(queryURL.toExternalForm()).get();
        Elements searchResults = searchpage.getElementsByClass("Results");
        if (searchResults.size() >= 1) {
            searchResults = searchResults.get(0).getElementsByClass("result");
            for (Element searchResult : searchResults) {
                String[] tags = searchResult.getElementsByTag("h1").text().split(":");
                if (tags.length != 2)
                    continue;
                String url = searchResult.getElementsByTag("a").attr("href");
                Lyrics lyrics = new Lyrics(SEARCH_ITEM);
                lyrics.setArtist(tags[0]);
                lyrics.setTitle(tags[1]);
                lyrics.setURL(url);
                lyrics.setSource(domain);
                results.add(lyrics);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return results;
}

From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.InterceptorsTest.java

/**
 * Runs interceptions test scenario.//  w ww .  j a  v a 2 s .  c  om
 *
 * @throws Exception
 *             if exception occurs while running interceptions test
 */
public static void interceptionsTest() throws Exception {
    String tnt4jCfgPath = System.getProperty(TrackerConfigStore.TNT4J_PROPERTIES_KEY);
    if (StringUtils.isEmpty(tnt4jCfgPath)) {
        URL defaultCfg = InterceptionsManager.getDefaultTrackerConfiguration();
        System.setProperty(TrackerConfigStore.TNT4J_PROPERTIES_KEY, defaultCfg.toExternalForm());
    }

    final Consumer<String, String> consumer = initConsumer();

    Thread pt = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                produce();
            } catch (Exception exc) {
                exc.printStackTrace();
            }
        }
    });

    Thread ct = new Thread(new Runnable() {
        @Override
        public void run() {
            consume(consumer);
        }
    });
    ct.start();

    pt.start();
    pt.join();
    consumer.wakeup();
    ct.join();
}