01: /*
02: * Created on May 12, 2006
03: */
04: package com.openedit.modules.update;
05:
06: import java.io.File;
07: import java.io.FileOutputStream;
08: import java.io.InputStream;
09: 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: public void download(String inUrl, String inOutput)
19: throws OpenEditException {
20: download(inUrl, new File(inOutput));
21: }
22:
23: public void download(String inStrUrl, File outputFile)
24: throws OpenEditException {
25: try {
26: URL url = new URL(inStrUrl);
27: URLConnection con = url.openConnection();
28: con.setUseCaches(false);
29: con.connect();
30:
31: //*** create new output file
32: //*** make a growable storage area to read into
33: outputFile.getParentFile().mkdirs();
34: FileOutputStream out = new FileOutputStream(outputFile);
35: //*** read in url connection stream into input stream
36: InputStream in = con.getInputStream();
37: //*** fill output stream
38: new OutputFiller().fill(in, out);
39: //*** close output stream
40: FileUtils.safeClose(out);
41: //*** close input stream
42: FileUtils.safeClose(in);
43: } catch (Exception ex) {
44: throw new OpenEditException(ex);
45: }
46: }
47:
48: }
|