URLConnection: getExpiration() : URLConnection « java.net « Java by API






URLConnection: getExpiration()

  

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;

public class Main {
  public static void main(String args[]) throws Exception {
    int c;
    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.");
    }

  }
}

   
    
  








Related examples in the same category

1.URLConnection: connect() throws IOException
2.URLConnection: getContentEncoding()
3.URLConnection: getContentType()
4.URLConnection: getHeaderFields()
5.URLConnection: getHeaderField(int n)
6.URLConnection: getHeaderFieldKey(int n)
7.URLConnection: getInputStream()
8.URLConnection: getIfModifiedSince()
9.URLConnection: getLastModified()
10.URLConnection: getURL()
11.URLConnection: setAllowUserInteraction(boolean allowuserinteraction)
12.URLConnection: setDoInput(boolean doinput)
13.URLConnection: setDoOutput(boolean dooutput)
14.URLConnection: setIfModifiedSince(long ifmodifiedsince)
15.URLConnection: setRequestProperty(String key, String value)
16.URLConnection: setUseCaches(boolean usecaches)