Java URL Connection getUrlEncoding(URLConnection connection)

Here you can find the source of getUrlEncoding(URLConnection connection)

Description

get Url Encoding

License

Open Source License

Declaration

public static String getUrlEncoding(URLConnection connection) 

Method Source Code

//package com.java2s;

import java.net.URLConnection;

import java.util.*;

public class Main {
    public static final String defaultEncoding = "utf-8";

    public static String getUrlEncoding(URLConnection connection) {
        String contentType = connection.getContentType();
        String[] values = contentType.split(";");
        String charset = defaultEncoding; // might or might not be right....

        for (String value : values) {
            value = value.trim();//w  w  w  . j  a v a2s  .  c o  m
            if (value.toLowerCase(Locale.ENGLISH).startsWith("charset=")) {
                charset = value.substring("charset=".length());
            }
        }
        return charset;
    }
}

Related

  1. getUrlAsProperties(String urlString)
  2. getUrlContent(String urlAddress)
  3. getURLContents(URL u, Map data)
  4. getURLContentsAsString(URL url)
  5. getURLDataList(URL StrurlStringing)
  6. getURLForward(URL url)
  7. getURLInputStream(final URL url)
  8. getUrlSource(String url)
  9. getURLStream(URL url, int level)