private File downloadTempFile ( final String jarURL , final LogNode log ) { final LogNode subLog = log == null ? null : log . log ( jarURL , "Downloading URL " + jarURL ) ; File tempFile ; try { tempFile = makeTempFile ( jarURL , /* onlyUseLeafname = */ true ) ; final URL url = new URL ( jarURL ) ; try ( InputStream inputStream = url . openStream ( ) ) { Files . copy ( inputStream , tempFile . toPath ( ) , StandardCopyOption . REPLACE_EXISTING ) ; } if ( subLog != null ) { subLog . addElapsedTime ( ) ; } } catch ( final IOException | SecurityException e ) { if ( subLog != null ) { subLog . log ( "Could not download " + jarURL , e ) ; } return null ; } if ( subLog != null ) { subLog . log ( "Downloaded to temporary file " + tempFile ) ; subLog . log ( "***** Note that it is time-consuming to scan jars at http(s) addresses, " + "they must be downloaded for every scan, and the same jars must also be " + "separately downloaded by the ClassLoader *****" ) ; } return tempFile ; }
Download a jar from a URL to a temporary file .