Java HTTP Read getContentLength(URL url)

Here you can find the source of getContentLength(URL url)

Description

get Content Length

License

Apache License

Declaration

public static long getContentLength(URL url) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static long getContentLength(URL url) throws IOException {
        URLConnection conn = url.openConnection();
        Long contentLength = conn.getContentLengthLong();
        if (contentLength != null && contentLength >= 0) {
            return contentLength;
        }/*w  ww.ja  va  2  s.  c om*/
        String contentLengthValue = conn.getHeaderField("content-length");
        if (contentLengthValue != null) {
            return Long.valueOf(contentLengthValue);
        }
        return -1;
    }
}

Related

  1. getContentAsString(URL url)
  2. getContentEncoding(URL url)
  3. getContentFromHttpGetBasicAuth(String urlString, String username, String password)
  4. getContentFromURL(String sURL)
  5. getContentFromURL(String url)
  6. getContentLength(URLConnection con)
  7. getContents(String urlStr)
  8. getContentTypeFromUrl(String urlname)
  9. getContentTypeSpecified(URLConnection connection)