Code example for URLConnection

Methods: getInputStream, setConnectTimeout, setReadTimeout

0
        private void cacheURLToFile( String urlStr, File file ) 
            throws FileNotFoundException, IOException 
        { 
            URL url = new URL( urlStr ); 
            URLConnection connection = url.openConnection(); 
            connection.setConnectTimeout( 5*1000 ); 
            connection.setReadTimeout( 5*1000 ); 
            File tempFile = new File( file.getParentFile(), file.getName()+".tmp" ); 
            if( tempFile.exists() ) tempFile.delete(); 
            copy( connection.getInputStream(), new FileOutputStream( tempFile ) ); 
            if( file.exists() ) file.delete(); 
            tempFile.renameTo( file ); 
        } 
 
        private File getFile( ImageHandler handler ) 
        { 
            File file = null; 
            try 
            { 
                MessageDigest m = MessageDigest.getInstance( "MD5" ); 
                m.update( handler.url.getBytes(), 0, handler.url.length() );