Revision 42140
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/net/downloader/se/SEDownloader.java | ||
---|---|---|
205 | 205 |
} |
206 | 206 |
|
207 | 207 |
SEMonitor monitorObj = new SEMonitor(this, cancel); |
208 |
Thread downloader = new Thread(createDownloaderTask(this, url, null, f, cancel.getID())); |
|
208 |
Thread downloader = new Thread(createDownloaderTask(this, url, null, f, cancel.getID().getClass(),-1));
|
|
209 | 209 |
Thread monitor = new Thread(monitorObj); |
210 | 210 |
|
211 | 211 |
monitor.start(); |
... | ... | |
275 | 275 |
* @throws UnknownHostException |
276 | 276 |
*/ |
277 | 277 |
public synchronized File downloadFile(URL url, String data, String name, ICancellable cancel) throws IOException, ConnectException, UnknownHostException { |
278 |
return downloadFile(url, data, name, cancel, -1); |
|
279 |
} |
|
280 |
|
|
281 |
public synchronized File downloadFile(URL url, String data, String name, ICancellable cancel,int maxbytes) throws IOException, ConnectException, UnknownHostException { |
|
278 | 282 |
File f = null; |
279 | 283 |
|
280 | 284 |
if ((f = getPreviousDownloadedURL(url, data)) == null) { |
... | ... | |
297 | 301 |
}; |
298 | 302 |
} |
299 | 303 |
SEMonitor monitorObj = new SEMonitor(this, cancel); |
300 |
Thread downloader = new Thread(createDownloaderTask(this, url, data, f, cancel.getID())); |
|
304 |
Thread downloader = new Thread( |
|
305 |
createDownloaderTask(this, url, data, f, cancel.getID(),maxbytes) |
|
306 |
); |
|
307 |
|
|
301 | 308 |
Thread monitor = new Thread(monitorObj); |
302 | 309 |
monitor.start(); |
303 | 310 |
downloader.start(); |
... | ... | |
449 | 456 |
return this.latency; |
450 | 457 |
} |
451 | 458 |
|
452 |
protected Runnable createDownloaderTask(Downloader downloader, URL url, String data, File target, Object groupID){ |
|
453 |
return new SEDownloaderTask(downloader, url, data, target, groupID); |
|
459 |
protected Runnable createDownloaderTask(Downloader downloader, URL url, String data, File target, Object groupID,int maxbytes){ |
|
460 |
SEDownloaderTask t = new SEDownloaderTask(downloader, url, data, target, groupID); |
|
461 |
t.setMaxbytes(maxbytes); |
|
462 |
return t; |
|
463 |
|
|
454 | 464 |
} |
455 | 465 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/net/downloader/se/SEDownloaderTask.java | ||
---|---|---|
27 | 27 |
private String data = null; |
28 | 28 |
private Downloader downloader = null; |
29 | 29 |
private static Logger LOG = LoggerFactory.getLogger(SEDownloaderTask.class); |
30 |
private int maxbytes = -1; |
|
30 | 31 |
|
31 | 32 |
public SEDownloaderTask(Downloader downloader, URL url, String data, File dstFile, Object groupID) { |
32 | 33 |
this.url = url; |
... | ... | |
37 | 38 |
downloader.setDownloadException(null); |
38 | 39 |
} |
39 | 40 |
|
41 |
public void setMaxbytes(int maxbytes) { |
|
42 |
this.maxbytes = maxbytes; |
|
43 |
} |
|
44 |
|
|
45 |
public int getMaxbytes() { |
|
46 |
return maxbytes; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
40 | 50 |
public void run() { |
41 | 51 |
LOG.info("downloading '" + url.toString() + "' to: " + dstFile.getAbsolutePath()); |
42 | 52 |
if (data != null) { |
... | ... | |
79 | 89 |
for (int i = is.read(buffer); !downloader.getCanceled(groupID) && i > 0; i = is.read(buffer)) { |
80 | 90 |
dos.write(buffer, 0, i); |
81 | 91 |
readed += i; |
92 |
if( maxbytes>0 && readed>maxbytes ) { |
|
93 |
break; |
|
94 |
} |
|
82 | 95 |
|
83 | 96 |
} |
84 | 97 |
if (os != null) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.api/src/main/java/org/gvsig/compat/net/Downloader.java | ||
---|---|---|
69 | 69 |
* @throws UnknownHostException |
70 | 70 |
*/ |
71 | 71 |
public File downloadFile(URL url, String data, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException; |
72 |
|
|
72 |
|
|
73 |
public File downloadFile(URL url, String data, String name, ICancellable cancel, int maxbytes) throws IOException,ConnectException, UnknownHostException; |
|
74 |
|
|
73 | 75 |
public void removeURL(URL url); |
74 | 76 |
|
75 | 77 |
public void removeURL(Object url); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/utils/Utilities.java | ||
---|---|---|
441 | 441 |
public static synchronized File downloadFile(URL url, String data, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException{ |
442 | 442 |
return downloader.downloadFile(url, data, name, cancel); |
443 | 443 |
} |
444 |
|
|
445 |
public static synchronized File downloadFile(URL url, String data, String name, ICancellable cancel, int maxbytes) throws IOException,ConnectException, UnknownHostException{ |
|
446 |
return downloader.downloadFile(url, data, name, cancel,maxbytes); |
|
447 |
} |
|
444 | 448 |
|
445 | 449 |
/** |
446 | 450 |
* Cleans every temporal file previously downloaded. |
Also available in: Unified diff