if ( contentType == null ) { LOG.debug("Guessing Content-Type for URL "+url); }
    public Resource fetchResource(URL url) throws IOException, Exception     {        if ( url == null )            throw new IllegalArgumentException("Parameter url is not allowed to be null");        System.setProperty("http.agent", USER_AGENT);        System.setProperty("sun.net.client.defaultReadTimeout", Integer.toString(READ_TIMEOUT) );        System.setProperty("sun.net.client.defaultConnectTimeout", Integer.toString(CONNECT_TIMEOUT) );                URLConnection con = url.openConnection();        con.setRequestProperty(USER_AGENT_HEADER, USER_AGENT);        int responseCode = Resource.DEFAULT_RESPONSE_CODE;        if ( con instanceof HttpURLConnection ) {            HttpURLConnection httpConnection = (HttpURLConnection) con;                        HttpURLConnection.setFollowRedirects(true);            httpConnection.setInstanceFollowRedirects(true);                        httpConnection.connect();                        responseCode = httpConnection.getResponseCode();                        // TODO implement handling of gzip encoding here        }                String contentType = con.getContentType();                // find out if Content-Type String contains encoding information        String embeddedContentEnc = null;        if ( contentType != null && contentType.indexOf(";") > -1 ) {            LOG.debug("Content-type string ("+contentType+") contains charset; strip it!");            contentType = contentType.substring(0, contentType.indexOf(";")).trim();                        String cType = con.getContentType();            if ( cType.indexOf("=") > -1 ) {                embeddedContentEnc = cType.substring(cType.indexOf("=")+1).trim();            }        }                String contentEnc  = con.getContentEncoding();        if ( contentEnc == null )             contentEnc = embeddedContentEnc != null ? embeddedContentEnc : defaultEncoding;                Resource resource = new Resource(url,                                          con.getInputStream(),                                         contentType,                                         contentEnc,                                         con.getLastModified(),                                         responseCode);                LOG.debug("Fetched Resource with ContentType: '"+contentType+"' - ContentEncoding: '"+contentEnc+"'");                return resource;    }