Example usage for java.net URL getContent

List of usage examples for java.net URL getContent

Introduction

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

Prototype

public final Object getContent() throws java.io.IOException 

Source Link

Document

Gets the contents of this URL.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    URL u = new URL("http://www.java2s.com");
    Object o = u.getContent();
    System.out.println(o.getClass().getName());
}

From source file:MainClass.java

public static void main(String[] args) {

    try {//w w w .j ava  2 s . com
        URL u = new URL("http://www.java2s.com");

        Object o = u.getContent();
        System.out.println("I got a " + o.getClass().getName());
    } catch (Exception ex) {
        System.err.println(ex);
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    URL url = new URL(args[0]);
    Reader reader = new InputStreamReader((InputStream) url.getContent());
    new ParserDelegator().parse(reader, new TextOnly(), false);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    URL url = new URL(args[0]);
    Reader reader = new InputStreamReader((InputStream) url.getContent());
    System.out.println("<HTML><HEAD><TITLE>Links for " + args[0] + "</TITLE>");
    System.out.println("<BASE HREF=\"" + args[0] + "\"></HEAD>");
    System.out.println("<BODY>");
    new ParserDelegator().parse(reader, new LinkPage(), false);
    System.out.println("</BODY></HTML>");
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    URL url = new URL(args[0]);
    Reader reader = new InputStreamReader((InputStream) url.getContent());
    new ParserDelegator().parse(reader, new HTMLParse(), false);
}

From source file:AuthDemo.java

public static void main(String args[]) throws MalformedURLException, IOException {
    String urlString = "";
    String username = "";
    String password = "";
    Authenticator.setDefault(new MyAuthenticator(username, password));
    URL url = new URL(urlString);
    InputStream content = (InputStream) url.getContent();
    BufferedReader in = new BufferedReader(new InputStreamReader(content));
    String line;//ww  w.  j  a va  2  s.co m
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
    System.out.println("Done.");
}

From source file:org.curriki.tools.tests.TryAnOpenIDRequestAtGoogle.java

public static void main(String[] args) {
    Object o = null;//www.ja  v a  2 s .c  o m
    String error = null;
    try {
        System.out.println("java.home is " + System.getProperty("java.home"));
        /* HttpClient client = new HttpClient();
        URL checkoutURL = new URL("https://www.google.com/accounts/o8/ud");//new URL("https://checkout.google.com/api/checkout/v2/reports/Merchant/MERCHANT_ID");
        Protocol myhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        client.getHostConfiguration().setHost("www.google.com", 443, myhttps);
        //client.getParams().setAuthenticationPreemptive(true);
        //client.getState().setCredentials(
        //        new AuthScope(checkoutURL.getHost(), checkoutURL.getPort(), AuthScope.ANY_REALM),
        //            new UsernamePasswordCredentials(merchant, key));
                
        GetMethod get = new GetMethod(checkoutURL.toExternalForm());
        client.executeMethod(get);
        System.out.println("Status " + get.getStatusCode() + " " + get.getStatusText());
        System.out.println("Obtained: " + get.getResponseBodyAsString());
        */
        URL url = new URL("https://checkout.google.com/api/checkout/v2/reports/Merchant/MERCHANT_ID");
        o = url.getContent();
    } catch (Exception ex) {
        StringWriter w = new StringWriter();
        ex.printStackTrace(new PrintWriter(w));
        error = w.toString();
    }
    System.out.println("error  " + error);
    System.out.println("obtained " + o);
}

From source file:Main.java

public static Object fetch(String address) throws MalformedURLException, IOException {
    URL url = new URL(address);
    Object content = url.getContent();
    return content;
}

From source file:Main.java

public static Object fetch(String address) {
    try {/* w  w  w .j a v  a 2  s . co  m*/
        URL url = new URL(address);
        Object content = url.getContent();
        return content;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static Drawable photo_fetch(String img) {
    Drawable image = null;//from  www  . j a v a 2s  . c om
    try {
        System.out.println("Inside Run !");
        java.net.URL u = new java.net.URL(img);
        Object content = u.getContent();
        InputStream is = (InputStream) content;
        image = Drawable.createFromStream(is, "src");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Returning ffrom heew !");
    return image;
}