separate compilation of PIDE vs. Pure sources, which enables independent Scala library;
1 /* Title: Pure/System/download.scala
5 Download URLs -- with progress monitor.
11 import java.io.{BufferedInputStream, BufferedOutputStream, FileOutputStream,
12 File, InterruptedIOException}
13 import java.net.{URL, URLConnection}
14 import java.awt.{Component, HeadlessException}
15 import javax.swing.ProgressMonitorInputStream
20 def stream(parent: Component, title: String, url: URL): (URLConnection, BufferedInputStream) =
22 val connection = url.openConnection
24 val stream = new ProgressMonitorInputStream(parent, title, connection.getInputStream)
25 val monitor = stream.getProgressMonitor
26 monitor.setNote(connection.getURL.toString)
28 val length = connection.getContentLength
29 if (length != -1) monitor.setMaximum(length)
31 (connection, new BufferedInputStream(stream))
34 def file(parent: Component, title: String, url: URL, file: File)
36 val (connection, instream) = stream(parent, title, url)
37 val mod_time = connection.getLastModified
41 catch { case _ : InterruptedIOException => error("Canceled by user") }
43 val outstream = new BufferedOutputStream(new FileOutputStream(file))
46 while ({ c = read(); c != -1 }) outstream.write(c)
48 finally { outstream.close }
49 if (mod_time > 0) file.setLastModified(mod_time)
51 finally { instream.close }