Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a url string to get a favicon in java

I am trying to get a favicon from a website with the following method. I tried to avoid // problems and decided to use a URL object.

 public static Bitmap getBitmapFromURL(URL src) {
        try {
            URL url = src;
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

I am running

Bitmap faviconBitmap = getBitmapFromURL(new URL("http", "www"+url, "/favicon.ico"));

with my url set to: url = imdb.com

but I am failing and getting the following error:

01-24 20:01:33.702: W/System.err(8678): java.io.IOException: Illegal character in authority at index 22: http://www.nytimes.com
01-24 20:01:33.702: W/System.err(8678): /favicon.ico

any suggestions on how to fix this?

like image 516
Quantico Avatar asked Nov 03 '22 05:11

Quantico


1 Answers

Looks like you have a newline or some other character at the end of url after "nytimes.com".

like image 159
kabuko Avatar answered Nov 14 '22 23:11

kabuko