Java HTTP Read getContentEncoding(URL url)

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

Description

Returns the value of the content-encoding header field.

License

Open Source License

Parameter

Parameter Description
url refereneces URL

Exception

Parameter Description
IOException when an error occurs when opening connection to URL

Return

the content encoding of the resource that the URL references, or null if not known.

Declaration

public static String getContentEncoding(URL url) throws IOException 

Method Source Code


//package com.java2s;
import java.io.IOException;

import java.net.HttpURLConnection;

import java.net.URL;

public class Main {
    /**// www  .java2  s.  co m
     * Returns the value of the content-encoding header field.
     * @param url refereneces URL
     * @return the content encoding of the resource that the URL references, or null if not known.
     * @throws IOException when an error occurs when opening connection to URL
     */
    public static String getContentEncoding(URL url) throws IOException {
        String encoding = null;
        HttpURLConnection conn = null;
        try {
            conn = (HttpURLConnection) url.openConnection();
            encoding = conn.getContentEncoding();
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }
        return encoding;
    }
}

Related

  1. getByteaArrayFromConn(HttpURLConnection conn, boolean isSuccess)
  2. getContent(final HttpURLConnection con)
  3. getContent(final String urlString)
  4. getContent(String urlStr)
  5. getContentAsString(URL url)
  6. getContentFromHttpGetBasicAuth(String urlString, String username, String password)
  7. getContentFromURL(String sURL)
  8. getContentFromURL(String url)
  9. getContentLength(URL url)