feisty meow concerns codebase 2.140
URLDownloader.java
Go to the documentation of this file.
1package org.gffs.network;
2
3import java.io.File;
4import java.io.FileOutputStream;
5import java.io.IOException;
6import java.io.InputStream;
7import java.io.OutputStream;
8import java.net.URL;
9import java.net.URLConnection;
10
11import org.gffs.io.IOUtils;
12
13public abstract class URLDownloader
14{
15 static final private int CONNECTION_TIMEOUT = 1000 * 8;
16 static final private int READ_TIMEOUT = 1000 * 8;
17
18 static public InputStream connect(URL url) throws IOException
19 {
20 URLConnection connection = url.openConnection();
21 connection.setConnectTimeout(CONNECTION_TIMEOUT);
22 connection.setReadTimeout(READ_TIMEOUT);
23 connection.connect();
24 return connection.getInputStream();
25 }
26
27 static public void download(URL source, File target) throws IOException
28 {
29 InputStream in = null;
30 OutputStream out = null;
31
32 try {
33 in = connect(source);
34 out = new FileOutputStream(target);
35 IOUtils.copy(in, out);
36 } finally {
37 IOUtils.close(in);
38 IOUtils.close(out);
39 }
40 }
41}
static InputStream connect(URL url)
static void download(URL source, File target)