public BufferedImage getImage ( URL url ) { String now = new Date ( ) . toString ( ) ; if ( url == null ) { return errorImage ( now , "(No image url)" ) ; } try { HttpURLConnection urlconn = ( HttpURLConnection ) url . openConnection ( ) ; urlconn . setReadTimeout ( msTimeout ) ; urlconn . setConnectTimeout ( msTimeout ) ; urlconn . setRequestMethod ( "GET" ) ; urlconn . connect ( ) ; BufferedImage image = ImageIO . read ( urlconn . getInputStream ( ) ) ; if ( image == null ) { return errorImage ( now , "(Null image read)" ) ; } imageWidth = image . getWidth ( ) ; imageHeight = image . getHeight ( ) ; return image ; } catch ( SocketTimeoutException e ) { logger . warn ( "getImage({}) => {} {}" , url , e . getClass ( ) . getCanonicalName ( ) , e . getMessage ( ) ) ; return errorImage ( now , msTimeout + "ms TIMEOUT" ) ; } catch ( Exception e ) { logger . warn ( "getImage({}) => {} {}" , url , e . getClass ( ) . getCanonicalName ( ) , e . getMessage ( ) ) ; return errorImage ( now , "(No image)" , url . toString ( ) , e . getMessage ( ) ) ; } }
Return image from given URL .