1 4 package com.openedit.modules.update; 5 6 import java.io.File ; 7 import java.io.FileOutputStream ; 8 import java.io.InputStream ; 9 import java.net.URL ; 10 import java.net.URLConnection ; 11 12 import com.openedit.OpenEditException; 13 import com.openedit.util.FileUtils; 14 import com.openedit.util.OutputFiller; 15 16 public class Downloader 17 { 18 19 public void download(String inUrl, String inOutput) throws OpenEditException 20 { 21 download(inUrl,new File ( inOutput)); 22 } 23 24 public void download(String inStrUrl, File outputFile) throws OpenEditException 25 { 26 try 27 { 28 URL url = new URL (inStrUrl); 29 URLConnection con = url.openConnection(); 30 con.setUseCaches(false); 31 con.connect(); 32 33 outputFile.getParentFile().mkdirs(); 36 FileOutputStream out = new FileOutputStream (outputFile); 37 InputStream in = con.getInputStream(); 39 new OutputFiller().fill(in,out); 41 FileUtils.safeClose(out); 43 FileUtils.safeClose(in); 45 } 46 catch ( Exception ex) 47 { 48 throw new OpenEditException(ex); 49 } 50 } 51 52 } 53 | Popular Tags |