private File downloadRemoteDU ( URL duURL , File deploymentRoot ) throws Exception { InputStream in = null ; OutputStream out = null ; try { // Get the filename out of the URL String filename = new File ( duURL . getPath ( ) ) . getName ( ) ; // Prepare for creating the file at deploy folder File tempFile = new File ( deploymentRoot , filename ) ; out = new BufferedOutputStream ( new FileOutputStream ( tempFile ) ) ; URLConnection conn = duURL . openConnection ( ) ; in = conn . getInputStream ( ) ; // Get the data byte [ ] buffer = new byte [ 1024 ] ; int numRead ; while ( ( numRead = in . read ( buffer ) ) != - 1 ) { out . write ( buffer , 0 , numRead ) ; } // Done! Successful. return tempFile ; } finally { // Do the clean up. try { if ( in != null ) { in . close ( ) ; in = null ; } if ( out != null ) { out . close ( ) ; out = null ; } } catch ( IOException ioe ) { // Shouldn't happen, let's ignore. } } }
Downloads a remote DU to a local folder