Example usage for java.net URLConnection getDate

List of usage examples for java.net URLConnection getDate

Introduction

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

Prototype

public long getDate() 

Source Link

Document

Returns the value of the date header field.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getDate());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    int c;/*from w  ww  . ja  va  2 s.  c  o  m*/
    URL hp = new URL("http", "www.java2s.com", 80, "/");
    URLConnection hpCon = hp.openConnection();
    System.out.println("Date: " + hpCon.getDate());
    System.out.println("Type: " + hpCon.getContentType());
    System.out.println("Exp: " + hpCon.getExpiration());
    System.out.println("Last M: " + hpCon.getLastModified());
    System.out.println("Length: " + hpCon.getContentLength());
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    int c;/*from   w w w. ja  v a  2  s.co m*/
    URL hp = new URL("http://www.internic.net");
    URLConnection hpCon = hp.openConnection();

    long d = hpCon.getDate();
    if (d == 0)
        System.out.println("No date information.");
    else
        System.out.println("Date: " + new Date(d));

    System.out.println("Content-Type: " + hpCon.getContentType());

    d = hpCon.getExpiration();
    if (d == 0)
        System.out.println("No expiration information.");
    else
        System.out.println("Expires: " + new Date(d));

    d = hpCon.getLastModified();
    if (d == 0)
        System.out.println("No last-modified information.");
    else
        System.out.println("Last-Modified: " + new Date(d));

    int len = hpCon.getContentLength();
    if (len == -1)
        System.out.println("Content length unavailable.");
    else
        System.out.println("Content-Length: " + len);

    if (len != 0) {
        InputStream input = hpCon.getInputStream();
        int i = len;
        while (((c = input.read()) != -1)) { // && (--i > 0)) {
            System.out.print((char) c);
        }
        input.close();

    } else {
        System.out.println("No content available.");
    }

}

From source file:Main.java

public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    System.out.println("Content-type: " + uc.getContentType());
    System.out.println("Content-encoding: " + uc.getContentEncoding());
    System.out.println("Date: " + new Date(uc.getDate()));
    System.out.println("Last modified: " + new Date(uc.getLastModified()));
    System.out.println("Expiration date: " + new Date(uc.getExpiration()));
    System.out.println("Content-length: " + uc.getContentLength());
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    uc.connect();/*from   ww w .j  a  v a 2 s. com*/
    System.out.println("Content-type: " + uc.getContentType());
    System.out.println("Content-encoding: " + uc.getContentEncoding());
    System.out.println("Date: " + new Date(uc.getDate()));
    System.out.println("Last modified: " + new Date(uc.getLastModified()));
    System.out.println("Expiration date: " + new Date(uc.getExpiration()));
    System.out.println("Content-length: " + uc.getContentLength());
}

From source file:URLConnectionTest.java

public static void main(String[] args) {
    try {//from ww w  .  j a  va  2 s.  c  o m
        String urlName;
        if (args.length > 0)
            urlName = args[0];
        else
            urlName = "http://java.sun.com";

        URL url = new URL(urlName);
        URLConnection connection = url.openConnection();

        // set username, password if specified on command line

        if (args.length > 2) {
            String username = args[1];
            String password = args[2];
            String input = username + ":" + password;
            String encoding = base64Encode(input);
            connection.setRequestProperty("Authorization", "Basic " + encoding);
        }

        connection.connect();

        // print header fields

        Map<String, List<String>> headers = connection.getHeaderFields();
        for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
            String key = entry.getKey();
            for (String value : entry.getValue())
                System.out.println(key + ": " + value);
        }

        // print convenience functions

        System.out.println("----------");
        System.out.println("getContentType: " + connection.getContentType());
        System.out.println("getContentLength: " + connection.getContentLength());
        System.out.println("getContentEncoding: " + connection.getContentEncoding());
        System.out.println("getDate: " + connection.getDate());
        System.out.println("getExpiration: " + connection.getExpiration());
        System.out.println("getLastModifed: " + connection.getLastModified());
        System.out.println("----------");

        Scanner in = new Scanner(connection.getInputStream());

        // print first ten lines of contents

        for (int n = 1; in.hasNextLine() && n <= 10; n++)
            System.out.println(in.nextLine());
        if (in.hasNextLine())
            System.out.println(". . .");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:GetURLInfo.java

/** Use the URLConnection class to get info about the URL */
public static void printinfo(URL url) throws IOException {
    URLConnection c = url.openConnection(); // Get URLConnection from URL
    c.connect(); // Open a connection to URL

    // Display some information about the URL contents
    System.out.println("  Content Type: " + c.getContentType());
    System.out.println("  Content Encoding: " + c.getContentEncoding());
    System.out.println("  Content Length: " + c.getContentLength());
    System.out.println("  Date: " + new Date(c.getDate()));
    System.out.println("  Last Modified: " + new Date(c.getLastModified()));
    System.out.println("  Expiration: " + new Date(c.getExpiration()));

    // If it is an HTTP connection, display some additional information.
    if (c instanceof HttpURLConnection) {
        HttpURLConnection h = (HttpURLConnection) c;
        System.out.println("  Request Method: " + h.getRequestMethod());
        System.out.println("  Response Message: " + h.getResponseMessage());
        System.out.println("  Response Code: " + h.getResponseCode());
    }/*  w  ww.  j av a  2 s.c om*/
}

From source file:focusedCrawler.util.parser.PaginaURL.java

public PaginaURL(URL url, URLConnection conexao, int max, StopList sl) throws IOException {
    this(url, conexao.getDate(), conexao.getLastModified(), conexao.getContentLength(),
            conexao.getInputStream(), max, sl);

    //        System.out.println("CONEXAO: RESPONSE CODE = " + ((HttpURLConnection) conexao).getResponseCode());

    URL url_final = ((HttpURLConnection) conexao).getURL();

    //        System.out.println("CONEXAO: GET URL       = " + url_final);

    //        if (!url_final.equals(url)) {
    //            System.out.println("A URL '" + url + "' foi redirecionada para '" + url_final + "'");
    //        } else {
    //            System.out.println("URL OK");
    //        }/*from  w ww  . j  a  va  2 s .  com*/

    ((HttpURLConnection) conexao).disconnect();
}

From source file:org.jzkit.search.util.RecordConversion.XSLFragmentTransformer.java

private void reloadStylesheet() throws javax.xml.transform.TransformerConfigurationException {
    log.debug("XSLFragmentTransformer::reloadStylesheet()");
    try {/*ww w .ja  v a2s . c o m*/
        TransformerFactory tFactory = TransformerFactory.newInstance();
        if (ctx == null)
            throw new RuntimeException("Application Context Is Null. Cannot resolve resources");

        org.springframework.core.io.Resource r = ctx.getResource(the_path);
        if ((r != null) && (r.exists())) {
            URL path_url = r.getURL();
            URLConnection conn = path_url.openConnection();
            datestamp = conn.getDate();
            log.debug("get template for " + the_path + " url:" + path_url + " datestamp=" + datestamp);
            t = tFactory.newTemplates(new javax.xml.transform.stream.StreamSource(conn.getInputStream()));
        } else {
            log.error("Unable to resolve URL for " + the_path);
        }
    } catch (java.io.IOException ioe) {
        log.warn("Problem with XSL mapping", ioe);
        throw new RuntimeException("Unable to locate mapping: " + the_path);
    } catch (javax.xml.transform.TransformerConfigurationException tce) {
        log.warn("Problem with XSL mapping", tce);
        throw (tce);
    }

}

From source file:org.jzkit.search.util.RecordConversion.XSLFragmentTransformer.java

private void checkStylesheetDatestamp() {
    try {/*w w w  .j  a  va 2 s.  c  o  m*/
        URL path_url = XSLFragmentTransformer.class.getResource(the_path.replaceFirst("classpath:", "/")); // classpath:config/crosswalks/RecordModel/DC2MARC21slim.xsl.xml
        URLConnection conn = path_url.openConnection();
        long current_date = conn.getDate();
        if (current_date != datestamp) {
            log.debug("Detected change of xsl stylesheet, reloading");
            reloadStylesheet();
        }
    } catch (java.io.IOException ioe) {
        log.warn("Problem with XSL mapping - " + the_path, ioe);
    } catch (javax.xml.transform.TransformerConfigurationException tce) {
        log.warn("Problem with XSL mapping - " + the_path, tce);
    }
}