Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

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

Prototype

public URI(String str) throws URISyntaxException 

Source Link

Document

Constructs a URI by parsing the given string.

Usage

From source file:Main.java

public static void main(String[] a) {
    try {/*from  w w w . ja  va2  s  .co m*/
        URI uri = new URI("http://www.java2s.com");
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        if (desktop != null)
            desktop.browse(uri);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (URISyntaxException use) {
        use.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] a) {
    try {//from w  w  w.ja va 2s.  co m
        URI uri = new URI("http://www.java2s.com");
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
            desktop.isSupported(Desktop.Action.PRINT);
        }

        if (desktop != null)
            desktop.browse(uri);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (URISyntaxException use) {
        use.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    URI uri = null;//from ww  w.  j  a  v a  2s  .com
    URL url = null;
    String uriString = "http://www.google.com/";

    try {
        uri = new URI(uriString);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    System.out.println("Original URI  : " + uri);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String baseURIStr = "http://www.java2s.com/a/b/c/index.html?id=1&rate=5%25#foo";
    String relativeURIStr = "../x/y/z/welcome.html";

    URI baseURI = new URI(baseURIStr);
    URI relativeURI = new URI(relativeURIStr);

    URI resolvedURI = baseURI.resolve(relativeURI);

    printURIDetails(baseURI);/*from  w w w.  j a v a 2  s.c  o m*/
    printURIDetails(relativeURI);
    printURIDetails(resolvedURI);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    System.setProperty("java.net.useSystemProxies", "true");
    List l = ProxySelector.getDefault().select(new URI("http://www.yahoo.com/"));

    for (Iterator iter = l.iterator(); iter.hasNext();) {
        Proxy proxy = (Proxy) iter.next();
        System.out.println("proxy hostname : " + proxy.type());
        InetSocketAddress addr = (InetSocketAddress) proxy.address();
        if (addr == null) {
            System.out.println("No Proxy");
        } else {//from  w w  w  .  j av a 2s .c o  m
            System.out.println("proxy hostname : " + addr.getHostName());
            System.out.println("proxy port : " + addr.getPort());
        }
    }
}

From source file:Main.java

public static void main(String[] a) throws URISyntaxException {
    try {//from  ww  w.  ja v  a  2  s . c  o m
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        desktop.mail(new URI("name@address.net"));
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Test.java

public static void main(String[] args) {
    try (BufferedReader inputReader = Files.newBufferedReader(Paths.get(new URI("file:///C:/users.txt")),
            Charset.defaultCharset());
            BufferedWriter outputWriter = Files.newBufferedWriter(Paths.get(new URI("file:///C:/users.bak")),
                    Charset.defaultCharset())) {

        String inputLine;/* w  w w  .  j av a2  s  .  c  o m*/
        while ((inputLine = inputReader.readLine()) != null) {
            outputWriter.write(inputLine);
            outputWriter.newLine();
        }
        System.out.println("Copy complete!");
    } catch (URISyntaxException | IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Test.java

public static void main(String[] args) {
    try (BufferedReader inputReader = Files.newBufferedReader(Paths.get(new URI("file:///C:/users.txt")),
            Charset.defaultCharset());

            BufferedWriter outputWriter = Files.newBufferedWriter(Paths.get(new URI("file:///C:/users.bak")),
                    Charset.defaultCharset())) {

        String inputLine;/*from ww  w. j  a v  a 2  s . c  o  m*/
        while ((inputLine = inputReader.readLine()) != null) {
            outputWriter.write(inputLine);
            outputWriter.newLine();
        }
        System.out.println("Copy complete!");
    } catch (URISyntaxException | IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    URL url = new URI("http://www.google.com").toURL();
    URLConnection conn = url.openConnection();
    Reader rd = new InputStreamReader(conn.getInputStream());

    EditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
    kit.read(rd, doc, 0);//from  w  w w.jav  a  2s . c om

    HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
    while (it.isValid()) {
        SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();

        String link = (String) s.getAttribute(HTML.Attribute.HREF);
        if (link != null) {
            System.out.println(link);
        }
        it.next();
    }
}

From source file:Test.java

public static void main(String[] args) throws Exception {
    Path path1 = Paths.get("/home/docs/users.txt");
    Path path2 = Paths.get("/home/music/users.txt");

    System.out.println(Files.isSymbolicLink(path1));
    System.out.println(Files.isSymbolicLink(path2));

    Path path = Paths.get(new URI("C:/home/./music/users.txt"));
    System.out.println("Normalized: " + path.normalize());
    System.out.println("Absolute path: " + path.toAbsolutePath());
    System.out.println("URI: " + path.toUri());
    System.out.println("toRealPath (Do not follow links): " + path.toRealPath(LinkOption.NOFOLLOW_LINKS));
    System.out.println("toRealPath: " + path.toRealPath());

}