File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
libs/unpuzzle-utils/src/main/groovy/org/akhikhl/unpuzzle/utils Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -66,8 +66,9 @@ final class Downloader {
6666
6767 void downloadFile (URL url , File file ) throws IOException {
6868 Long remoteContentLength
69+ def connection = openConnection(url)
6970 try {
70- remoteContentLength = Long . parseLong(url . openConnection() . getHeaderField(' Content-Length' ))
71+ remoteContentLength = Long . parseLong(connection . getHeaderField(' Content-Length' ))
7172 } catch (NumberFormatException e) {
7273 // no header, download anyway
7374 }
@@ -76,15 +77,30 @@ final class Downloader {
7677 return
7778 }
7879 console. startProgress(" Downloading file: ${ url.toExternalForm()} " )
80+ InputStream inStream = connection. getInputStream();
7981 try {
8082 file. parentFile. mkdirs()
81- url . openStream() . withStream { is ->
83+ inStream . withStream { is ->
8284 file. withOutputStream { os ->
8385 IOUtils . copy(is, new DownloadCountingOutputStream (os))
8486 }
8587 }
8688 } finally {
89+ inStream. close()
8790 console. endProgress()
8891 }
8992 }
93+
94+ URLConnection openConnection (URL url ){
95+ String protocol = url. getProtocol()
96+ String user = System . getProperty(" ${ protocol} .proxyUser" )
97+ String pw = System . getProperty(" ${ protocol} .proxyPassword" )
98+ def connection = url. openConnection();
99+ if (user != null && pw != null ){
100+ connection. setRequestProperty(
101+ " Proxy-Authorization" ,
102+ " Basic " + Base64 . getEncoder(). encodeToString(" ${ user} :${ pw} " . getBytes()));
103+ }
104+ return connection
105+ }
90106}
You can’t perform that action at this time.
0 commit comments