public static String getPageTitle(String url) throws IOException {
        URL u = new URL(url);
        URLConnection conn = u.openConnection();

        ContentType contentType = getContentTypeHeader(conn);
        if (!contentType.contentType.equals("text/html"))
            return null;
        else {

            Charset charset = getCharset(contentType);
            if (charset == null)
                charset = Charset.defaultCharset();

            InputStream in = conn.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, charset));
            int n = 0, totalRead = 0;
            char[] buf = new char[1024];
            StringBuilder content = new StringBuilder();

            while (totalRead < 8192 && (n = reader.read(buf, 0, buf.length)) != -1) {
                content.append(buf, 0, n);
                totalRead += n;
            }
            reader.close();

            Matcher matcher = TITLE_TAG.matcher(content);
            if (matcher.find()) {
                return matcher.group(1).replaceAll("[\\s<>]+", " ").trim();
            }
            else
                return null;
        }
    }